예제 #1
0
    def test_is_empty(self):
        """is_empty()"""
        # Check return True for len(self.kchar) == 0, otherwise return False.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        self.assertTrue(abc.is_empty() == False)

        empty = b_Sym_kchar("empty", (), 1)
        self.assertTrue(empty.is_empty() == True)
예제 #2
0
    def test_is_empty(self):
        """is_empty()"""
        # Check return True for len(self.kchar) == 0, otherwise return False.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        self.assertTrue(abc.is_empty() == False)

        empty = b_Sym_kchar("empty", (), 1)
        self.assertTrue(empty.is_empty() == True)
예제 #3
0
    def test_compute_double_stride(self):
        """compute_double_stride()"""
        # compute_double_stride(compSymbol, reverse, last, local_chars):
        # Test with compSymbol of type sym_kchar.
        # If is reverse True, check in result kchar reverse sort self and comp.
        # Check in result kchar that last value is same as called.
        # Chech that local_chars[i] for i in len(local_chars) have value
        # local_chars[i] = local_chars[i] - compSymbol.kchar[i]
        ab = b_Sym_kchar("ab", ('a', 'b'), 0)
        ef = b_Sym_kchar("ef", ('e', 'f'), 1)
        local_chars = list()
        chars = set()
        for i in range(0, 256):
            chars.add(chr(i))
            local_chars.append(chars.copy())

        new_kchar = ab.compute_double_stride(ef, False, 2, local_chars)[0]
        new_local_chars = \
            ab.compute_double_stride(ef, False, 2, local_chars)[1]

        reference_kchar = b_Sym_kchar("abef", ('a', 'b', 'e', 'f'), 2)
        reference_kchar_2 = \
            b_Sym_kchar("abef", ('a', 'b', 'e', 'f'), 2)
        reference_kchar.last = 2
        reference_kchar_2.last = 2

        reference_local_chars = local_chars[0] - set([ef.kchar])

        self.assertTrue(new_kchar == reference_kchar
                        or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 2)

        # reverse = True
        ab = b_Sym_kchar("ab", ('a', 'b'), 0)
        ef = b_Sym_kchar("ef", ('e', 'f'), 1)
        local_chars = list()
        chars = set()
        for i in range(0, 256):
            chars.add(chr(i))
            local_chars.append(chars.copy())

        new_kchar = ab.compute_double_stride(ef, True, 2, local_chars)[0]
        new_local_chars = \
            ab.compute_double_stride(ef, True, 2, local_chars)[1]

        reference_kchar = b_Sym_kchar("efab", ('e', 'f', 'a', 'b'), 2)
        reference_kchar_2 = \
            b_Sym_kchar("efab", ('e', 'f', 'a', 'b'), 2)
        reference_kchar.last = 2
        reference_kchar_2.last = 2
        reference_local_chars = local_chars[0] - set([ab.kchar])

        self.assertTrue(new_kchar == reference_kchar
                        or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 2)
