def test_exhaustive_consistent(): # check basic consistency assert consistent(var('a'), var('b'), sequential('a', 'b')) # see how long a causal loop can be before transitivity stops working for i in range(1, 5): clauses = [sequential(to_char(i), 'a')] + chain(i) assert not consistent(and_(*clauses), exhaustive=True)
def test_timeline(): statements = [simultaneous('a', 'b'), sequential('b', 'a')] t = timeline(relationships(statements)) print('timeline: ', t) formula = and_(var('a'), var('b'), *(t + statements)) print('formula: ', formula) s = formula.sat()[1] if s: print('solution: ', [k for k, v in s.items() if v]) assert not s
def test_transitivity(): def trans(s): return transitivity(triples(relationships(s))) statements = [sequential('a', 'b'), sequential('b', 'c'), sequential('d', 'e')] assert len(trans(statements)) == 1 statements += sequential('a', 'c') assert trans(statements)[0].equiv( impl(and_(var("a<b"), var("b<c")), var("a<c")))
def test_occurrence(): occ = occurrence(relationships([simultaneous('a', 'b')])) print('occurrence: ', occ) formula = and_(simultaneous('a', 'b'), not_(var('a')), *occ) print('formula: ', formula) s = formula.sat()[1] if s: print('solution: ', [k for k, v in s.items() if v]) assert not s
def observe(role, event): return var(role + ":" + event)
def test_ordered(): assert not (ordered('a', 'b') & var('a') & var('b') & ~sequential('a', 'b') & ~sequential('b', 'a')).sat()[1]
def test_consistent(): # check basic consistency assert consistent(var('a'), var('b'), sequential('a', 'b'))