# HG changeset patch # User Madhusudan.C.S # Date 1283494878 -19800 # Node ID 513d43e2592799419496c845ea5b96831aabeeef # Parent fab0281a992ff0b3cbbfdd77075f5549c209fd81 Move the code and data files to math_utils directory. diff -r fab0281a992f -r 513d43e25927 tdd/gcd.py --- a/tdd/gcd.py Fri Sep 03 11:49:18 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -r fab0281a992f -r 513d43e25927 tdd/gcd_testcases.dat --- a/tdd/gcd_testcases.dat Fri Sep 03 11:49:18 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -6, 22, 2 -6, 48744, 6 -14, 143295, 1 -22, 751, 1 -35, 79, 1 -35, 96, 1 -52, 12, 4 -73, 79, 1 -73, 184790, 1 -86, 11, 1 -93, 8, 1 -93, 798, 3 -113, 42785, 1 -209, 2135, 1 -395, 8989, 1 -587, 331, 1 -643, 751, 1 -721, 242525, 1 -733, 5622, 1 -854, 42785, 1 -1695, 57, 3 -1695, 798, 3 -3429, 177203, 1 -4603, 12, 1 -4603, 48744, 1 -6139, 57, 1 -6139, 204, 1 -6660, 96, 12 -6660, 410400, 180 -6703, 410400, 1 -8964, 22, 2 -9673, 751, 1 -9673, 7909, 1 -9673, 3335, 1 -16028, 891, 1 -44231, 378, 1 -49020, 751, 1 -57908, 184790, 2 -65482, 548045, 1 -79715, 8, 1 -79715, 891, 1 -79715, 66371, 1 -321807, 891, 3 -366607, 97, 1 -402212, 5595, 1 -448426, 66371, 1 -575271, 4617, 9 -575271, 402152, 1 -680256, 48744, 72 -779565, 184790, 5 diff -r fab0281a992f -r 513d43e25927 tdd/math_utils/gcd.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tdd/math_utils/gcd.py Fri Sep 03 11:51:18 2010 +0530 @@ -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 -r fab0281a992f -r 513d43e25927 tdd/math_utils/gcd_testcases.dat --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tdd/math_utils/gcd_testcases.dat Fri Sep 03 11:51:18 2010 +0530 @@ -0,0 +1,50 @@ +6, 22, 2 +6, 48744, 6 +14, 143295, 1 +22, 751, 1 +35, 79, 1 +35, 96, 1 +52, 12, 4 +73, 79, 1 +73, 184790, 1 +86, 11, 1 +93, 8, 1 +93, 798, 3 +113, 42785, 1 +209, 2135, 1 +395, 8989, 1 +587, 331, 1 +643, 751, 1 +721, 242525, 1 +733, 5622, 1 +854, 42785, 1 +1695, 57, 3 +1695, 798, 3 +3429, 177203, 1 +4603, 12, 1 +4603, 48744, 1 +6139, 57, 1 +6139, 204, 1 +6660, 96, 12 +6660, 410400, 180 +6703, 410400, 1 +8964, 22, 2 +9673, 751, 1 +9673, 7909, 1 +9673, 3335, 1 +16028, 891, 1 +44231, 378, 1 +49020, 751, 1 +57908, 184790, 2 +65482, 548045, 1 +79715, 8, 1 +79715, 891, 1 +79715, 66371, 1 +321807, 891, 3 +366607, 97, 1 +402212, 5595, 1 +448426, 66371, 1 +575271, 4617, 9 +575271, 402152, 1 +680256, 48744, 72 +779565, 184790, 5