예제 #4
0
    def test_compute_double_stride(self):
        """compute_double_stride()"""
        # compute_double_stride(compSymbol, reverse, last, local_chars):
        # Test with compSymbol of type sym_kchar.
        # If is reverse True, check in result kchar reverse sort self and comp.
        # Check in result kchar that last value is same as called.
        # Chech that local_chars[i] for i in len(local_chars) have value
        # local_chars[i] = local_chars[i] - compSymbol.kchar[i]
        ab = b_Sym_kchar("ab", ('a', 'b'), 0)
        ef = b_Sym_kchar("ef", ('e', 'f'), 1)
        local_chars = list()
        chars = set()
        for i in range(0, 256):
            chars.add(chr(i))
            local_chars.append(chars.copy())

        new_kchar = ab.compute_double_stride(ef, False, 2, local_chars)[0]
        new_local_chars = \
            ab.compute_double_stride(ef, False, 2, local_chars)[1]

        reference_kchar = b_Sym_kchar("abef", ('a', 'b', 'e', 'f'), 2)
        reference_kchar_2 = \
            b_Sym_kchar("abef", ('a', 'b', 'e', 'f'), 2)
        reference_kchar.last = 2
        reference_kchar_2.last = 2
        
        reference_local_chars = local_chars[0] - set([ef.kchar])

        self.assertTrue(new_kchar == reference_kchar
           or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 2)

        # reverse = True
        ab = b_Sym_kchar("ab", ('a', 'b'), 0)
        ef = b_Sym_kchar("ef", ('e', 'f'), 1)
        local_chars = list()
        chars = set()
        for i in range(0, 256):
            chars.add(chr(i))
            local_chars.append(chars.copy())

        new_kchar = ab.compute_double_stride(ef, True, 2, local_chars)[0]
        new_local_chars = \
            ab.compute_double_stride(ef, True, 2, local_chars)[1]

        reference_kchar = b_Sym_kchar("efab", ('e', 'f', 'a', 'b'), 2)
        reference_kchar_2 = \
            b_Sym_kchar("efab", ('e', 'f', 'a', 'b'), 2)
        reference_kchar.last = 2
        reference_kchar_2.last = 2
        reference_local_chars = local_chars[0] - set([ab.kchar])

        self.assertTrue(new_kchar == reference_kchar
           or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 2)
예제 #5
0
 def test_get_support_type(self):
     """get_support_type()"""
     # Check return [b_symbol.io_mapper["b_Sym_char"],
     # b_symbol.io_mapper["b_Sym_char_class"],
     # b_symbol.io_mapper["b_Sym_string"],
     # b_symbol.io_mapper["b_Sym_kchar"]] 
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.get_support_type() == [io_mapper["b_Sym_char"],
         io_mapper["b_Sym_char_class"], io_mapper["b_Sym_string"],
         io_mapper["b_Sym_kchar"]])
예제 #6
0
 def test_get_support_type(self):
     """get_support_type()"""
     # Check return [b_symbol.io_mapper["b_Sym_char"],
     # b_symbol.io_mapper["b_Sym_char_class"],
     # b_symbol.io_mapper["b_Sym_string"],
     # b_symbol.io_mapper["b_Sym_kchar"]]
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.get_support_type() == [
         io_mapper["b_Sym_char"], io_mapper["b_Sym_char_class"],
         io_mapper["b_Sym_string"], io_mapper["b_Sym_kchar"]
     ])
예제 #7
0
    def test_collision(self):
        """collision()"""
        # method collision(set_of_symbols):
        # Try with suitable objects of class sym_kchar and check correct
        # result - is / is not collision.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        ac = b_Sym_char_class("ac", set(['a', 'c']), 1)
        b = b_Sym_char("b", 'b', 2)
        efg = b_Sym_kchar("efg", ('e', 'f', 'g'), 3)
        set_of_symbols = set([efg, ac, b])
        self.assertTrue(abc.collision(set_of_symbols) == False)

        a = b_Sym_char("a", 'a', 4)
        set_of_symbols.add(a)
        self.assertTrue(abc.collision(set_of_symbols) == False)

        cba = b_Sym_kchar("cba", ('c', 'b', 'a'), 5)
        set_of_symbols.add(cba)
        self.assertTrue(abc.collision(set_of_symbols) == False)

        abc_2 = b_Sym_kchar("abc", ('a', 'b', 'c'), 6)
        set_of_symbols.add(abc_2)
        self.assertTrue(abc.collision(set_of_symbols) == True)
예제 #8
0
    def test_collision(self):
        """collision()"""
        # method collision(set_of_symbols):
        # Try with suitable objects of class sym_kchar and check correct
        # result - is / is not collision.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        ac = b_Sym_char_class("ac", set(['a', 'c']), 1)
        b = b_Sym_char("b", 'b', 2)
        efg = b_Sym_kchar("efg", ('e', 'f', 'g'), 3)
        set_of_symbols = set([efg, ac, b])
        self.assertTrue(abc.collision(set_of_symbols) == False)

        a = b_Sym_char("a", 'a', 4)
        set_of_symbols.add(a)
        self.assertTrue(abc.collision(set_of_symbols) == False)

        cba = b_Sym_kchar("cba", ('c', 'b', 'a'), 5)
        set_of_symbols.add(cba)
        self.assertTrue(abc.collision(set_of_symbols) == False)

        abc_2 = b_Sym_kchar("abc", ('a', 'b', 'c'), 6)
        set_of_symbols.add(abc_2)
        self.assertTrue(abc.collision(set_of_symbols) == True)
