Exemplo n.º 1
0
 def test_freeze(self):
     """MutableBitvector freeze should return immutable bv with same data"""
     b = MutableBitvector("111")
     b[1] = 0
     c = b.freeze()
     self.assertSameObj(c, b._handler)
     self.assertEqual(c, Bitvector("101"))
     try:
         c[1] = 1
     except TypeError:
         pass
     else:
         raise AssertionError, "MutableBitvector.freeze() returned mutable object."
Exemplo n.º 2
0
 def test_thaw(self):
     """MutableBitvector thaw should return same object"""
     v = MutableBitvector()
     self.assertSameObj(v.thaw(), v)
Exemplo n.º 3
0
 def test_repr(self):
     """MutableBitvector repr should look like a normal object"""
     v = MutableBitvector(3, 10)
     v_id = str(hex(id(v)))
     expected = '<cogent.core.bitvector.MutableBitvector object at'
     self.assertTrue( ` v `.startswith(expected))
Exemplo n.º 4
0
 def test_thaw(self):
     """MutableBitvector thaw should return same object"""
     v = MutableBitvector()
     self.assertSameObj(v.thaw(), v)
Exemplo n.º 5
0
    def test_str(self):
        """MutableBitvector str should match expected results"""
        vecs = [MutableBitvector(i, 0) for i in [0, 1, 2, 7, 8, 1024, 814715L]]
        for v in vecs:
            self.assertEqual(str(v), '')

        vecs = [
            MutableBitvector(i, 1)
            for i in [0, 1, 2, 7, 8, 1024, 814715L, '1' * 50]
        ]
        single_results = list('01010011')
        for exp, vec in zip(single_results, vecs):
            self.assertEqual(str(vec), exp)

        vecs = [
            MutableBitvector(i, 3)
            for i in [0, 1, 2, 7, 8, 1024, 814715L, '1' * 50]
        ]
        three_results = [
            '000', '001', '010', '111', '000', '000', '011', '111'
        ]
        for exp, vec in zip(three_results, vecs):
            self.assertEqual(str(vec), exp)

        #should pad or truncate to the correct length
        self.assertEqual(str(MutableBitvector(814715, 20)),
                         '11000110111001111011')
        self.assertEqual(str(MutableBitvector(814715, 10)), '1001111011')
        self.assertEqual(str(MutableBitvector(8, 10)), '0000001000')
        self.assertEqual(str(MutableBitvector('1' * 50)), '1' * 50)