import unittest
import io
import re
from unittest import mock
import math
import student_X as main #Replace student_X with your filename 
import sys
import io
from io import StringIO
    
    
    
 

class PrintWhetherRightTriangleTests(unittest.TestCase):
    
    def test_default_case(self):
        function = main.print_whether_right_triangle

        try:
            docstring = function.__doc__
            docstring = docstring.strip()
        except:
            docstring = ""
        correct = docstring != ""
        message = "docstring is blank."
        self.assertTrue(correct, message) 

        

        with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            function(12.0, 16.0, 20.0)
        output = fake_stdout.getvalue().strip()

        correct = "12.0" in output
        feedback = "The first parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "16.0" in output
        feedback = "The second parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "20.0" in output
        feedback = "The third parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "not" not in output
        feedback = "Says no when the inputs can be a right triangle."
        self.assertTrue(correct, feedback)

        correct = output.endswith(".")
        feedback = "The output doesn't end with a period."
        self.assertTrue(correct, feedback)

        regex = "A right triangle can have sides of length 12.0 *, +16.0 *,? (and *)?20.0 ?.?"
        correct = re.match(regex, output)
        feedback = "Doesn't print the full correct output when the lengths can form a right triangle (and the hypotenuse is the third parameter)."
        self.assertTrue(correct, feedback)
        


        with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            function(30.0, 50.0, 40.0)
        output = fake_stdout.getvalue().strip()

        correct = "30.0" in output
        feedback = "The first parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "50.0" in output
        feedback = "The second parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "40.0" in output
        feedback = "The third parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "not" not in output
        feedback = "Says no when the inputs can be a right triangle."
        self.assertTrue(correct, feedback)

        correct = output.endswith(".")
        feedback = "The output doesn't end with a period."
        self.assertTrue(correct, feedback)

        regex = "A right triangle can have sides of length 30.0 *, +50.0 *,? (and *)?40.0 ?.?"
        correct = re.match(regex, output)
        feedback = "Doesn't print the full correct output when the lengths can form a right triangle (and the hypotenuse is the second parameter)."
        self.assertTrue(correct, feedback)
        


        with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            function(10.0, 8.0, 6.0)
        output = fake_stdout.getvalue().strip()

        correct = "10.0" in output
        feedback = "The first parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "8.0" in output
        feedback = "The second parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "6.0" in output
        feedback = "The third parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "not" not in output
        feedback = "Says no when the inputs can be a right triangle."
        self.assertTrue(correct, feedback)

        correct = output.endswith(".")
        feedback = "The output doesn't end with a period."
        self.assertTrue(correct, feedback)

        regex = "A right triangle can have sides of length 10.0 *, +8.0 *,? (and *)?6.0 ?.?"
        correct = re.match(regex, output)
        feedback = "Doesn't print the full correct output when the lengths can form a right triangle (and the hypotenuse is the first parameter)."
        self.assertTrue(correct, feedback)
        


        with mock.patch('sys.stdout', new=io.StringIO()) as fake_stdout:
            function(5.0, 8.0, 6.0)
        output = fake_stdout.getvalue().strip()

        correct = "5.0" in output
        feedback = "The first parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "8.0" in output
        feedback = "The second parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "6.0" in output
        feedback = "The third parameter is not in the output."
        self.assertTrue(correct, feedback)

        correct = "cannot" in output
        feedback = "Missing the word 'cannot' when the inputs can't be a right triangle."
        self.assertTrue(correct, feedback)

        correct = output.endswith(".")
        feedback = "The output doesn't end with a period."
        self.assertTrue(correct, feedback)

        regex = "A right triangle cannot have sides of length 5.0 *, +8.0 *,? (and *)?6.0 ?.?"
        correct = re.match(regex, output)
        feedback = "Doesn't print the full correct output when the lengths can't form a right triangle."
        self.assertTrue(correct, feedback)
        
        
if __name__ == "__main__":
    tests = PrintWhetherRightTriangleTests()
    tests.test_default_case()