예제 #9
0
    def test_accept(self):
        """accept()"""
        # method accept(text):
        # Check if len(text) < len(self.kchar) then is thrown exception
        # symbol_string_to_short.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        try:
            abc.accept("ab")
            self.assertTrue(False)
        except symbol_string_to_short:
            self.assertTrue(True)

        # If begin of text is same as any combination of kchar then return
        # text[len(self.kchar):]
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        self.assertTrue(abc.accept("abcdef") == "def")

        # In case there is no combination then thrown exception
        # symbol_accept_exception.
        try:
            abc.accept("wrong_text")
            self.assertTrue(False)
        except symbol_accept_exception:
            self.assertTrue(True)
예제 #10
0
    def test_accept(self):
        """accept()"""
        # method accept(text):
        # Check if len(text) < len(self.kchar) then is thrown exception
        # symbol_string_to_short.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        try:
            abc.accept("ab")
            self.assertTrue(False)
        except symbol_string_to_short:
            self.assertTrue(True)

        # If begin of text is same as any combination of kchar then return
        # text[len(self.kchar):]
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        self.assertTrue(abc.accept("abcdef") == "def")

        # In case there is no combination then thrown exception
        # symbol_accept_exception.
        try:
            abc.accept("wrong_text")
            self.assertTrue(False)
        except symbol_accept_exception:
            self.assertTrue(True)
예제 #11
0
 def test_decode_symbol(self):
     """decode_symbol()"""
     # Test if different types of symbols are decoded correctly and
     # the symbol was removed from the beginning of input string.
     aut = PHF_DFA()
     aut._automaton.alphabet[0] = b_Sym_char_class("ch0", set(['a', 'b']), 0)
     aut._automaton.alphabet[1] = b_Sym_char_class("ch1", set(['c', 'd']), 1)
     aut._automaton.alphabet[2] = b_Sym_char_class("ch2", set(['e', 'f']), 2)
     aut._automaton.alphabet[3] = b_Sym_char("ch3", "g", 3)
     aut._automaton.alphabet[4] = b_Sym_kchar("ch4", (frozenset(['1', '2']), frozenset(['1', '2'])), 4)
     self.assertEqual(aut.decode_symbol("abeg112"), ("beg112", 0))
     self.assertEqual(aut.decode_symbol("beg112"), ("eg112", 0))
     self.assertEqual(aut.decode_symbol("eg112"), ("g112", 2))
     self.assertEqual(aut.decode_symbol("g112"), ("112", 3))
     self.assertEqual(aut.decode_symbol("112"), ("2", 4))
     # Nonexistent symbol is removed from the string and -1 is returned
     self.assertEqual(aut.decode_symbol("2"), ("", -1))
예제 #12
0
    def test_import_symbol(self):
        """import_symbol()"""
        # Check that is from test_repr created and returned correct object
        # having set self._id on tid and all parametrs are correct set.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        abc.import_symbol("40000|65|66|67", 1)

        self.assertTrue(abc.kchar == ('e', 'f', 'g')) 
        self.assertTrue(abc._id == 1)
        self.assertTrue(abc._text == "{efg}")

        # Check if is text_repr of different type, then is thrown exception
        # symbol_import_exception.
        try:
            abc.import_symbol("0|65|66|67", 1)
            self.assertTrue(False)
        except symbol_import_exception:
            self.assertTrue(True)
