summaryrefslogtreecommitdiff
path: root/tdd/gcd.py
blob: 454a71917de0e3fbaa2104fc5781a42837bac58a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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!"