Add the gcd.py sample file being used in the hand out.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Tue, 31 Aug 2010 18:57:46 +0530
changeset 111 a6a442d1bbd9
parent 110 4e7b98636b58
child 112 0b01bb6ea6b8
Add the gcd.py sample file being used in the hand out.
tdd/gcd.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tdd/gcd.py	Tue Aug 31 18:57:46 2010 +0530
@@ -0,0 +1,17 @@
+def gcd(a, b):
+    while b != 0:
+        a, b = b, a % b
+    return a
+
+if __name__ == '__main__':
+    tc1 = gcd(48, 64)
+    if tc1 != 16:
+        print "Test failed for the case a=48 and b=64. Expected 16. Obtained %d instead." % tc1
+        exit(1)
+
+    tc2 = gcd(44, 19)
+    if tc2 != 1:
+        print "Test failed for the case a=44 and b=19. Expected 1. Obtained %d instead." % tc2
+        exit(1)
+
+    print "All tests passed!"