Ejemplo n.º 1
0
class TestCommon(TestCase):
    def setUp(self):
        self.model = KModel()
        json_data = utils.read_json('modelchecker/models/test_model_km.json')
        self.model = KModel.from_json(json_data)
        self.lhs = Proposition('p')

    def test_one_relation_without_relations(self):
        node = Common(self.lhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))
        self.assertFalse(truth_value)
        # print dict['condition']
        # print dict['conclusion']


    def test_one_relation_one_relations(self):
        node = Common(self.lhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('se'))
        self.assertFalse(truth_value)
        # print dict['condition']
        # print dict['conclusion']

    def test_multiple_relations_true(self):
        node = Common(Disjunction(self.lhs, Proposition('r')))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sa'))
        self.assertTrue(truth_value)
        # print dict['condition']
        # print dict['conclusion']
        # print dict['interlude']

    def test_multiple_relations_false(self):
        node = Common(self.lhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sc'))
        self.assertFalse(truth_value)
Ejemplo n.º 2
0
class TestNegation(TestCase):
    def setUp(self):
        self.model = KModel()
        json_data = utils.read_json('modelchecker/models/test_model_km.json')
        self.model = KModel.from_json(json_data)
        self.lhs = Proposition('p')

    def test_is_true_1(self):
        node = Negation(self.lhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sa'))

        self.assertFalse(truth_value)
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_2(self):
        node = Negation(self.lhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))

        self.assertTrue(truth_value)
        # print dict['condition']
        # print dict['conclusion']

    def test_is_true_3(self):
        node = Negation(Conjunction(self.lhs, self.lhs))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))

        self.assertTrue(truth_value)
Ejemplo n.º 3
0
class TestProposition(TestCase):
    def setUp(self):
        self.model = KModel()
        json_data = utils.read_json('./modelchecker/models/test_model_km.json')
        self.model = KModel.from_json(json_data)

    def test_is_true_true(self):
        node = Proposition('p')
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sa'))
        self.assertTrue(truth_value)
        # print dict

    def test_is_true_false(self):
        node = Proposition('p')
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sc'))
        self.assertFalse(truth_value)
