diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e96d33d --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +__pycache__/ +*.py[cod] +.pytest_cache/ +.coverage +htmlcov/ +*.exe +caeser_test diff --git a/Learning/Part-1/Python/calcfinalq2.py b/Learning/Part-1/Python/calcfinalq2.py index 6358120..5ee5505 100644 --- a/Learning/Part-1/Python/calcfinalq2.py +++ b/Learning/Part-1/Python/calcfinalq2.py @@ -91,22 +91,24 @@ def select_op(choice): print("Unrecognized operation") c1 = 0 hist = [] -while True: - print("Select operation.") - print("1.Add : + ") - print("2.Subtract : - ") - print("3.Multiply : * ") - print("4.Divide : / ") - print("5.Power : ^ ") - print("6.Remainder: % ") - print("7.Terminate: # ") - print("8.Reset : $ ") - print("8.History : ? ") - # take input from the user - choice = input("Enter choice(+,-,*,/,^,%,#,$,?): ") - print(choice) - c1 +=1 - if(select_op(choice) == -1): - #program ends here - print("Done. Terminating") - exit() \ No newline at end of file + +if __name__ == "__main__": + while True: + print("Select operation.") + print("1.Add : + ") + print("2.Subtract : - ") + print("3.Multiply : * ") + print("4.Divide : / ") + print("5.Power : ^ ") + print("6.Remainder: % ") + print("7.Terminate: # ") + print("8.Reset : $ ") + print("8.History : ? ") + # take input from the user + choice = input("Enter choice(+,-,*,/,^,%,#,$,?): ") + print(choice) + c1 +=1 + if(select_op(choice) == -1): + #program ends here + print("Done. Terminating") + exit() \ No newline at end of file diff --git a/Learning/Part-1/Python/test_calcfinalq2.py b/Learning/Part-1/Python/test_calcfinalq2.py new file mode 100644 index 0000000..68e5c47 --- /dev/null +++ b/Learning/Part-1/Python/test_calcfinalq2.py @@ -0,0 +1,24 @@ +import unittest +from calcfinalq2 import add + +class TestCalcAdd(unittest.TestCase): + def test_add_positive_numbers(self): + self.assertEqual(add(5, 3), 8) + self.assertEqual(add(10.5, 2.5), 13.0) + + def test_add_negative_numbers(self): + self.assertEqual(add(-5, -3), -8) + self.assertEqual(add(-10.5, -2.5), -13.0) + + def test_add_mixed_numbers(self): + self.assertEqual(add(5, -3), 2) + self.assertEqual(add(-10, 5), -5) + self.assertEqual(add(10.5, -2.5), 8.0) + + def test_add_zero(self): + self.assertEqual(add(5, 0), 5) + self.assertEqual(add(0, -3), -3) + self.assertEqual(add(0, 0), 0) + +if __name__ == '__main__': + unittest.main()