def test_discrete(): mgr = BDD() x = DiscreteSet(5) x.conc2pred(mgr, 'x', 2) # Declares variables x_0, x_1, x_2 in manager mgr.declare("x_0", "x_1", "x_2") x0 = mgr.var("x_0") x1 = mgr.var("x_1") x2 = mgr.var("x_2") assert x.conc2pred(mgr, 'x', 2) == ~x0 & x1 & ~x2 assert x.abs_space(mgr, 'x') == (x0 & ~x1 & ~x2) | ~x0 with raises(AssertionError): x.conc2pred(mgr, 'x', -1)
def test_fixed_periodic(): mgr = BDD() y = FixedCover(0, 10, 5, periodic=True) # 5 bins assert set(y.box2bvs((3, 7), False)) == {(False, False, True), (False, True, False), (False, True, True)} assert set(y.box2bvs((3, 7), True)) == {(False, True, False)} # Inner-outer tests assert set(y.box2bvs((3, 3.5), True)) == set([]) assert set(y.box2bvs((3, 3.5), False)) == {(False, False, True)} assert set(y.box2bvs((3, 5), True)) == set([]) # Wrap around tests assert set(y.box2bvs((9, 1), True)) == set([]) assert set(y.box2bvs((9, 2.1), True)) == {(False, False, False)} assert set(y.box2bvs((9, 2.1), False)) == {(True, False, False), (False, False, False), (False, False, True)} z = FixedCover(0, 10, 5, periodic=True) mgr.declare("z_0", "z_1", "z_2") assert y == z assert z.box2indexwindow((9.9, .1), innerapprox=True) is None assert z.box2indexwindow((1.9, 2.1), innerapprox=True) is None assert z.box2indexwindow((9.9, .1), innerapprox=False) == (4, 0) assert z.box2indexwindow((4.4, 4.3), innerapprox=False) == (3, 2) assert z.box2indexwindow((9.9, 9.8), innerapprox=False) == (0, 4) z0 = mgr.var("z_0") z1 = mgr.var("z_1") z2 = mgr.var("z_2") assert z.conc2pred(mgr, 'z', (4.4, 4.3), innerapprox=False) == ~z0 | (z0 & ~z1 & ~z2) assert z.box2indexwindow((19.9, 19.8), innerapprox=False) == (0, 4) # Over and under approximations of boxes that align exactly with the grid are the same assert z.conc2pred(mgr, 'z', (0, 4), innerapprox=True) == z.conc2pred(mgr, 'z', (0, 4), innerapprox=False)
def test_embeddedgrid_module(): mgr = BDD() inputs = {'x': EmbeddedGrid(4, 0, 3)} outputs = {'y': EmbeddedGrid(8, 4, 11)} m = Interface(mgr, inputs, outputs) mgr.declare("x_0", "x_1", "y_0", "y_1", "y_2") x0 = mgr.var("x_0") x1 = mgr.var("x_1") y0 = mgr.var("y_0") y1 = mgr.var("y_1") y2 = mgr.var("y_2") assert m.io_refined({ 'x': 2, 'y': 4 }).pred == (x0 & ~x1) & (~(x0 & ~x1) | (~y0 & ~y1 & ~y2)) assert len(mgr.vars) > 0
def test_dynamic_periodic(): mgr = BDD() x = DynamicCover(0, 20, periodic=True) # assert x.pt2bv(11, 4) == (True, True, False, False) # assert x.pt2bv(19+20, 4) == (True, False, False, False) # Wrap around assert set(x.box2bvs((17, 7), 2, innerapprox=True)) == {(False, False)} assert set(x.box2bvs((17, 7), 2, innerapprox=False)) == {(True, False), (False, False), (False, True)} mgr.declare("x_0", "x_1", "x_2") x0 = mgr.var("x_0") x1 = mgr.var("x_1") x2 = mgr.var("x_2") assert x.conc2pred(mgr, 'x', (1, 19), 3) == mgr.true # assert x.conc2pred(mgr, 'x', (19,1), 3, True) == mgr.false assert x.conc2pred(mgr, 'x', (0, 9.9), 3, False) == ~x0 assert x.conc2pred(mgr, 'x', (0, 9.9), 3, True) == (~x0 & ~x1) | (~x0 & x1 & x2) assert x.box2indexwindow((.1, 19), 3, False) == (0, 7) assert x.box2indexwindow((.1, 19), 3, True) == (1, 6) assert x.box2indexwindow((19, 1), 3, True) is None assert x.box2indexwindow((19, 1), 3, False) == (7, 0) assert x.box2indexwindow((.1, 1), 3, False) == (0, 0) assert x.box2indexwindow((.1, 1), 3, True) is None assert x.box2indexwindow((1, .1), 3, True) == (1, 7) assert x.box2indexwindow((9.7, 29.5), 3, True) == (4, 2) assert x.box2indexwindow((1.80, 21.1), 1, True) == (1, 1) assert x.box2indexwindow((16.2, 31), 3, True) == (7, 3) assert x.box2indexwindow((19.9, .1), 3, innerapprox=True) is None assert x.box2indexwindow((2.4, 2.6), 3, innerapprox=True) is None # wrap around with overapproximation assert x.box2indexwindow((19.9, .1), 3, innerapprox=False) == (7, 0) assert x.box2indexwindow((39.9, 20.1), 3, innerapprox=False) == (7, 0) assert x.box2indexwindow((9.9, 9.8), 3, innerapprox=False) == (4, 3) assert x.box2indexwindow((29.9, 29.8), 3, innerapprox=False) == (4, 3) assert x.box2indexwindow((29.9, 9.8), 3, innerapprox=False) == (4, 3) assert x.box2indexwindow((19.9, 19.8), 3, innerapprox=False) == (0, 7) # total cover assert x.box2indexwindow((39.9, 39.8), 3, innerapprox=False) == (0, 7) # total cover # Over and under approximations of boxes that align exactly with the grid are the same assert x.conc2pred(mgr, 'x', (5, 15), 4, innerapprox=True) == x.conc2pred(mgr, 'x', (5, 15), 4, innerapprox=False) assert x.conc2pred(mgr, 'x', (0, 5), 4, innerapprox=True) == x.conc2pred(mgr, 'x', (0, 5), 4, innerapprox=False) assert x.conc2pred(mgr, 'x', (15, 5), 4, innerapprox=True) == x.conc2pred(mgr, 'x', (15, 5), 4, innerapprox=False) assert x.conc2pred(mgr, 'x', (0, 20), 4, innerapprox=True) == x.conc2pred(mgr, 'x', (20, 40), 4, innerapprox=False) """