import unittest import Numeric from combinatorics import bitvector from numtools import expand #------------------------------------------------------------- class TestCase(unittest.TestCase): def setUp(self): pass def test_bitvector(self): d = 4 assert Numeric.allclose(bitvector(0, d), Numeric.array([0,0,0,0])) assert Numeric.allclose(bitvector(1, d), Numeric.array([1,0,0,0])) assert Numeric.allclose(bitvector(2, d), Numeric.array([0,1,0,0])) assert Numeric.allclose(bitvector(3, d), Numeric.array([1,1,0,0])) assert Numeric.allclose(bitvector(4, d), Numeric.array([0,0,1,0])) assert Numeric.allclose(bitvector(5, d), Numeric.array([1,0,1,0])) assert Numeric.allclose(bitvector(6, d), Numeric.array([0,1,1,0])) assert Numeric.allclose(bitvector(7, d), Numeric.array([1,1,1,0])) assert Numeric.allclose(bitvector(8, d), Numeric.array([0,0,0,1])) assert Numeric.allclose(bitvector(9, d), Numeric.array([1,0,0,1])) assert Numeric.allclose(bitvector(10, d), Numeric.array([0,1,0,1])) assert Numeric.allclose(bitvector(11, d), Numeric.array([1,1,0,1])) assert Numeric.allclose(bitvector(12, d), Numeric.array([0,0,1,1])) assert Numeric.allclose(bitvector(13, d), Numeric.array([1,0,1,1])) assert Numeric.allclose(bitvector(14, d), Numeric.array([0,1,1,1])) assert Numeric.allclose(bitvector(15, d), Numeric.array([1,1,1,1])) def test_expand(self): d = 4 mask = Numeric.array([0,1,1,0,1]) v = Numeric.array([2,3,4]) assert Numeric.allclose(expand(v, mask), Numeric.array([0,2,3,0,4])) #------------------------------------------------------------- if __name__ == "__main__": mysuite = unittest.makeSuite(TestCase,'test') runner = unittest.TextTestRunner() runner.run(mysuite)