예제 #13
0
    def test_import_symbol(self):
        """import_symbol()"""
        # Check that is from test_repr created and returned correct object
        # having set self._id on tid and all parametrs are correct set.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        abc.import_symbol("40000|65|66|67", 1)

        self.assertTrue(abc.kchar == ('e', 'f', 'g'))
        self.assertTrue(abc._id == 1)
        self.assertTrue(abc._text == "{efg}")

        # Check if is text_repr of different type, then is thrown exception
        # symbol_import_exception.
        try:
            abc.import_symbol("0|65|66|67", 1)
            self.assertTrue(False)
        except symbol_import_exception:
            self.assertTrue(True)
예제 #14
0
    def test_compute_equal(self):
        """compute_equal()"""
        # method compute_equal(other):
        # If is other type sym_kchar, then return True if are arguments
        # kchar same.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        efg = b_Sym_kchar("efg", ('e', 'f', 'g'), 1)
        self.assertTrue(abc.compute_equal(efg) == False)

        abc_2 = b_Sym_kchar(
            "abc", (frozenset(['a']), frozenset(['b']), frozenset(['c'])), 2)
        self.assertTrue(abc.compute_equal(abc_2) == True)

        # If is other type sym_string, then return True if is
        # len(other.string) == len(self.kchar), all subsymbols kchar have
        # length one (len(self.kchar[i]) == 1) and value string is straight
        # value kchar.
        kchar_abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        string_abc = b_Sym_string("abc", "abc", 1)
        string_abcde = b_Sym_string("abcde", "abcde", 2)
        self.assertTrue(kchar_abc.compute_equal(string_abc) == True)
        self.assertTrue(kchar_abc.compute_equal(string_abcde) == False)

        # If is other type sym_char, then return True if is
        # len(self.kchar) == 1 and len(self.kchar[0]) == 1 and their
        # arguments are same.
        kchar_a = b_Sym_kchar("kchar_a", ('a'), 0)
        a = b_Sym_char("a", 'a', 1)
        self.assertTrue(kchar_a.compute_equal(a) == True)
        b = b_Sym_char("b", 'b', 2)
        self.assertTrue(kchar_a.compute_equal(b) == False)

        # If is other type sym_char_class, then return True if is
        # len(self.kchar) == 1 and len(other.charClass) == len(self.kchar[0])
        # and values of arguments are same.
        kchar_abc = b_Sym_kchar("kchar_[abc]", (frozenset(['a', 'b', 'c']), ),
                                0)
        set_abc = b_Sym_char_class("[abc]", set(['a', 'b', 'c']), 1)
        self.assertTrue(kchar_abc.compute_equal(set_abc) == True)
        cd = b_Sym_char_class("set(['c', 'd'])", set(['c', 'd']), 2)
        self.assertTrue(kchar_abc.compute_equal(cd) == False)
예제 #15
0
    def test_compute_equal(self):
        """compute_equal()"""
        # method compute_equal(other):
        # If is other type sym_kchar, then return True if are arguments
        # kchar same.
        abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        efg = b_Sym_kchar("efg", ('e', 'f', 'g'), 1)
        self.assertTrue(abc.compute_equal(efg) == False)

        abc_2 = b_Sym_kchar("abc", (frozenset(['a']), frozenset(['b']),
            frozenset(['c'])), 2)
        self.assertTrue(abc.compute_equal(abc_2) == True)

        # If is other type sym_string, then return True if is
        # len(other.string) == len(self.kchar), all subsymbols kchar have
        # length one (len(self.kchar[i]) == 1) and value string is straight
        # value kchar.
        kchar_abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
        string_abc = b_Sym_string("abc", "abc", 1)
        string_abcde = b_Sym_string("abcde", "abcde", 2)
        self.assertTrue(kchar_abc.compute_equal(string_abc) == True)
        self.assertTrue(kchar_abc.compute_equal(string_abcde) == False)

        # If is other type sym_char, then return True if is
        # len(self.kchar) == 1 and len(self.kchar[0]) == 1 and their
        # arguments are same.
        kchar_a = b_Sym_kchar("kchar_a", ('a'), 0)
        a = b_Sym_char("a", 'a', 1)
        self.assertTrue(kchar_a.compute_equal(a) == True)
        b = b_Sym_char("b", 'b', 2)
        self.assertTrue(kchar_a.compute_equal(b) == False)

        # If is other type sym_char_class, then return True if is
        # len(self.kchar) == 1 and len(other.charClass) == len(self.kchar[0])
        # and values of arguments are same.
        kchar_abc = b_Sym_kchar("kchar_[abc]", (frozenset(['a', 'b', 'c']),), 0)
        set_abc = b_Sym_char_class("[abc]", set(['a', 'b', 'c']), 1)
        self.assertTrue(kchar_abc.compute_equal(set_abc) == True)
        cd = b_Sym_char_class("set(['c', 'd'])", set(['c', 'd']), 2)
        self.assertTrue(kchar_abc.compute_equal(cd) == False)
