author | Puneeth Chaganti <punchagan@fossee.in> |
Sun, 06 Feb 2011 17:57:03 +0530 | |
changeset 157 | 3174d4803cd5 |
parent 119 | 9f353900cee8 |
permissions | -rw-r--r-- |
119
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
1 |
import gcd |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
2 |
import unittest |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
3 |
|
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
4 |
class TestGcdFunction(unittest.TestCase): |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
5 |
|
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
6 |
def setUp(self): |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
7 |
self.test_file = open('gcd_testcases.dat') |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
8 |
self.test_cases = [] |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
9 |
for line in self.test_file: |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
10 |
values = line.split(', ') |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
11 |
a = int(values[0]) |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
12 |
b = int(values[1]) |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
13 |
g = int(values[2]) |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
14 |
|
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
15 |
self.test_cases.append([a, b, g]) |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
16 |
|
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
17 |
def test_gcd(self): |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
18 |
for case in self.test_cases: |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
19 |
a = case[0] |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
20 |
b = case[1] |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
21 |
g = case[2] |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
22 |
self.assertEqual(gcd.gcd(a, b), g) |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
23 |
|
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
24 |
def tearDown(self): |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
25 |
self.test_file.close() |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
26 |
del self.test_cases |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
27 |
|
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
28 |
if __name__ == '__main__': |
9f353900cee8
Add unittest based test module.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff
changeset
|
29 |
unittest.main() |