Exemple #1
0
def match(costs):

    start = time()
    m = munkres.Munkres()
    match = m.compute(costs.copy())
    print("Munkres: %fs"%(time()-start))
    print(match)

    start = time()
    match = pymatch.match(costs.copy())
    print("pymatch: %fs"%(time()-start))
    print(match)
Exemple #2
0
 def test_match_no_tuple_types(self):
     result = match([((bool, bool, bool), lambda i: True)], (4, 5, 6))
     assert result is None
Exemple #3
0
 def test_match_partial_tuple_types(self):
     result = match([((int, int, bool), lambda i, j, k: True)], (1, 2, 4))
     assert result is None
Exemple #4
0
 def test_match_tuple_types(self):
     result = match([((int, int, int), lambda i, j, k: True)], (1, 2, 3))
     assert result
Exemple #5
0
 def test_no_patterns(self):
     result = match([], "Hello World")
     assert result is None
Exemple #6
0
 def test_match_no_tuple_values(self):
     result = match([((1, 2, 3), lambda i: True)], (4, 5, 6))
     assert result is None
Exemple #7
0
 def test_does_not_match(self):
     result = match([(int, lambda i: i + 1)], "Hello World")
     assert result is None
Exemple #8
0
 def test_first_match(self):
     result = match([(int, lambda i: True), (any, lambda i: False)],
                    "hello")
     assert not result
Exemple #9
0
 def test_match_regex(self):
     result = match([(Regex("^abc[a-z]*"), lambda i: True)], "abcdefg")
     assert result
Exemple #10
0
 def test_match_basic_bool(self):
     match = pattern((bool, lambda i: False))
     result = match(True)
     assert not result
Exemple #11
0
 def test_match_basic_float(self):
     match = pattern((float, lambda i: i + 1))
     result = match(0.0)
     assert result == 1.0
Exemple #12
0
 def test_match_basic_int(self):
     match = pattern((int, lambda i: i + 1))
     result = match(0)
     assert result == 1
Exemple #13
0
 def test_match_basic_str(self):
     match = pattern((str, lambda i: "goodbye"))
     result = match("Hello World")
     assert result == "goodbye"
Exemple #14
0
 def test_does_not_match_pattern(self):
     match = pattern((int, lambda i: i + 1))
     result = match("Hello World")
     assert result is None
Exemple #15
0
 def test_match_partial_tuple_types_etc(self):
     result = match([((int, int, etc), lambda i, j, k, l, m: True)],
                    (1, 2, 6, 7, 8))
     assert result
Exemple #16
0
 def test_first_match(self):
     result = match([(int, lambda i: True), (int, lambda i: False)], 1)
     assert result
Exemple #17
0
 def test_match_tuple_values(self):
     result = match([((1, 2, 3), lambda i, j, k: True)], (1, 2, 3))
     assert result
Exemple #18
0
 def test_match_partial_tuple_values(self):
     result = match([((1, 2, 3), lambda i, j, k: True)], (1, 2, 4))
     assert result is None
Exemple #19
0
 def test_no_patterns_pattern(self):
     match = pattern()
     result = match("Hello World")
     assert result is None