class main(model.Module): c1 = model.Var(model.Range(0, 2)) VAR = collections.OrderedDict((("c2", "0..2"),)) INIT = [c1 == 0, model.Identifier("c2") == 0] TRANS = [model.Next(c1) == (c1 + 1) % 2, model.Next("c2") == (model.Identifier("c2") + 1) % 2]
class main(model.Module): c1 = model.Identifier("c1") c2 = model.Identifier("c2") VAR = collections.OrderedDict(((c1, model.Range(0,2)), (c2, model.Range(0,2)))) INIT = [c1 == 0, c2 == 0] TRANS = [model.Next(c1) == (c1 + 1) % 2, model.Next(c2) == (c2 + 1) % 2]
def test_copy_module(self): class main(model.Module): c1 = model.Var(model.Range(0, 2)) VAR = collections.OrderedDict((("c2", "0..2"),)) INIT = [c1 == 0, model.Identifier("c2") == 0] TRANS = [model.Next(c1) == (c1 + 1) % 2, model.Next("c2") == (model.Identifier("c2") + 1) % 2] expected = """ MODULE main VAR c1: 0 .. 2; c2: 0..2; INIT c1 = 0 INIT c2 = 0 TRANS next(c1) = (c1 + 1) mod 2 TRANS next(c2) = (c2 + 1) mod 2 """ copy = main.copy() copy.VAR[model.Identifier("c3")] = model.Range(0, 2) self.assertEqual(str(main), expected.strip()) self.assertNotEqual(str(copy), expected.strip())
class Counter(model.Module): run = model.Identifier("run") ARGS = [run] c = model.Var(model.Range(0, 2)) INIT = c == 0 TRANS = [run.implies(c.next() == (c + 1) % 2), (~run).implies(c.next() == c)]
def test_variables_comment(self): variables = model.Variables(collections.OrderedDict( ((model.Identifier("v"), model.Comment(model.Boolean(), "The variable")), (model.Identifier("w"), model.Comment( model.Comment(model.Boolean(), "Another variable"), "and a new name!"))))) expected = """ VAR v: boolean; -- The variable w: boolean; -- Another variable -- and a new name! """ self.assertEqual(str(variables), expected.strip())
class main(model.Module): COMMENT = "This is the main module" myvar = model.Var(model.Comment(model.Boolean(), "My variable")) var2 = model.Identifier("var2") VAR = {var2: model.Comment(model.Range(0, 3), "The counter")} INIT = [model.Comment(~myvar, "myvar is false") & model.Comment(var2 == 0, "we start at 0")] TRANS = [ model.Case(((myvar, model.Comment( model.Comment(var2.next() == ((var2 + 1) % 4), "Increase var2"), "Only when myvar is true" ) ), (model.Trueexp(), model.Comment(var2.next() == var2, "otherwise do nothing")))) ]
def test_getattr_expr(self): mod = model.Identifier("mod") self.assertEqual(type(mod.act), model.Dot) self.assertEqual(type(mod.name), str)