コード例 #1
0
ファイル: actions.py プロジェクト: xihuni/polypyus
def makeGraph(matchers: Iterable[Matcher] = None) -> Graph:
    if matchers is None:
        matchers = Matcher.select(
            lambda matcher: matcher.type_ == "Fuzzy-bytes")
    match_graph = Graph()
    for matcher in matchers:
        match_graph.insert(matcher.comparer(), matcher)
    return match_graph
コード例 #2
0
ファイル: actions.py プロジェクト: xihuni/polypyus
def start_matchers_graph(
        start_matchers: Iterable[StartMatcher] = None) -> Graph:
    if start_matchers is None:
        start_matchers = StartMatcher.select()
    start_graph = Graph()
    for matcher in start_matchers:
        start_graph.insert(matcher.comparer(), matcher)
    return start_graph
コード例 #3
0
ファイル: test_graph.py プロジェクト: ycmint/polypyus
 def test_identity_matching(self, match):
     assume(match)
     match_frag = MatchFragment(match)
     graph = Graph()
     graph.insert(match_frag, match)
     matches = list(graph.match(match))
     note(
         f"frag: {match_frag}, target: {match}, matches: {matches}, graph: {graph}"
     )
     self.assertIn(([match], len(match), len(match)), matches)
コード例 #4
0
ファイル: test_graph.py プロジェクト: ycmint/polypyus
    def test_data_existence(self, data):
        graph = Graph()
        for binary in data:
            graph.insert(MatchFragment(binary), binary)

        g_data = list(itertools.chain.from_iterable(graph.data.values()))
        self.assertEqual(len(g_data), len(data))

        for binary in data:
            self.assertIn(binary, g_data)
コード例 #5
0
ファイル: test_graph.py プロジェクト: ycmint/polypyus
class TestShortWildCardEdges(unittest.TestCase):
    def setUp(self):
        self.g = Graph()
        self.a = MatchFragment(b"a", bytes([1]))
        self.b = MatchFragment(b"ba", bytes([1, 1]))
        self.c = MatchFragment(b"ccc", bytes([1, 1, 1]))

    def test_longest_common_prefix(self):
        self.assertEqual(self.a.longest_common_prefix(self.b), 1)
        self.assertEqual(self.b.longest_common_prefix(self.a),
                         self.a.longest_common_prefix(self.b))
        self.assertEqual(self.c.longest_common_prefix(self.a), 1)
        self.assertEqual(self.b.longest_common_prefix(self.c), 2)

    def test_minimality(self):
        self.g.insert(self.a, "a")
        self.g.insert(self.b, "b")
        self.g.insert(self.c, "c")
        self.assertEqual(len(list(self.g.edges_at(0))), 1)
コード例 #6
0
ファイル: test_graph.py プロジェクト: ycmint/polypyus
    def test_graph_constraints(self, data):
        graph = Graph()
        for binary in data:
            graph.insert(MatchFragment(binary), binary)

        self.assertLessEqual(len(list(graph.edges_at(0))), len(data))

        if data:
            self.assertEqual(max(len(binary) for binary in data),
                             graph._get_max_match_size(0))
コード例 #7
0
ファイル: test_graph.py プロジェクト: ycmint/polypyus
 def setUp(self):
     self.g = Graph()
     self.a = MatchFragment(b"a", bytes([1]))
     self.b = MatchFragment(b"ba", bytes([1, 1]))
     self.c = MatchFragment(b"ccc", bytes([1, 1, 1]))