def test_accept(self): """accept()""" # method accept(text): # Check return text if self.string == "" empty = b_Sym_string("", "", 0) self.assertTrue(empty.accept("hello") == "hello") # Chech if len(text) < len(self.string) then exception # symbol_string_to_short is thrown. abcd = b_Sym_string("abcd", "abcd", 0) try: abcd.accept("ba") self.assertTrue(False) except symbol_string_to_short: self.assertTrue(True) # Check if self.string is equal begin of text then is returned value # text[len(self.string):] abcd = b_Sym_string("abcd", "abcd", 0) self.assertTrue(abcd.accept("abcdefg") == "efg") # In case that self.string is not equal begin of text then is # thrown exception symbol_accept_exception abcd = b_Sym_string("abcd", "abcd", 0) try: abcd.accept("different_text") self.assertTrue(False) except symbol_accept_exception: self.assertTrue(True)
def test_is_empty(self): """is_empty()""" # Check return True for len(self.string) == 0, otherwise return False. hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.is_empty() == False) empty = b_Sym_string("empty", "", 1) self.assertTrue(empty.is_empty() == True)
def test_is_empty(self): """is_empty()""" # Check return True for len(self.string) == 0, otherwise return False. hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.is_empty() == False) empty = b_Sym_string("empty", "", 1) self.assertTrue(empty.is_empty() == True)
def test_compute_equal(self): """compute_equal()""" # method compute_equal(other): # If is other object of class sym_string, then return True if are # their arguments string same. hello = b_Sym_string("hello", "hello", 0) abba = b_Sym_string("abba", "abba", 1) self.assertTrue(hello.compute_equal(abba) == False) hello_2 = b_Sym_string("hello_2", "hello", 2) self.assertTrue(hello.compute_equal(hello_2) == True) # If is other object of type sym_char, then return True if is length # of string equal to 1 and argument char is same as argument string. hello_short = b_Sym_string("h", "h", 0) a = b_Sym_char('a', 'a', 1) self.assertTrue(hello_short.compute_equal(a) == False) h = b_Sym_char('h', 'h', 2) self.assertTrue(hello_short.compute_equal(h) == True) # If is other object of class sym_char_class, then return True if is # len(other.charClass) == 1, length string equal to 1 and values of # arguments string and charClass are same. hello_short = b_Sym_string("h", "h", 0) set_a = b_Sym_char_class('[a]', set(['a']), 1) self.assertTrue(hello_short.compute_equal(set_a) == False) set_h = b_Sym_char_class('[h]', set(['h']), 2) self.assertTrue(hello_short.compute_equal(set_h) == True)
def test_compute_equal(self): """compute_equal()""" # method compute_equal(other): # If is other object of class sym_string, then return True if are # their arguments string same. hello = b_Sym_string("hello", "hello", 0) abba = b_Sym_string("abba", "abba", 1) self.assertTrue(hello.compute_equal(abba) == False) hello_2 = b_Sym_string("hello_2", "hello", 2) self.assertTrue(hello.compute_equal(hello_2) == True) # If is other object of type sym_char, then return True if is length # of string equal to 1 and argument char is same as argument string. hello_short = b_Sym_string("h", "h", 0) a = b_Sym_char('a', 'a', 1) self.assertTrue(hello_short.compute_equal(a) == False) h = b_Sym_char('h', 'h', 2) self.assertTrue(hello_short.compute_equal(h) == True) # If is other object of class sym_char_class, then return True if is # len(other.charClass) == 1, length string equal to 1 and values of # arguments string and charClass are same. hello_short = b_Sym_string("h", "h", 0) set_a = b_Sym_char_class('[a]', set(['a']), 1) self.assertTrue(hello_short.compute_equal(set_a) == False) set_h = b_Sym_char_class('[h]', set(['h']), 2) self.assertTrue(hello_short.compute_equal(set_h) == True)
def test_accept(self): """accept()""" # method accept(text): # Check return text if self.string == "" empty = b_Sym_string("", "", 0) self.assertTrue(empty.accept("hello") == "hello") # Chech if len(text) < len(self.string) then exception # symbol_string_to_short is thrown. abcd = b_Sym_string("abcd", "abcd", 0) try: abcd.accept("ba") self.assertTrue(False) except symbol_string_to_short: self.assertTrue(True) # Check if self.string is equal begin of text then is returned value # text[len(self.string):] abcd = b_Sym_string("abcd", "abcd", 0) self.assertTrue(abcd.accept("abcdefg") == "efg") # In case that self.string is not equal begin of text then is # thrown exception symbol_accept_exception abcd = b_Sym_string("abcd", "abcd", 0) try: abcd.accept("different_text") self.assertTrue(False) except symbol_accept_exception: self.assertTrue(True)
def test_collision(self): """collision()""" # method collision(set_of_symbols): # Try with suitable objects of class sym_char, sym_char_class, # sym_string. Check correct output. abcd = b_Sym_string("abcd", "abcd", 0) e = b_Sym_char('e', 'e', 1) fg = b_Sym_char_class("[fg]", set(['f', 'g']), 2) hello = b_Sym_string("hello", "hello", 3) set_of_symbols = set([e, fg, hello]) self.assertTrue(abcd.collision(set_of_symbols) == False) a = b_Sym_char('a', 'a', 4) set_of_symbols.add(a) self.assertTrue(abcd.collision(set_of_symbols) == True) set_of_symbols.remove(a) self.assertTrue(abcd.collision(set_of_symbols) == False) ab = b_Sym_char_class("[ab]", set(['a', 'b']), 5) set_of_symbols.add(ab) self.assertTrue(abcd.collision(set_of_symbols) == True) set_of_symbols.remove(ab) self.assertTrue(abcd.collision(set_of_symbols) == False) abcd_2 = b_Sym_string("abcd_2", "abcd", 6) set_of_symbols.add(abcd_2) self.assertTrue(abcd.collision(set_of_symbols) == True)
def test_collision(self): """collision()""" # method collision(set_of_symbols): # Try with suitable objects of class sym_char, sym_char_class, # sym_string. Check correct output. abcd = b_Sym_string("abcd", "abcd", 0) e = b_Sym_char('e', 'e', 1) fg = b_Sym_char_class("[fg]", set(['f', 'g']), 2) hello = b_Sym_string("hello", "hello", 3) set_of_symbols = set([e, fg, hello]) self.assertTrue(abcd.collision(set_of_symbols) == False) a = b_Sym_char('a', 'a', 4) set_of_symbols.add(a) self.assertTrue(abcd.collision(set_of_symbols) == True) set_of_symbols.remove(a) self.assertTrue(abcd.collision(set_of_symbols) == False) ab = b_Sym_char_class("[ab]", set(['a', 'b']), 5) set_of_symbols.add(ab) self.assertTrue(abcd.collision(set_of_symbols) == True) set_of_symbols.remove(ab) self.assertTrue(abcd.collision(set_of_symbols) == False) abcd_2 = b_Sym_string("abcd_2", "abcd", 6) set_of_symbols.add(abcd_2) self.assertTrue(abcd.collision(set_of_symbols) == True)
def test_collision(self): """collision()""" # method collision(set_of_symbols): # Try with suitable objects class sym_char, sym_char_class, # sym_string. Check correct output (is / is not collision). sym_char = b_Sym_char('a', 'a', 1) other_sym_char = b_Sym_char('b', 'b', 2) sym_char_class = b_Sym_char_class("set(['c', 'd'])", set(['c', 'd']), 3) sym_string = b_Sym_string("adam", "adam", 4) set_of_symbols = set([other_sym_char, sym_char_class, sym_string]) self.assertTrue(sym_char.collision(set_of_symbols) == True) sym_string = b_Sym_string("eva", "eva", 4) set_of_symbols = set([other_sym_char, sym_char_class, sym_string]) self.assertTrue(sym_char.collision(set_of_symbols) == False)
def test_get_support_type(self): """get_support_type()""" # Check return [io_mapper["b_Sym_char"], io_mapper["b_Sym_char_class"], # io_mapper["b_Sym_string"]] hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.get_support_type() == [io_mapper["b_Sym_char"], io_mapper["b_Sym_char_class"], io_mapper["b_Sym_string"]])
def test_collision(self): """collision()""" # method collision(set_of_symbols): # Try with suitable objects class sym_char, sym_char_class, # sym_string. Check correct output (is / is not collision). sym_char = b_Sym_char('a', 'a', 1) other_sym_char = b_Sym_char('b', 'b', 2) sym_char_class = b_Sym_char_class("set(['c', 'd'])", set(['c', 'd']), 3) sym_string = b_Sym_string("adam", "adam", 4) set_of_symbols = set([other_sym_char, sym_char_class, sym_string]) self.assertTrue(sym_char.collision(set_of_symbols) == True) sym_string = b_Sym_string("eva", "eva", 4) set_of_symbols = set([other_sym_char, sym_char_class, sym_string]) self.assertTrue(sym_char.collision(set_of_symbols) == False)
def test_get_support_type(self): """get_support_type()""" # Check return [io_mapper["b_Sym_char"], io_mapper["b_Sym_char_class"], # io_mapper["b_Sym_string"]] hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.get_support_type() == [ io_mapper["b_Sym_char"], io_mapper["b_Sym_char_class"], io_mapper["b_Sym_string"] ])
def test_import_symbol(self): """import_symbol()""" # Check that is text_repr created and returned correctly and having # set self._id on tid and all parametrs are correct set. hello = b_Sym_string("hello", "hello", 0) hello.import_symbol("24a41524f534c4156", 1) self.assertTrue(hello._id == 1) self.assertTrue(hello.string == "JAROSLAV") self.assertTrue(hello._text == "JAROSLAV") # Check, if text_repr is representation of different type, then # thrown exception symbol_import_exception. hello = b_Sym_string("hello", "hello", 0) try: hello.import_symbol("14a41524f534c4156", 1) self.assertTrue(False) except symbol_import_exception: self.assertTrue(True)
def test_import_symbol(self): """import_symbol()""" # Check that is text_repr created and returned correctly and having # set self._id on tid and all parametrs are correct set. hello = b_Sym_string("hello", "hello", 0) hello.import_symbol("24a41524f534c4156", 1) self.assertTrue(hello._id == 1) self.assertTrue(hello.string == "JAROSLAV") self.assertTrue(hello._text == "JAROSLAV") # Check, if text_repr is representation of different type, then # thrown exception symbol_import_exception. hello = b_Sym_string("hello", "hello", 0) try: hello.import_symbol("14a41524f534c4156", 1) self.assertTrue(False) except symbol_import_exception: self.assertTrue(True)
def test_collision(self): """collision()""" # method collision(set_of_symbols): # Try with suitable objects class sym_char, sym_char_class, # sym_string, sym_cnt_constr. Check correct output # (is / is not collision). ac = b_Sym_cnt_constr('a', 'a', 3, 5, 0) bc = b_Sym_cnt_constr('b', 'b', 3, 5, 0) b = b_Sym_char('b', 'b', 0) cd = b_Sym_char_class("set(['c', 'd'])", set(['c', 'd']), 1) adam = b_Sym_string("baba", "baba", 3) set_of_symbols = set([b, bc, cd, adam]) self.assertTrue(ac.collision(set_of_symbols) == False) c = b_Sym_cnt_constr('a', 'a', 1, 9, 0) set_of_symbols = set([c, b, bc, cd, adam]) self.assertTrue(ac.collision(set_of_symbols) == True) c = b_Sym_char('a', 'a', 0) set_of_symbols = set([c, b, bc, cd, adam]) self.assertTrue(ac.collision(set_of_symbols) == True) c = b_Sym_char_class("set(['a', 'd'])", set(['a', 'd']), 1) set_of_symbols = set([c, b, bc, cd, adam]) self.assertTrue(ac.collision(set_of_symbols) == True) c = b_Sym_char('a', 'a', 0) set_of_symbols = set([c, b, bc, cd, adam]) self.assertTrue(ac.collision(set_of_symbols) == True) c = b_Sym_string("aaaa", "aaaa", 3) set_of_symbols = set([c, b, bc, cd, adam]) self.assertTrue(ac.collision(set_of_symbols) == True) c = b_Sym_string("aa", "aa", 3) set_of_symbols = set([c, b, bc, cd, adam]) self.assertTrue(ac.collision(set_of_symbols) == True) c = b_Sym_string("aaaaaaaaaaaa", "aaaaaaaaaaaa", 3) set_of_symbols = set([c, b, bc, cd, adam]) self.assertTrue(ac.collision(set_of_symbols) == True)
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)
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)
def test_collision(self): """collision()""" # method collision(set_of_symbols): # Try with suitable objects class sym_char, sym_char_class, # sym_string. Check correct output (is / is not collision). a = b_Sym_char('a', 'a', 0) cd = b_Sym_char_class("set(['c', 'd'])", set(['c', 'd']), 1) ef = b_Sym_char_class("set(['e', 'f'])", set(['e', 'f']), 2) adam = b_Sym_string("baba", "baba", 3) set_of_symbols = set([a, cd, adam]) self.assertTrue(ef.collision(set_of_symbols) == False) fg = b_Sym_char_class("set(['f', 'g'])", set(['f', 'g']), 4) set_of_symbols = set([a, fg, adam]) self.assertTrue(ef.collision(set_of_symbols) == True)
def test___str__(self): """__str__()""" # Check return self.string. hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.__str__() == hello.string)
def test___hash__(self): """__hash__()""" # Check return hash(self.string). hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.__hash__() == hash(hello.string))
def test___repr__(self): """__repr__()""" # Check return repr(self.string). hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.__repr__() == repr(hello.string))
def test___hash__(self): """__hash__()""" # Check return hash(self.string). hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.__hash__() == hash(hello.string))
def test___repr__(self): """__repr__()""" # Check return repr(self.string). hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.__repr__() == repr(hello.string))
def test___str__(self): """__str__()""" # Check return self.string. hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.__str__() == hello.string)
def test_export_symbol(self): """export_symbol()""" # Check return correct representation of symbol. hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.export_symbol() == "268656c6c6f")
def test_export_symbol(self): """export_symbol()""" # Check return correct representation of symbol. hello = b_Sym_string("hello", "hello", 0) self.assertTrue(hello.export_symbol() == "268656c6c6f")