Ejemplo n.º 4
0
class TestImplicit(TestCase):
    def setUp(self):
        self.model = KModel()
        json_data = utils.read_json('modelchecker/models/test_model_km_2.json')
        self.model = KModel.from_json(json_data)
        self.lhs = Proposition('p')

    def test_no_relations(self):
        node = Implicit(self.lhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sb'))
        self.assertTrue(truth_value)
        # print dict['condition']
        # print dict['conclusion']


    def test_one_relation_true(self):
        node = Implicit(self.lhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sa'))
        self.assertTrue(truth_value)
        # print dict['condition']
        # print dict['conclusion']

    def test_one_relation_false(self):
        node = Implicit(Proposition('q'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sa'))
        self.assertFalse(truth_value)
        # print dict['condition']
        # print dict['conclusion']
        # print dict['interlude']


    def test_multiple_relations_true(self):
        node = Implicit(self.lhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))
        self.assertTrue(truth_value)
        # print dict['condition']
        # print dict['conclusion']
        # print dict['interlude']

    def test_multiple_relations_false(self):
        node = Implicit(Proposition('q'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))
        self.assertFalse(truth_value)
        # print dict['condition']
        # print dict['conclusion']
        # print dict['interlude']
Ejemplo n.º 5
0
class TestAgent(TestCase):
    def setUp(self):
        self.model = KModel()
        json_data = utils.read_json('modelchecker/models/test_model_km.json')
        self.model = KModel.from_json(json_data)

    def test_is_true_knowledge_1(self):
        # Formula is true
        node = Knowledge(3, Proposition('p'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sb'))
        self.assertTrue(truth_value,
                        "The formula is true, there is a reflexive relation.")
        # print dict['condition']
        # print dict['conclusion']
        # print dict['interlude']

    def test_is_true_knowledge_2(self):
        node = Knowledge(1, Proposition('q'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))
        self.assertTrue(
            truth_value,
            "The agent does not have a relationship in the state.")
        # print dict['conclusion']

    def test_is_true_knowledge_3(self):
        # Formula is false
        node = Knowledge(1, Proposition('p'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))
        self.assertTrue(truth_value,
                        "The formula is false, there no reflexive relation")

    def test_is_true_knowledge_4(self):
        node = Knowledge(1, Proposition('q'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sc'))
        self.assertTrue(truth_value,
                        "The agent has only one relationship to a state.")
        # print dict['condition']
        # print dict['conclusion']
        # print dict['interlude']

    def test_is_true_knowledge_5(self):
        node = Knowledge(1, Proposition('r'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sc'))
        self.assertFalse(truth_value,
                         "The agent has only one relationship to a state.")
        # print dict['condition']
        # print dict['conclusion']
        # print dict['interlude']

    def test_is_true_knowledge_6(self):
        # Formula is true
        node = Knowledge(3, Proposition('q'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sb'))
        self.assertFalse(
            truth_value, "The formula is true, there is a reflexive relation.")
        # print dict['condition']
        # print dict['conclusion']

    def test_is_true_possible_1(self):
        node = Possible(
            3, Negation(Conjunction(Proposition('p'), Proposition('q'))))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sb'))
        self.assertTrue(truth_value)
        # print dict['condition']
        # print dict['conclusion']

    def test_is_true_possible_2(self):
        node = Possible(1, Proposition('r'))
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sb'))
        self.assertFalse(truth_value)
Ejemplo n.º 6
0
class TestBinary(TestCase):
    def setUp(self):
        self.model = KModel()
        json_data = utils.read_json('modelchecker/models/test_model_km.json')
        self.model = KModel.from_json(json_data)
        self.lhs = Proposition('p')
        self.rhs = Proposition('q')

    def test_is_true_conjunction_1(self):
        node = Conjunction(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sa'))

        self.assertTrue(truth_value)
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_conjunction_2(self):
        node = Conjunction(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sb'))

        self.assertFalse(truth_value)
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_conjunction_3(self):
        node = Conjunction(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sc'))

        self.assertFalse(truth_value)
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_conjunction_4(self):
        node = Conjunction(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))

        self.assertFalse(truth_value)
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_disjunction_1(self):
        node = Disjunction(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sa'))

        self.assertTrue(truth_value)
        # print dict['interlude']
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_disjunction_2(self):
        node = Disjunction(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sb'))

        self.assertTrue(truth_value)
        # print dict['interlude']
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_disjunction_3(self):
        node = Disjunction(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sc'))

        self.assertFalse(truth_value)
        # print dict['interlude']
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_disjunction_4(self):
        node = Disjunction(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))

        self.assertTrue(truth_value)
        # print dict['interlude']
        # print dict['condition'] + '\\\\'
        # print dict['conclusion']

    def test_is_true_implication_1(self):
        node = Implication(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sd'))

        self.assertTrue(truth_value)
        # print dict['condition'] + '\\\\\n'
        # print dict['conclusion']

    def test_is_true_implication_2(self):
        node = Implication(self.lhs, self.rhs)
        (truth_value, _) = node.is_true(self.model.get_state_by_name('sb'))
        self.assertFalse(truth_value)

    def test_is_true_implication_3(self):
        node = Implication(self.lhs, self.rhs)
        (truth_value, _) = node.is_true(self.model.get_state_by_name('sc'))
        self.assertTrue(truth_value)

    def test_is_true_implication_4(self):
        node = Implication(self.lhs, self.rhs)
        (truth_value, _) = node.is_true(self.model.get_state_by_name('sa'))
        self.assertTrue(truth_value)

    def test_is_true_biimplication_1(self):
        node = BiImplication(self.lhs, self.rhs)
        (truth_value, dict) = node.is_true(self.model.get_state_by_name('sa'))
        self.assertTrue(truth_value)
        # print dict['condition'] + '\\\\'
        # print dict['conclusion'] + '\\\\'
        # print dict['interlude']

    def test_is_true_biimplication_2(self):
        node = BiImplication(self.lhs, self.rhs)
        (truth_value, _) = node.is_true(self.model.get_state_by_name('sb'))
        self.assertFalse(truth_value)