예제 #16
0
 def test___str__(self):
     """__str__()"""
     # Check output str(self.kchar).
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.__str__() == str(abc.kchar))
예제 #17
0
 def test___hash__(self):
     """__hash__()"""
     # Check return hash(self.kchar).
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.__hash__() == hash(abc.kchar))
예제 #18
0
 def test___repr__(self):
     """__repr__()"""
     # Check return repr(self.kchar).
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.__repr__() == repr(abc.kchar))
예제 #19
0
 def test___hash__(self):
     """__hash__()"""
     # Check return hash(self.kchar).
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.__hash__() == hash(abc.kchar))
예제 #20
0
 def test___str__(self):
     """__str__()"""
     # Check output str(self.kchar).
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.__str__() == str(abc.kchar))
예제 #21
0
 def test___repr__(self):
     """__repr__()"""
     # Check return repr(self.kchar).
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.__repr__() == repr(abc.kchar))
예제 #22
0
    def test_compute_double_stride(self):
        """compute_double_stride()"""
        # Method compute_double_stride(compSymbol, reverse, last, local_chars)
        # Test with compSymbol type sym_char and sym_char_class.
        # If the reverse is True then change order self and compSymbol.

        # compSymbol type sym_char ; reverse = False
        a = b_Sym_char('a', 'a', 0)
        b = b_Sym_char('b', 'b', 1)
        local_chars = list()
        chars = set()
        for i in range(0, 256):
            chars.add(chr(i))
        local_chars.append(chars)

        new_kchar = a.compute_double_stride(b, False, 2, local_chars)[0]
        new_local_chars = a.compute_double_stride(b, False, 2, local_chars)[1]

        reference_kchar = b_Sym_kchar("ab", ('a', 'b'), 2)
        reference_kchar_2 = \
            b_Sym_kchar("ab", (frozenset(['a']),frozenset(['b'])), 2)
        reference_kchar.last = 2
        reference_kchar_2.last = 2
        reference_local_chars = local_chars[0] - set([b.char])

        self.assertTrue(new_kchar == reference_kchar
                        or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 2)

        # compSymbol type sym_char_class ; reverse = False
        a = b_Sym_char('a', 'a', 0)
        bc = b_Sym_char_class("set(['b', 'c'])", set(['b', 'c']), 1)
        local_chars = list()
        chars = set()
        for i in range(0, 256):
            chars.add(chr(i))
        local_chars.append(chars)

        new_kchar = a.compute_double_stride(bc, False, 3, local_chars)[0]
        new_local_chars = a.compute_double_stride(bc, False, 3, local_chars)[1]

        reference_kchar = b_Sym_kchar("a[bc]", ('a', set(['b', 'c'])), 2)
        reference_kchar_2 = \
            b_Sym_kchar("a[bc]", (frozenset(['a']),frozenset(['b','c'])), 2)
        reference_kchar.last = 3
        reference_kchar_2.last = 3
        reference_local_chars = local_chars[0] - bc.charClass

        self.assertTrue(new_kchar == reference_kchar
                        or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 3)

        # compSymbol type sym_char ; reverse = True
        a = b_Sym_char('a', 'a', 0)
        b = b_Sym_char('b', 'b', 1)
        local_chars = list()
        chars = set()
        for i in range(0, 256):
            chars.add(chr(i))
        local_chars.append(chars)

        new_kchar = a.compute_double_stride(b, True, 2, local_chars)[0]
        new_local_chars = a.compute_double_stride(b, True, 2, local_chars)[1]

        reference_kchar = b_Sym_kchar("ba", ('b', 'a'), 2)
        reference_kchar_2 = \
            b_Sym_kchar("ba", (frozenset(['b']),frozenset(['a'])), 2)
        reference_kchar.last = 2
        reference_kchar_2.last = 2
        reference_local_chars = local_chars[0] - set([a.char])

        self.assertTrue(new_kchar == reference_kchar
                        or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 2)
