def test_branch(self): simple_branches = alg.generate([0, 1, 2], [(0, 1), (0, 2)], 0, [1, 2], EmptyOptions) self.assertEquals("{1 + a + e, 1 + a + e}", str(simple_branches)) delayed_branches = alg.generate([0, 1, 2, 3], [(0, 1), (1, 2), (1, 3)], 0, [2], EmptyOptions) self.assertEquals("1 + {1 + a + e, 1 + e}", str(delayed_branches))
def test_recursion_fail(self): nodes = [0, 6197, 6198, 6199, 6200, 6201, 6202, 6203, 6204, 6205, 6206, 6207, 6208, 6209, 6210, 6211, 6212, 6213, 6214, 6215, 6216, 6217, 6218, 6219, 6220, 6221, 6222, 6223, 6224, 6225, 6226, 6227, 6228, 6229, 6230, 6231, 6232, 6233, 6234, 6235, 6236, 6237, 6238, 6239, 6240, 6241, 6242, 6243, 6244, 6245, 6246, 6247, 6248, 6249, 6250, 6251, 6252, 6253, 6254, 6255, 6256, 6257, 6258, 6259, 6260, 6261, 6262, 6263, 6264, 6265, 6266, 6267, 6268, 6269, 6270, 6271, 6272, 6273, 6274, 6275, 6276, 6277, 6278, 6279, 6280, 6281, 6282, 6283, 6284, 6285, 6286, 6287, 6288, 6289, 6290, 6291, 6292, 6293, 6294, 6295, 6296, 6297, 6298, 6299, 6300, 6301, 6302, 6303, 6304, 6305, 6306, 6307, 6308, 6309, 6310, 6311, 6312, 6313, 6314, 6315, 6316, 6317, 6318, 6319] edges = [(0, 6197), (6197, 6198), (6198, 6199), (6199, 6200), (6200, 6201), (6201, 6202), (6202, 6203), (6203, 6204), (6204, 6205), (6205, 6206), (6206, 6207), (6206, 6208), (6206, 6209), (6206, 6210), (6206, 6211), (6206, 6212) , (6206, 6213), (6206, 6214), (6206, 6215), (6206, 6216), (6206, 6217), (6206, 6218), (6206, 6219), (6206, 6220), (6206, 6221), (6206, 6222), (6206, 6223), (6206, 6224), (6206, 6225), (6206, 6226), (6206, 6227), (6206, 6228), (6206, 6229), (6206, 6230), (6206, 6231), (6206, 6232), (6206, 6233), (6206, 6234), (6206, 6235), (6206, 6236), (6206, 6237), (6206, 6238), (6206, 6239), (6206, 6240), (6206, 6241), (6206, 6242), (6206, 6243), (6206, 6244), (6206, 6245), (6206, 6246), (6206, 6247), (6206, 6248), (6206, 6249), (6206 , 6250), (6206, 6251), (6206, 6252), (6206, 6253), (6206, 6254), (6206, 6255), (6206, 6256), (6206, 6257), (6206, 6258), (6206, 6259), (6206, 6260), ( 6206, 6261), (6206, 6262), (6206, 6263), (6206, 6264), (6206, 6265), (6206, 6266), (6206, 6267), (6206, 6268), (6206, 6269), (6206, 6270), (6206, 6271), (6206, 6272), (6206, 6273), (6206, 6274), (6206, 6275), (6206, 6276), (6206, 6277), (6206, 6278), (6206, 6279), (6206, 6280), (6206, 6281), (6206, 6282), (6206, 6283), (6206, 6284), (6206, 6285), (6206, 6286), (6206, 6287) , (6206, 6288), (6206, 6289), (6206, 6290), (6206, 6291), (6206, 6292), (6206, 6293), (6206, 6294), (6206, 6295), (6206, 6296), (6206, 6297), (6206, 6298), (6206, 6299), (6206, 6300), (6206, 6301), (6206, 6302), (6206, 6303), (6206, 6304), (6206, 6305), (6206, 6306), (6206, 6307), (6206, 6308), (6206, 6309), (6206, 6310), (6206, 6311), (6206, 6312), (6207, 6208), (6208, 6209), (6209, 6210), (6210, 6211), (6211, 6212), (6212, 6213), (6213, 6214), (6214, 6215), (6215, 6216), (6216, 6217), (6217, 6218), (6218, 6219), (6219 , 6220), (6220, 6221), (6221, 6222), (6222, 6223), (6223, 6224), (6224, 6225), (6225, 6226), (6226, 6227), (6227, 6228), (6228, 6229), (6229, 6230), ( 6230, 6231), (6231, 6232), (6232, 6233), (6233, 6234), (6234, 6235), (6235, 6236), (6236, 6237), (6237, 6238), (6238, 6239), (6239, 6240), (6240, 6241), (6241, 6242), (6242, 6243), (6243, 6244), (6244, 6245), (6245, 6246), (6246, 6247), (6247, 6248), (6248, 6249), (6249, 6250), (6250, 6251), (6251, 6252), (6252, 6253), (6253, 6254), (6254, 6255), (6255, 6256), (6256, 6257) , (6257, 6258), (6258, 6259), (6259, 6260), (6260, 6261), (6261, 6262), (6262, 6263), (6263, 6264), (6264, 6265), (6265, 6266), (6266, 6267), (6267, 6268), (6268, 6269), (6269, 6270), (6270, 6271), (6271, 6272), (6272, 6273), (6273, 6274), (6274, 6275), (6275, 6276), (6276, 6277), (6277, 6278), (6278, 6279), (6279, 6280), (6280, 6281), (6281, 6282), (6282, 6283), (6283, 6284), (6284, 6285), (6285, 6286), (6286, 6287), (6287, 6288), (6288, 6289), (6289, 6290), (6290, 6291), (6291, 6292), (6292, 6293), (6293, 6294), (6294 , 6295), (6295, 6296), (6296, 6297), (6297, 6298), (6298, 6299), (6299, 6300), (6300, 6301), (6301, 6302), (6302, 6303), (6303, 6304), (6304, 6305), ( 6305, 6306), (6306, 6307), (6307, 6308), (6308, 6309), (6309, 6310), (6310, 6311), (6311, 6312), (6312, 6313), (6313, 6314), (6314, 6315), (6315, 6316), (6316, 6317), (6317, 6318), (6318, 6319)] res = alg.generate(nodes, edges, 0, [], EmptyOptions) print res
def test_trailing_product_3(self): nodes = [4, 5, 6, 7, 0, 8, 11] edges = [(4, 5), (4, 6), (5, 6), (6, 7), (7, 8), (0, 4), (7, 11), (7, 7)] accepting = [11] start = 0 algebra = alg.generate(nodes, edges, start, accepting, EmptyOptions) print algebra self.assertEqual(str(algebra), "1 + {1, 2} + 1 + (1)* + {1 + e, 1 + a + e}")
def test_butterfly(self): nodes = [0, 1, 2, 3, 4] edges = [(0, 1), (0, 2), (2, 1), (1, 3), (2, 3)] # No true correct answer? Anyway, it's not SJSS, so # something odd should happen res = alg.generate(nodes, edges, 0, [3], EmptyOptions) self.assertEqual("{2 + a + e, 1 + {1 + a + e, 2 + a + e}}", str(res)) # edges should be internally duplicated though. self.assertTrue(res.size() > len(edges))
def test_testcase(self): nodes = [0, 1686, 1687, 1688, 1689, 1690, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1700, 1701, 1702, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710, 1711, 1712, 1713, 1714, 1715, 1716, 1717, 1718, 1719, 1720, 1721, 1722, 1723, 1724, 1725, 1726, 1727, 1728, 1729, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1750, 1751, 1752, 1753, 1754, 1755, 1756, 1757, 1758, 1759, 1760, 1761, 1762] edges = [(0, 1716), (1686, 1686), (1686, 1687), (1687, 1688), (1687, 1689), (1688, 1688), (1688, 1689), (1689, 1690), (1690, 1691), (1691, 1692), (1692, 1693), (1692, 1694), (1693, 1693), (1693, 1694), (1694, 1696), (1694, 1695), (1695, 1696), (1695, 1695), (1696, 1697), (1696, 1718), (1696, 1705), (1697, 1698), (1698, 1699), (1699, 1700), (1700, 1701), (1701, 1702), (1702, 1703), (1703, 1704), (1704, 1733), (1705, 1706), (1706, 1707), (1707, 1708), (1708, 1709), (1709, 1710), (1710, 1711), (1711, 1712), (1712, 1713), (1713, 1714), (1714, 1715), (1715, 1717), (1716, 1727), (1717, 1733), (1718, 1719), (1719, 1720), (1720, 1721), (1721, 1729), (1721, 1722), (1722, 1723), (1723, 1724), (1724, 1725), (1725, 1726), (1726, 1728), (1727, 1738), (1728, 1733), (1729, 1730), (1730, 1731), (1731, 1732), (1732, 1733), (1733, 1734), (1733, 1735), (1734, 1734), (1734, 1735), (1735, 1736), (1735, 1737), (1736, 1736), (1736, 1737), (1737, 1739), (1738, 1749), (1739, 1740), (1740, 1741), (1741, 1742), (1742, 1743), (1743, 1744), (1743, 1745), (1744, 1744), (1744, 1745), (1745, 1746), (1745, 1747), (1745, 1748), (1746, 1747), (1746, 1748), (1747, 1747), (1747, 1748), (1748, 1753), (1748, 1750), (1748, 1751), (1749, 1760), (1749, 1762), (1750, 1753), (1750, 1750), (1750, 1751), (1751, 1752), (1752, 1757), (1752, 1758), (1753, 1754), (1754, 1755), (1755, 1756), (1756, 1757), (1756, 1758), (1757, 1757), (1757, 1758), (1758, 1761), (1758, 1759), (1759, 1761), (1759, 1759), (1760, 1760), (1760, 1762), (1762, 1686), (1762, 1687)] start = time.time() result = str(alg.generate(nodes, edges, 0, [], EmptyOptions)) print(result) end1 = time.time() alg.CACHE_ENABLED = False result2 = str(alg.generate(nodes, edges, 0, [], EmptyOptions)) end2 = time.time() print "Time taken with cache: ", end1 - start print "Time taken without cache: ", end2 - start # This is no longer the case, because # joining relies on things being equal. # self.assertEqual(result, result2) # Assert that the caching is giving some speedup. # I was seeing roughly 10x speedup with caching. self.assertTrue(end1 - start < (end2 - start) / 0.5)
def test_long_loop(self): nodes = [0, 1654, 1655, 1656, 1657, 1658, 1659, 1660, 1661] edges = [(1654, 1661), (1654, 1654), (1654, 1655), (1661, 1661), (1661, 1654), (1661, 1655), (1659, 1660), (1659, 1661), (1660, 1660), (1660, 1661), (1658, 1659), (1657, 1658), (1656, 1657), (0, 1656)] algebra = alg.generate(nodes, edges, 0, [1657], EmptyOptions) for edge in algebra.all_edges(): self.assertTrue(edge in edges) # I'm really not sure about tha e in the middle of the loop. # Seems like there is a simple equivalent to me? Not sure # though. # Don't think it's incorrect, just obtuse and hard to # compile to. self.assertEqual( str(algebra), '2 + a + 2 + {1, 1 + (1)* + 1} + ({1, 1 + (1)* + 1 + e})* + 1 + e')
def test_complex_branch(self): branches = alg.generate([0, 1, 2, 3, 4, 5], [(0, 1), (0, 2), (0, 3), (3, 4), (3, 5)], 0, [2, 3, 5], EmptyOptions) self.assertEquals(str(branches), "{1 + e, 1 + a + e, 1 + a + {1 + e, 1 + a + e}}")
def test_simpleTest(self): simple = alg.generate([0, 1, 2, 3], [(0, 1), (1, 2), (2, 3)], 0, [3], EmptyOptions) self.assertEquals("3 + a + e", str(simple))
def test_trailing_product(self): algebra = alg.generate([0, 1, 2, 3, 4], [(0, 1), (1, 3), (3, 4), (1, 4), (4, 4)], 0, [4], EmptyOptions) self.assertEqual("1 + {1, 2} + a + (1 + a)*", str(algebra))
def test_multiple_loops(self): res = alg.generate([0, 1, 2, 3, 4], [(0, 1), (1, 2), (2, 1), (1, 3), (3, 1), (1, 4)], 0, [4], EmptyOptions)
def test_multiple_removed_edges(self): res = alg.generate([0, 1, 2, 3, 4], [(0, 1), (1, 1), (1, 2), (2, 1), (2, 3), (3, 4)], 0, [4], EmptyOptions) print(res)
def test_converging_triple(self): triple = alg.generate([0, 1, 2, 3, 4], [(0, 1), (0, 2), (1, 3), (2, 3), (3, 4), (1, 4), (2, 4)], 0, [4], EmptyOptions) print triple
def test_memory(self): nodes = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19] edges = [(0, 1), (1, 1), (1, 2), (1, 3), (2, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (7, 9), (7, 7), (8, 8), (8, 9), (9, 10), (10, 11), (11, 12), (12, 13), (13, 13), (13, 14), (14, 14), (14, 15), (15, 16), (15, 15), (16, 16), (16, 17), (17, 17), (17, 18), (18, 18), (18, 19)] res = alg.generate(nodes, edges, 0, [19], EmptyOptions) print(res)
def test_compress_fail(self): nodes = [0, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494] edges = [(0, 449), (449, 450), (450, 451), (451, 452), (452, 453), (453, 454), (454, 455), (455, 456), (456, 457), (457, 458), (458, 459), (459, 460), (460, 461), (461, 462), (461, 463), (461, 464), (461, 465), (461, 466), (461, 467), (462, 463), (463, 464), (464, 465), (465, 466), (466, 467), (467, 468), (468, 469), (469, 470), (470, 471), (471, 472), (472, 473), (473, 474), (474, 475), (475, 476), (476, 477), (477, 478), (478, 479), (479, 480), (480, 481), (480, 482), (481, 482), (482, 483), (483, 484), (484, 485), (485, 486), (486, 487), (487, 488), (488, 489), (489, 490), (490, 491), (491, 492), (492, 493), (493, 494)] alg.generate(nodes, edges, 0, [], EmptyOptions)
def test_simple_loop_2(self): loop = alg.generate([0, 1, 2, 3, 4], [(0, 1), (1, 2), (2, 1), (2, 3), (3, 2), (1, 4)], 0, [4], EmptyOptions) self.assertEquals("1 + (1 + (2)* + 1)* + 1 + a + e", str(loop))
def test_mono_loop(self): loop = alg.generate([0], [(0, 0)], 0, [0], EmptyOptions) # I am not actually sure this is correct --- it might # need to be a + (1 + a)*? --- Not too sure though. # Also not sure it matters. self.assertEqual("(1 + a)*", str(loop))
def test_double_branch_2(self): res = alg.generate([0, 1, 2, 3, 4, 5, 6], [(0, 1), (0, 2), (2, 3), (1, 3), (3, 4), (4, 5), (4, 6)], 0, [], EmptyOptions) self.assertEqual(str(res), "{2, 2} + 1 + {1 + e, 1 + e}")