Exemplo n.º 1
0
 def test_variations(self):
     # Assert variations include the original input (the empty list has one variation = itself).
     v = search.variations([])
     self.assertEqual(v, [[]])
     # Assert variations = [1] and [].
     v = search.variations([1], optional=lambda item: item == 1)
     self.assertEqual(v, [[1], []])
     # Assert variations = the original input, [1], [2] and [].
     v = search.variations([1,2], optional=lambda item: item in (1,2))
     self.assertEqual(v, [[1,2], [2], [1], []])
     # Assert variations are sorted longest-first.
     v = search.variations([1,2,3,4], optional=lambda item: item in (1,2))
     self.assertEqual(v, [[1,2,3,4], [2,3,4], [1,3,4], [3,4]])
     self.assertTrue(len(v[0]) >= len(v[1]) >= len(v[2]), len(v[3]))
     print "pattern.search.variations()"
Exemplo n.º 2
0
 def test_variations(self):
     # Assert variations include the original input.txt (the empty list has one variation = itself).
     v = search.variations([])
     self.assertEqual(v, [()])
     # Assert variations = (1,) and ().
     v = search.variations([1], optional=lambda item: item == 1)
     self.assertEqual(v, [(1, ), ()])
     # Assert variations = the original input.txt, (2,), (1,) and ().
     v = search.variations([1, 2], optional=lambda item: item in (1, 2))
     self.assertEqual(v, [(1, 2), (2, ), (1, ), ()])
     # Assert variations are sorted longest-first.
     v = search.variations([1, 2, 3, 4],
                           optional=lambda item: item in (1, 2))
     self.assertEqual(v, [(1, 2, 3, 4), (2, 3, 4), (1, 3, 4), (3, 4)])
     self.assertTrue(len(v[0]) >= len(v[1]) >= len(v[2]), len(v[3]))
     print("pattern.search.variations()")
Exemplo n.º 3
0
 def test_variations(self):
     # Assert variations include the original input (the empty list has one
     # variation = itself).
     v = search.variations([])
     self.assertEqual(v, [()])
     # Assert variations = (1,) and ().
     v = search.variations([1], optional=lambda item: item == 1)
     self.assertEqual(v, [(1,), ()])
     # Assert variations = the original input, (2,), (1,) and ().
     v = search.variations([1, 2], optional=lambda item: item in (1, 2))
     self.assertEqual(v, [(1, 2), (2,), (1,), ()])
     # Assert variations are sorted longest-first.
     v = search.variations(
         [1, 2, 3, 4], optional=lambda item: item in (1, 2))
     self.assertEqual(v, [(1, 2, 3, 4), (2, 3, 4), (1, 3, 4), (3, 4)])
     self.assertTrue(len(v[0]) >= len(v[1]) >= len(v[2]), len(v[3]))
     print("pattern.search.variations()")