[18] | 1 | import unittest |
---|
| 2 | import Numeric |
---|
| 3 | from combinatorics import bitvector |
---|
| 4 | from numtools import expand |
---|
| 5 | |
---|
| 6 | #------------------------------------------------------------- |
---|
| 7 | |
---|
| 8 | class TestCase(unittest.TestCase): |
---|
| 9 | |
---|
| 10 | def setUp(self): |
---|
| 11 | pass |
---|
| 12 | |
---|
| 13 | def test_bitvector(self): |
---|
| 14 | |
---|
| 15 | d = 4 |
---|
| 16 | assert Numeric.allclose(bitvector(0, d), Numeric.array([0,0,0,0])) |
---|
| 17 | assert Numeric.allclose(bitvector(1, d), Numeric.array([1,0,0,0])) |
---|
| 18 | assert Numeric.allclose(bitvector(2, d), Numeric.array([0,1,0,0])) |
---|
| 19 | assert Numeric.allclose(bitvector(3, d), Numeric.array([1,1,0,0])) |
---|
| 20 | assert Numeric.allclose(bitvector(4, d), Numeric.array([0,0,1,0])) |
---|
| 21 | assert Numeric.allclose(bitvector(5, d), Numeric.array([1,0,1,0])) |
---|
| 22 | assert Numeric.allclose(bitvector(6, d), Numeric.array([0,1,1,0])) |
---|
| 23 | assert Numeric.allclose(bitvector(7, d), Numeric.array([1,1,1,0])) |
---|
| 24 | assert Numeric.allclose(bitvector(8, d), Numeric.array([0,0,0,1])) |
---|
| 25 | assert Numeric.allclose(bitvector(9, d), Numeric.array([1,0,0,1])) |
---|
| 26 | assert Numeric.allclose(bitvector(10, d), Numeric.array([0,1,0,1])) |
---|
| 27 | assert Numeric.allclose(bitvector(11, d), Numeric.array([1,1,0,1])) |
---|
| 28 | assert Numeric.allclose(bitvector(12, d), Numeric.array([0,0,1,1])) |
---|
| 29 | assert Numeric.allclose(bitvector(13, d), Numeric.array([1,0,1,1])) |
---|
| 30 | assert Numeric.allclose(bitvector(14, d), Numeric.array([0,1,1,1])) |
---|
| 31 | assert Numeric.allclose(bitvector(15, d), Numeric.array([1,1,1,1])) |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | def test_expand(self): |
---|
| 35 | |
---|
| 36 | d = 4 |
---|
| 37 | mask = Numeric.array([0,1,1,0,1]) |
---|
| 38 | v = Numeric.array([2,3,4]) |
---|
| 39 | |
---|
| 40 | assert Numeric.allclose(expand(v, mask), Numeric.array([0,2,3,0,4])) |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | #------------------------------------------------------------- |
---|
| 47 | if __name__ == "__main__": |
---|
| 48 | |
---|
| 49 | mysuite = unittest.makeSuite(TestCase,'test') |
---|
| 50 | runner = unittest.TextTestRunner() |
---|
| 51 | runner.run(mysuite) |
---|
| 52 | |
---|