Mercurial > hg > tvii
annotate tests/test_unique.py @ 50:4b20694b8a16
add module + test for uniqueness
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 17 Sep 2017 14:28:36 -0700 |
parents | |
children | e1eb45c4763e |
rev | line source |
---|---|
50
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
2 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
3 import os |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
4 import unittest |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
5 from tvii.unique import unique |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
6 from tvii.unique import NotUnique |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
7 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
8 class TestUnique(unittest.TestCase): |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
9 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
10 def test_positive(self): |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
11 """ensure the unique functionality works as expected""" |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
12 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
13 # true positive |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
14 a_unique_value = [7] * 7 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
15 assert unique(a_unique_value) == 7 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
16 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
17 def test_negative(self): |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
18 """what if a set is not unique?""" |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
19 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
20 data = [1,2,3,4] |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
21 e = None |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
22 try: |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
23 unique(data) |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
24 except NotUnique as e: |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
25 pass |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
26 assert e is not None |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
27 assert isinstance(e, NotUnique) |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
28 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
29 if __name__ == '__main__': |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
30 unittest.main() |