Пример #1
0
    def test_init(self):
        """VectorFromCases should return vector with 1 where string is ucase"""
        valid_strings = ['', 'a', 'X', 'aBc', 'Acb', 'abC', 'AAA', 'aaa', '@']
        results = ['', '0', '1', '010', '100', '001', '111', '000', '0']

        for data, result in zip(valid_strings, results):
            self.assertEqual(VectorFromCases(data), LongBitvector(result))
            self.assertTrue(isinstance(VectorFromCases(data), LongBitvector))
            self.assertEqual(VectorFromCases(data, ShortBitvector), \
                ShortBitvector(result))
            self.assertTrue(isinstance(VectorFromCases(data, ShortBitvector), \
                                       ShortBitvector))

        v = VectorFromCases('aBC')
        self.assertTrue(isinstance(v, ImmutableBitvector))

        w = VectorFromCases('aBC', MutableBitvector)
        self.assertTrue(isinstance(w, MutableBitvector))
        self.assertEqual(w, Bitvector('011'))
        w[0] = 1
        self.assertEqual(w, Bitvector('111'))
Пример #2
0
 def setUp(self):
     """Define a few standard vectors"""
     self.s = ShortBitvector('00000000000000101111000000001011000')
     self.l = LongBitvector('11111111111111111111111111111111111')
     self.tiny = ShortBitvector('1')
     self.huge = LongBitvector('1' * 1000)