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])))
def test_diagonal(self): bl = Blacklist() self.assertTrue(bl.contains(Tipp([1, 9, 17, 25, 33, 41]))) self.assertTrue(bl.contains(Tipp([9, 17, 25, 33, 41, 49]))) self.assertTrue(bl.contains(Tipp([1, 9, 17, 33, 41, 3]))) self.assertTrue(bl.contains(Tipp([9, 17, 25, 33, 41, 5]))) self.assertTrue(bl.contains(Tipp([29, 23, 17, 11, 5, 9])))
class TestTipp(unittest.TestCase): def setUp(self): self.tipp = Tipp([1, 7, 14, 36, 46, 49]) def test_get_coords(self): self.assertEqual(self.tipp.get_coords(), [[0, 0], [6, 0], [6, 1], [0, 5], [3, 6], [6, 6]]) def test_get_coords_set(self): self.assertEqual(self.tipp.get_coords_set(), {(0, 0), (6, 0), (6, 1), (0, 5), (3, 6), (6, 6)})
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])))
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])))
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])))
def test_write(self): q = Quicktipp() q.tipps = [Tipp([1, 2, 3, 4, 5, 6]), Tipp([7, 14, 21, 28, 35, 42])] q.skipped = [ SkippedTipp(Tipp([2, 3, 4, 5, 6, 7]), 'mock1'), SkippedTipp(Tipp([8, 15, 22, 29, 36, 43]), 'mock2') ] self.assertEqual( write_to_journal_str(q, self.now), """ 2019-07-18T21:08:00: skipped 2 3 4 5 6 7 mock1 2019-07-18T21:08:00: skipped 8 15 22 29 36 43 mock2 2019-07-18T21:08:00: tipp 1 2 3 4 5 6 2019-07-18T21:08:00: tipp 7 14 21 28 35 42 """.lstrip())
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])))
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])))
def test_regular(self): item = BlacklistItemDate() self.assertTrue(item.matches(Tipp([1,2,19,40,44,39,38]))) self.assertTrue(item.matches(Tipp([3,6,19,40,45,48,49]))) self.assertTrue(item.matches(Tipp([3,10,19,40,20,30,49]))) self.assertFalse(item.matches(Tipp([1,2,20,40,44,39,38]))) self.assertTrue(item.matches(Tipp([1,2,20,30,44,39,38]))) self.assertFalse(item.matches(Tipp([1,2,10,40,44,39,38]))) self.assertFalse(item.matches(Tipp([1,2,3,4,5,19]))) self.assertFalse(item.matches(Tipp([30,32,33,44,39,38])))
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])))
def test_matches(self): 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])))
def _get_tipp(self): return Tipp(list(self.current_pool[:6]))
def setUp(self): self.tipp = Tipp([1, 7, 14, 36, 46, 49])
def test_fuenfer_abstand(self): bl = Blacklist() self.assertTrue(bl.contains(Tipp([5, 10, 15, 20, 25, 30])))
def test_little_cup(self): bl = Blacklist() self.assertTrue(bl.contains(Tipp([17, 24, 26, 32, 37, 48])))
def test_missing1(self): item = BlacklistItemDirect("d2", [1,11,22,33,44,49], 2) self.assertEqual(item.get_name(), "d2") self.assertEqual(item.get_misses(), 2) self.assertTrue(item.matches(Tipp([9,10,22,33,44,49]))) self.assertFalse(item.matches(Tipp([9,10,13,33,44,49])))
def test_corners(self): bl = Blacklist() self.assertTrue(bl.contains(Tipp([1, 7, 43, 49, 24, 33])))
def test_regular(self): item = BlacklistItemDirect("d1", [2,3,5,7,9,12], 0) self.assertEqual(item.get_name(), "d1") self.assertEqual(item.get_misses(), 0) self.assertTrue(item.matches(Tipp([2,3,5,7,9,12]))) self.assertFalse(item.matches(Tipp([2,3,5,7,9,1])))
def test_line(self): bl = Blacklist() self.assertTrue(bl.contains(Tipp([1, 2, 3, 4, 5]))) self.assertTrue(bl.contains(Tipp([1, 2, 3, 4]))) self.assertTrue(bl.contains(Tipp([1, 3, 4, 5])))
def test_matches_simple(self): self.line = BlacklistParser.parse('xxxx') self.assertTrue(self.line.matches(Tipp([1, 2, 3, 4])))