Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
    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))
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
 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]))