예제 #23
0
 def test_export_symbol(self):
     """export_symbol()"""
     # Check correct output.
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.export_symbol() == "40000|61|62|63")
예제 #24
0
    def test_compute_double_stride(self):
        """compute_double_stride()"""
        # Method compute_double_stride(compSymbol, reverse, last, local_chars)
        # Test with compSymbol type sym_char and sym_char_class.
        # If the reverse is True then change order self and compSymbol.

        # compSymbol type sym_char ; reverse = False
        a = b_Sym_char('a', 'a', 0)
        b = b_Sym_char('b', 'b', 1)
        local_chars = list()
        chars = set()
        for i in range(0,256):
            chars.add(chr(i))
        local_chars.append(chars)

        new_kchar = a.compute_double_stride(b, False, 2, local_chars)[0]
        new_local_chars = a.compute_double_stride(b, False, 2, local_chars)[1]

        reference_kchar = b_Sym_kchar("ab", ('a','b'), 2)
        reference_kchar_2 = \
            b_Sym_kchar("ab", (frozenset(['a']),frozenset(['b'])), 2)
        reference_kchar.last = 2
        reference_kchar_2.last = 2
        reference_local_chars = local_chars[0] - set([b.char])

        self.assertTrue(new_kchar == reference_kchar
            or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 2)

        # compSymbol type sym_char_class ; reverse = False
        a = b_Sym_char('a', 'a', 0)
        bc = b_Sym_char_class("set(['b', 'c'])", set(['b', 'c']), 1)
        local_chars = list()
        chars = set()
        for i in range(0,256):
            chars.add(chr(i))
        local_chars.append(chars)

        new_kchar = a.compute_double_stride(bc, False, 3, local_chars)[0]
        new_local_chars = a.compute_double_stride(bc, False, 3, local_chars)[1]

        reference_kchar = b_Sym_kchar("a[bc]", ('a',set(['b', 'c'])), 2)
        reference_kchar_2 = \
            b_Sym_kchar("a[bc]", (frozenset(['a']),frozenset(['b','c'])), 2)
        reference_kchar.last = 3
        reference_kchar_2.last = 3
        reference_local_chars = local_chars[0] - bc.charClass

        self.assertTrue(new_kchar == reference_kchar
            or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 3)

        # compSymbol type sym_char ; reverse = True
        a = b_Sym_char('a', 'a', 0)
        b = b_Sym_char('b', 'b', 1)
        local_chars = list()
        chars = set()
        for i in range(0,256):
            chars.add(chr(i))
        local_chars.append(chars)

        new_kchar = a.compute_double_stride(b, True, 2, local_chars)[0]
        new_local_chars = a.compute_double_stride(b, True, 2, local_chars)[1]

        reference_kchar = b_Sym_kchar("ba", ('b','a'), 2)
        reference_kchar_2 = \
            b_Sym_kchar("ba", (frozenset(['b']),frozenset(['a'])), 2)
        reference_kchar.last = 2
        reference_kchar_2.last = 2
        reference_local_chars = local_chars[0] - set([a.char])

        self.assertTrue(new_kchar == reference_kchar
            or new_kchar == reference_kchar_2)
        self.assertTrue(new_local_chars[0] == reference_local_chars)
        self.assertTrue(new_kchar.last == 2)
예제 #25
0
 def test_export_symbol(self):
     """export_symbol()"""
     # Check correct output.
     abc = b_Sym_kchar("abc", ('a', 'b', 'c'), 0)
     self.assertTrue(abc.export_symbol() == "40000|61|62|63")