From d5aeb0fe42ef2258ae09709fafb96d8a17e8f20e Mon Sep 17 00:00:00 2001 From: fdai7764 Date: Fri, 19 Jan 2024 12:12:36 +0100 Subject: [PATCH] added test for greatest common divisor (gcd) as well as corresponding functionality --- src/main/py/more_advanced_calculations.py | 6 ++++++ src/test/py/test_more_advanced_calculations.py | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/main/py/more_advanced_calculations.py create mode 100644 src/test/py/test_more_advanced_calculations.py diff --git a/src/main/py/more_advanced_calculations.py b/src/main/py/more_advanced_calculations.py new file mode 100644 index 0000000..449119c --- /dev/null +++ b/src/main/py/more_advanced_calculations.py @@ -0,0 +1,6 @@ +def gcd(a,b): + while a != b: + if a < b: + (a,b) = (b,a) + a -= b + return a \ No newline at end of file diff --git a/src/test/py/test_more_advanced_calculations.py b/src/test/py/test_more_advanced_calculations.py new file mode 100644 index 0000000..720df91 --- /dev/null +++ b/src/test/py/test_more_advanced_calculations.py @@ -0,0 +1,18 @@ +import unittest +from src.main.py.more_advanced_calculations import * + + +class more_advanced_calculations(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + + def test_gcd_of_747_and_81_should_be_9(self): + self.assertEqual(gcd(747,81), 9) + + + +if __name__ == '__main__': + unittest.main()