예제 #1
0
    def test_matches_partial(self):
        pattern = BlacklistParser.parse("""
        misses 2
        xx...xx
        x.....x
        """)

        self.assertTrue(pattern.matches(Tipp([
            1, 2, 6, 7])))
        self.assertFalse(pattern.matches(Tipp([
            1, 2, 6])))

        # note: 2 instead of 1 would not match!
        self.assertTrue(pattern.matches(Tipp([
            1, 6, 8, 14])))

        pattern = BlacklistParser.parse("""
        misses 2
        xxxxxx
        """)

        self.assertTrue(pattern.matches(Tipp([
            1, 2, 3, 4, 5, 6])))
        self.assertTrue(pattern.matches(Tipp([
            2, 3, 4, 5, 6])))
        self.assertTrue(pattern.matches(Tipp([
            2, 3, 4, 5])))
        self.assertTrue(pattern.matches(Tipp([
            1, 2, 5, 6])))

        self.assertFalse(pattern.matches(Tipp([
            1, 2, 3])))
예제 #2
0
    def test_misses(self):
        blacklist_item = BlacklistParser.parse("""
        misses 2
        xx
        .x
        """)
        self.assertEqual(blacklist_item.get_coords(), [[0,0], [1,0], [1,1]])
        self.assertEqual(blacklist_item.get_misses(), 2)

        blacklist_item2 = BlacklistParser.parse("""
        missing 3
        x
        """)
        self.assertEqual(blacklist_item2.get_coords(), [[0,0]])
        self.assertEqual(blacklist_item2.get_misses(), 3)
예제 #3
0
    def test_matches_complex(self):
        pattern = BlacklistParser.parse("""
        xx...xx
        x.....x
        ...x...
        x.....x
        xx...xx
        """)

        self.assertTrue(pattern.matches(Tipp([
            1, 2, 6, 7,
            8, 14,
            18,
            22, 28,
            29, 30, 34, 35])))

        self.assertFalse(pattern.matches(Tipp([
            1, 2, 6, 7,
            8, 14,
            22, 28,
            29, 30, 34, 35])))

        self.assertTrue(pattern.matches(Tipp([
            8, 9, 13, 14,
            15, 21,
            25,
            29, 35,
            36, 37, 41, 42])))
예제 #4
0
    def test_rotate_multi(self):
        blacklist_item = BlacklistParser.parse("""
        name Rotate Test Multi
        transform L, R, M, F
        xxx
        x
        """)

        self.assertEqual(len(blacklist_item.get_patterns()), 5)
        ori = blacklist_item.get_patterns()[0]
        rot_l = blacklist_item.get_patterns()[1]
        rot_r = blacklist_item.get_patterns()[2]
        mirrored = blacklist_item.get_patterns()[3]
        flipped = blacklist_item.get_patterns()[4]
        self.assertEqual(ori.get_name(), "Rotate Test Multi")
        self.assertEqual(rot_l.get_name(), "Rotate Test Multi L")
        self.assertEqual(rot_r.get_name(), "Rotate Test Multi R")
        self.assertEqual(mirrored.get_name(), "Rotate Test Multi M")
        self.assertEqual(flipped.get_name(), "Rotate Test Multi F")

        self.assertEqual(ori.get_coords(), [[0,0],[1, 0],[2,0],[0,1]])
        self.assertEqual(rot_l.get_coords(), [[0,0],[0, 1],[0,2],[1,2]])
        self.assertEqual(rot_r.get_coords(), [[0,0],[1, 0],[1,1],[1,2]])
        self.assertEqual(mirrored.get_coords(),  [[0,0],[1, 0],[2,0],[2,1]])
        self.assertEqual(flipped.get_coords(),  [[0,0],[0,1],[1, 1],[2,1]])
예제 #5
0
 def test_name(self):
     blacklist_item = BlacklistParser.parse("""
     name Prince Albert
     misses 1
     x
     """)
     self.assertEqual(blacklist_item.get_name(), "Prince Albert")
     self.assertEqual(blacklist_item.get_coords(), [[0,0]])
     self.assertEqual(blacklist_item.get_misses(), 1)
예제 #6
0
    def test_match_out_of_bounds(self):
        blacklist_item = BlacklistParser.parse("""
        misses 2
        transform M
          ...x
          xxxx
        """)

        self.assertTrue(
            blacklist_item.matches(Tipp([1, 16, 24, 38, 40, 41, 42])))
예제 #7
0
    def test_2d(self):
        self.assertEqual(BlacklistParser.parse("""
        x..
        .x.
        ..x
        """).get_coords(), [[0,0], [1,1], [2,2]])

        self.assertEqual(BlacklistParser.parse("""
        xx...xx
        x.....x
        ...x...
        x.....x
        xx...xx
        """).get_coords(), [
            [0,0], [1,0],[5,0],[6,0],
            [0,1],             [6,1],
                     [3,2]          ,
            [0,3],             [6,3],
            [0,4], [1,4],[5,4],[6,4]]
        )
예제 #8
0
    def test_parse_number(self):
        blacklist_item = BlacklistParser.parse("""
        name numbers1
        misses 1
        numbers 5, 10, 15, 20, 25, 30
        """)

        self.assertEqual(blacklist_item.get_coords(), [[4,0],[2,1],[0,2],[5,2],[3,3],[1,4]])
        self.assertTrue(blacklist_item.matches(Tipp([5, 10, 15, 20, 25, 30])))
        self.assertTrue(blacklist_item.matches(Tipp([4, 10, 15, 20, 25, 30])))
        self.assertFalse(blacklist_item.matches(Tipp([4, 9, 15, 20, 25, 30])))
