Mercurial > hg > tvii
annotate tests/test_unique.py @ 87:9d5a5e9f5c3b
add kmeans + dataset
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 17 Dec 2017 14:05:57 -0800 |
parents | 9d55e0299c3f |
children |
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 |
51
e1eb45c4763e
[compat] fix variable scoping for py3
Jeff Hammel <k0scist@gmail.com>
parents:
50
diff
changeset
|
3 """ |
e1eb45c4763e
[compat] fix variable scoping for py3
Jeff Hammel <k0scist@gmail.com>
parents:
50
diff
changeset
|
4 test uniqueness of set elements |
e1eb45c4763e
[compat] fix variable scoping for py3
Jeff Hammel <k0scist@gmail.com>
parents:
50
diff
changeset
|
5 """ |
e1eb45c4763e
[compat] fix variable scoping for py3
Jeff Hammel <k0scist@gmail.com>
parents:
50
diff
changeset
|
6 |
50
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
7 import os |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
8 import unittest |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
9 from tvii.unique import unique |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
10 from tvii.unique import NotUnique |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
11 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
12 class TestUnique(unittest.TestCase): |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
13 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
14 def test_positive(self): |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
15 """ensure the unique functionality works as expected""" |
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 # true positive |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
18 a_unique_value = [7] * 7 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
19 assert unique(a_unique_value) == 7 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
20 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
21 def test_negative(self): |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
22 """what if a set is not unique?""" |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
23 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
24 data = [1,2,3,4] |
68 | 25 e = None |
50
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
26 try: |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
27 unique(data) |
71 | 28 except NotUnique as _e: |
29 e = _e | |
68 | 30 assert e is not None |
31 assert isinstance(e, NotUnique) | |
50
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
32 |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
33 if __name__ == '__main__': |
4b20694b8a16
add module + test for uniqueness
Jeff Hammel <k0scist@gmail.com>
parents:
diff
changeset
|
34 unittest.main() |