diff options
author | Madhusudan.C.S | 2010-09-03 11:51:18 +0530 |
---|---|---|
committer | Madhusudan.C.S | 2010-09-03 11:51:18 +0530 |
commit | fa67c4c7459d25400034dc917659e142751db2af (patch) | |
tree | 741087f14fa8d96996f842d7c05533cc84c6dec7 /tdd | |
parent | bc0ad135306888835b623bbcca220c704d81598a (diff) | |
download | sees-fa67c4c7459d25400034dc917659e142751db2af.tar.gz sees-fa67c4c7459d25400034dc917659e142751db2af.tar.bz2 sees-fa67c4c7459d25400034dc917659e142751db2af.zip |
Move the code and data files to math_utils directory.
Diffstat (limited to 'tdd')
-rw-r--r-- | tdd/gcd.py | 18 | ||||
-rw-r--r-- | tdd/math_utils/gcd.py | 22 | ||||
-rw-r--r-- | tdd/math_utils/gcd_testcases.dat (renamed from tdd/gcd_testcases.dat) | 0 |
3 files changed, 22 insertions, 18 deletions
diff --git a/tdd/gcd.py b/tdd/gcd.py deleted file mode 100644 index 454a719..0000000 --- a/tdd/gcd.py +++ /dev/null @@ -1,18 +0,0 @@ -def gcd(a, b): - while b != 0: - a, b = b, a % b - return a - -if __name__ == '__main__': - for line in open('gcd_testcases.dat'): - values = line.split(', ') - a = int(values[0]) - b = int(values[1]) - g = int(values[2]) - - tc = gcd(a, b) - if tc != g: - print "Test failed for the case a=%d and b=%d. Expected %d. Obtained %d instead." % (a, b, g, tc) - exit(1) - - print "All tests passed!" diff --git a/tdd/math_utils/gcd.py b/tdd/math_utils/gcd.py new file mode 100644 index 0000000..7204ac0 --- /dev/null +++ b/tdd/math_utils/gcd.py @@ -0,0 +1,22 @@ +def gcd(a, b): + """Returns the Greatest Common Divisor of the two integers + passed as arguments. + + Args: + a: an integer + b: another integer + + Returns: Greatest Common Divisor of a and b + + >>> gcd(48, 64) + 16 + >>> gcd(44, 19) + 1 + """ + if b == 0: + return b + return gcd(b, a%b) + +if __name__ == "__main__": + import doctest + doctest.testmod() diff --git a/tdd/gcd_testcases.dat b/tdd/math_utils/gcd_testcases.dat index 3829b12..3829b12 100644 --- a/tdd/gcd_testcases.dat +++ b/tdd/math_utils/gcd_testcases.dat |