diff --git a/__pycache__/calculator.cpython-39.pyc b/__pycache__/calculator.cpython-39.pyc new file mode 100644 index 0000000..32ebaa5 Binary files /dev/null and b/__pycache__/calculator.cpython-39.pyc differ diff --git a/__pycache__/test_calculator.cpython-39.pyc b/__pycache__/test_calculator.cpython-39.pyc new file mode 100644 index 0000000..da55feb Binary files /dev/null and b/__pycache__/test_calculator.cpython-39.pyc differ diff --git a/calculator.py b/calculator.py index 306879a..6451dc5 100644 --- a/calculator.py +++ b/calculator.py @@ -1,3 +1,4 @@ + class Calculator: def add(self, a, b): return a + b diff --git a/clear b/clear new file mode 100644 index 0000000..0b4ca25 --- /dev/null +++ b/clear @@ -0,0 +1,65 @@ +commit a78cb6ab1c920e585c15f0fbfb8a83e90c206b6b (HEAD, origin/master, origin/HEAD) +Author: alex2521-code +Date: Thu Nov 13 02:32:39 2025 +0000 + + Test commit 2 + +commit 970f08e6de52b87bb7b0f4d1511c4dd1d37a73f1 +Author: alex2521-code +Date: Wed Nov 12 13:12:36 2025 +0000 + + show line error + +commit a8133f3433fbdb529a9870bbfba39298fa41b4ea +Author: alex2521-code +Date: Wed Nov 12 13:11:02 2025 +0000 + + Added the test cases2 + +commit 2e8dd5b2624fe65669825fc55f9afec4aa079453 +Author: alex2521-code +Date: Wed Nov 12 12:57:44 2025 +0000 + + Added the test cases by cmd + +commit 886c30470f3b7e3119639d7b9d5c4c56e14f6e81 +Author: Chaiyong Ragkhitwetsagul +Date: Mon Nov 4 01:38:06 2024 +0000 + + Add one more bug + +commit af8f9360d321dff40108fb6d62d07c2ab51f4413 +Author: Chaiyong Ragkhitwetsagul +Date: Sat Nov 2 23:14:44 2024 +0000 + + Updated the code + +commit 1d231767e3175bbb806dc6fef1047abc738a676a +Author: Chaiyong Ragkhitwetsagul +Date: Sat Nov 2 22:17:11 2024 +0000 + + Updated README. + +commit c03cd9084e4e23493d52139a2ebb6d460cb5f79f +Author: Chaiyong Ragkhitwetsagul +Date: Sat Nov 2 22:13:43 2024 +0000 + + Removed other test cases. + +commit cc20158fb48f090aa485de2cebde644737ab92bd +Author: Chaiyong Ragkhitwetsagul +Date: Sat Nov 2 22:12:24 2024 +0000 + + Added .gitignore + +commit 4eed8f1aa1c3268b010fa7716d68341a0e242f5b +Author: Chaiyong Ragkhitwetsagul +Date: Sat Nov 2 22:12:03 2024 +0000 + + Added initial files. + +commit 42aeda4c0e2092713331e5cb3ddaac55fb2f3db9 +Author: Chaiyong Ragkhitwetsagul +Date: Sun Nov 3 05:04:11 2024 +0700 + + Initial commit diff --git a/test_calculator.py b/test_calculator.py index 7a241ca..5acc93f 100644 --- a/test_calculator.py +++ b/test_calculator.py @@ -1,15 +1,58 @@ +# import unittest +# from calculator import Calculator + +# class TestCalculator(unittest.TestCase): + +# def setUp(self): +# self.calc = Calculator() + +# def test_add(self): +# self.assertEqual(self.calc.add(1, 2), 3) +# self.assertEqual(self.calc.add(-1, 5), 4) + +# def test_subtract(self): +# # expected a - b +# self.assertEqual(self.calc.subtract(5, 3), -2) +# self.assertEqual(self.calc.subtract(3, 5), 2) +# # Add the following test methods to the TestCalculator class: + +# if __name__ == '__main__': +# unittest.main() + + import unittest from calculator import Calculator class TestCalculator(unittest.TestCase): - def setUp(self): self.calc = Calculator() def test_add(self): self.assertEqual(self.calc.add(1, 2), 3) + self.assertEqual(self.calc.add(-1, 5), 4) + + def test_subtract(self): + # expected a - b + self.assertEqual(self.calc.subtract(5, 3), 2) + self.assertEqual(self.calc.subtract(3, 5), -2) + + def test_multiply(self): + self.assertEqual(self.calc.multiply(2, 3), 6) + self.assertEqual(self.calc.multiply(5, 0), 0) + self.assertEqual(self.calc.multiply(0, 5), 0) + + def test_divide(self): + # integer division + self.assertEqual(self.calc.divide(10, 2), 5) + self.assertEqual(self.calc.divide(9, 2), 4) # 9 // 2 == 4 + self.assertEqual(self.calc.divide(0, 3), 0) + with self.assertRaises(ZeroDivisionError): + self.calc.divide(5, 0) - # Add the following test methods to the TestCalculator class: + # def test_modulo(self): + # self.assertEqual(self.calc.modulo(10, 3), 1) + # self.assertEqual(self.calc.modulo(9, 3), 0) + # self.assertEqual(self.calc.modulo(2, 5), 2) -if __name__ == '__main__': - unittest.main() \ No newline at end of file +if __name__ == "__main__": + unittest.main()