예제 #9
0
 def test_dimension(self):
     bl_item = BlacklistParser.parse("""
     x.x.x
     .x...
     ....x
     """)
     pattern = bl_item.get_main_pattern()
     #self.assertEqual(pattern.width, 5)
     #self.assertEqual(pattern.height, 3)
     # unexpected but it was better to calc with 0 based "width"
     self.assertEqual(pattern.width, 4)
     self.assertEqual(pattern.height, 2)
예제 #10
0
    def test_matches(self):
        self.line = BlacklistParser.parse('xxxx')

        self.assertTrue(self.line.matches(Tipp([1, 2, 3, 4])))
        self.assertTrue(self.line.matches(Tipp([3, 4, 5, 6])))

        self.assertTrue(self.line.matches(Tipp([43, 44, 45, 46])))
        self.assertTrue(self.line.matches(Tipp([46, 47, 48, 49])))

        self.assertTrue(self.line.matches(Tipp([2, 3, 4, 5, 6, 7])))

        self.assertFalse(self.line.matches(Tipp([2, 3, 4, 12, 6, 7])))
예제 #11
0
    def test_rotate_zero_based(self):
        blacklist_item = BlacklistParser.parse("""
        name Rotate Test Zero
        transform L
        misses 1
        x.x.x
        x
        """)

        self.assertEqual(len(blacklist_item.get_patterns()), 2)
        rot_r = blacklist_item.get_patterns()[1]
        self.assertEqual(rot_r.get_coords(), [[0,0],[0,2],[0,4],[1,4]])
예제 #12
0
    def test_rotate_name(self):
        blacklist_item = BlacklistParser.parse("""
        name Rotate Test
        transform L
        misses 1
        x
        """)

        self.assertEqual(len(blacklist_item.get_patterns()), 2)
        original = blacklist_item.get_patterns()[0]
        rot_r = blacklist_item.get_patterns()[1]
        self.assertEqual(original.get_name(), "Rotate Test")
        self.assertEqual(rot_r.get_name(), "Rotate Test L")
예제 #13
0
    def test_rotate_relocate(self):
        blacklist_item = BlacklistParser.parse("""
        name Rotate Test Relocate
        transform L
        ..
        xx
        """)

        self.assertEqual(len(blacklist_item.get_patterns()), 2)
        original = blacklist_item.get_patterns()[0]
        rot_r = blacklist_item.get_patterns()[1]

        self.assertEqual(original.get_coords(), [[0,1],[1, 1]])
        self.assertEqual(rot_r.get_coords(), [[0,0],[0,1]])
예제 #14
0
    def test_match_small(self):
        blacklist_item = BlacklistParser.parse("""
        misses 1
          xx
          xx
        """)

        self.assertTrue(
            blacklist_item.matches(Tipp([1, 23, 24, 30, 31, 34, 43])))
        self.assertTrue(blacklist_item.matches(Tipp([6, 7, 13, 14, 9, 37,
                                                     49])))
        self.assertTrue(
            blacklist_item.matches(Tipp([41, 42, 48, 49, 9, 37, 2])))
        self.assertTrue(
            blacklist_item.matches(Tipp([41, 42, 48, 49, 9, 37, 2])))
예제 #15
0
    def test_match_with_misses_big(self):
        blacklist_item = BlacklistParser.parse("""
        misses 2
        transform R
          x..
          .x
          ..x
          ...x
          ....x
          .....x
        """)

        self.assertTrue(
            blacklist_item.matches(Tipp([9, 17, 25, 33, 41, 3, 12])))
        self.assertTrue(
            blacklist_item.matches(Tipp([43, 37, 19, 13, 7, 1, 31])))
예제 #16
0
    def test_misses_big(self):
        blacklist_item = BlacklistParser.parse("""
        misses 2
          .....x
          ....x
          ...x
          ..x
          .x
          x
        """)

        self.assertTrue(blacklist_item.matches(Tipp([43, 37, 31, 25, 19, 13])))
        self.assertTrue(blacklist_item.matches(Tipp([43, 37, 19, 13, 7, 31])))
        self.assertTrue(blacklist_item.matches(Tipp([37, 31, 25, 19, 4, 2])))
        self.assertTrue(blacklist_item.matches(Tipp([44, 38, 32, 26, 4, 2])))
        self.assertTrue(blacklist_item.matches(Tipp([14, 20, 26, 32, 48, 3])))
예제 #17
0
 def test_matches_simple(self):
     self.line = BlacklistParser.parse('xxxx')
     self.assertTrue(self.line.matches(Tipp([1, 2, 3, 4])))
예제 #18
0
 def test_oneline(self):
     self.assertEqual(BlacklistParser.parse('x').get_coords(), [[0,0]])
     self.assertEqual(BlacklistParser.parse('x.').get_coords(), [[0,0]])
     self.assertEqual(BlacklistParser.parse('xx').get_coords(), [[0,0], [1,0]])
     self.assertEqual(BlacklistParser.parse('x.x').get_coords(), [[0,0], [2,0]])
예제 #19
0
 def test_empty(self):
     self.assertRaises(ValueError, lambda: BlacklistParser.parse("").get_coords())
예제 #20
0
 def __init__(self):
     self.patterns = [BlacklistParser.parse(ps) for ps in PATTERNS]
     self.patterns.append(BlacklistItemDate())
예제 #21
0
 def setUp(self):
     self.line = BlacklistParser.parse('xxxx')