def test_json_deserialization(s, transition): objects = [ Direction.CAUSE, s.network, # Network s, # Subsystem models.Bipartition(models.Part((0, ), ()), models.Part((1, ), (2, 3))), models.KPartition(models.Part((0, ), ()), models.Part((1, ), (2, 3))), models.Tripartition(models.Part((0, ), ()), models.Part((1, ), (2, 3)), models.Part((3, ), (4, ))), models.Cut((0, ), (2, )), models.NullCut((0, 1)), models.KCut( Direction.CAUSE, models.KPartition(models.Part((0, ), ()), models.Part((1, ), (2, 3)))), s.concept((1, 2)), s.concept((1, )), compute.ces(s), compute.sia(s), transition, transition.find_actual_cause((0, ), (0, )), actual.account(transition), actual.sia(transition) ] for o in objects: loaded = jsonify.loads(jsonify.dumps(o)) assert loaded == o
def test_ac_ex1_transition(transition): """Basic regression test for ac_ex1 example.""" cause_account = actual.account(transition, Direction.CAUSE) assert len(cause_account) == 1 cria = cause_account[0].ria assert cria.mechanism == (0,) assert cria.purview == (1,) assert cria.direction == Direction.CAUSE assert cria.state == (1, 0, 0) assert cria.alpha == 0.415037 assert cria.probability == 0.66666666666666663 assert cria.partitioned_probability == 0.5 assert cria.partition == models.Bipartition( models.Part((), (1,)), models.Part((0,), ()) ) effect_account = actual.account(transition, Direction.EFFECT) assert len(effect_account) == 2 eria0 = effect_account[0].ria eria1 = effect_account[1].ria assert eria0.mechanism == (1,) assert eria0.purview == (0,) assert eria0.direction == Direction.EFFECT assert eria0.state == (0, 1, 1) assert eria0.alpha == 0.415037 assert eria0.probability == 1.0 assert eria0.partitioned_probability == 0.75 assert eria0.partition == models.Bipartition( models.Part((), (0,)), models.Part((1,), ()) ) assert eria1.mechanism == (2,) assert eria1.purview == (0,) assert eria1.direction == Direction.EFFECT assert eria1.state == (0, 1, 1) assert eria1.alpha == 0.415037 assert eria1.probability == 1.0 assert eria1.partitioned_probability == 0.75 assert eria1.partition == models.Bipartition( models.Part((), (0,)), models.Part((2,), ()) )
def test_ac_ex1_transition(transition): """Basic regression test for ac_ex1 example.""" cause_account = actual.account(transition, Direction.CAUSE) assert len(cause_account) == 1 cria = cause_account[0].ria assert cria.mechanism == (0,) assert cria.purview == (1,) assert cria.direction == Direction.CAUSE assert cria.state == (1, 0, 0) assert cria.alpha == 0.415037 assert cria.probability == 0.66666666666666663 assert cria.partitioned_probability == 0.5 assert cria.partition == models.Bipartition(models.Part((), (1,)), models.Part((0,), ())) effect_account = actual.account(transition, Direction.EFFECT) assert len(effect_account) == 2 eria0 = effect_account[0].ria eria1 = effect_account[1].ria assert eria0.mechanism == (1,) assert eria0.purview == (0,) assert eria0.direction == Direction.EFFECT assert eria0.state == (0, 1, 1) assert eria0.alpha == 0.415037 assert eria0.probability == 1.0 assert eria0.partitioned_probability == 0.75 assert eria0.partition == models.Bipartition(models.Part((), (0,)), models.Part((1,), ())) assert eria1.mechanism == (2,) assert eria1.purview == (0,) assert eria1.direction == Direction.EFFECT assert eria1.state == (0, 1, 1) assert eria1.alpha == 0.415037 assert eria1.probability == 1.0 assert eria1.partitioned_probability == 0.75 assert eria1.partition == models.Bipartition(models.Part((), (0,)), models.Part((2,), ()))