Ejemplo n.º 1
0
 def test_admissible_larger_framework(self):
     baba = ExampleFrameworks.larger_framework()
     self.assertTrue(Semantics.is_admissible(baba, [b, e, g, h]))
     self.assertTrue(Semantics.is_admissible(baba, [b, e, i]))
     self.assertTrue(Semantics.is_admissible(baba, [b, f, h, g, i]))
     self.assertFalse(Semantics.is_admissible(baba, [b, e, f, g, h]))
     self.assertFalse(Semantics.is_admissible(baba, [b, e, f, i]))
Ejemplo n.º 2
0
 def test_conflict_free_larger_framework(self):
     baba = ExampleFrameworks.larger_framework()
     self.assertTrue(Semantics.conflict_free(baba, []),
                     "Expected: conflict free")
     self.assertTrue(Semantics.conflict_free(baba, [b, e, f]),
                     "Expected: conflict free")
     self.assertTrue(Semantics.conflict_free(baba, [b, b, e, f]),
                     "Expected: conflict free")
     self.assertTrue(Semantics.conflict_free(baba, [b, b, i, f, g, h]),
                     "Expected: conflict free")
     self.assertFalse(Semantics.conflict_free(baba, [b, d, e, f]),
                      "Expected: NOT conflict free")
     self.assertFalse(Semantics.conflict_free(baba, [b, e, f, g, h]),
                      "Expected: NOT conflict free")
     self.assertFalse(Semantics.conflict_free(baba, [b, e, f, i]),
                      "Expected: NOT conflict free")
     self.assertFalse(Semantics.conflict_free(baba, [b, d, e, f, g, h, i]),
                      "Expected: NOT conflict free")
Ejemplo n.º 3
0
    def test_required_to_derive(self):
        baba = ExampleFrameworks.larger_framework()
        required_to_derive_a = baba.compute_required_to_derive(a)
        self.assertIn([b], required_to_derive_a)
        self.assertIn([e, f], required_to_derive_a)
        self.assertEqual(3, len(required_to_derive_a))

        self.assertEqual(1, len(baba.compute_required_to_derive(j)))

        required_to_derive_c = baba.compute_required_to_derive(c)
        self.assertEqual(5, len(required_to_derive_c))
        first_derivation = required_to_derive_c[0]
        second_derivation = required_to_derive_c[1]
        all(
            self.assertIn(element, first_derivation)
            or self.assertIn(element, second_derivation)
            for element in [e, f, g, h])
        all(
            self.assertIn(element, first_derivation)
            or self.assertIn(element, second_derivation)
            for element in [e, f, i])
Ejemplo n.º 4
0
 def test_preferred_larger_framework(self):
     baba = ExampleFrameworks.larger_framework()
     preferred_sets = Semantics.preferred(baba)
     self.assertIn(Semantics.SemanticSet([b, f, g, h, i]), preferred_sets)
Ejemplo n.º 5
0
 def test_generate_admissible_larger_framework(self):
     baba = ExampleFrameworks.larger_framework()
     admissible_sets = Semantics.admissible(baba)
     self.assertIn(Semantics.SemanticSet([b, e, i]), admissible_sets)
     self.assertIn(Semantics.SemanticSet([b, e, g, h]), admissible_sets)
     self.assertIn(Semantics.SemanticSet([b, f, g, h, i]), admissible_sets)
Ejemplo n.º 6
0
 def test_generate_attacks(self):
     baba = ExampleFrameworks.larger_framework()
     attacks = Semantics.get_attacks(baba, [b])
     self.assertIn(Semantics.Attack(b, set([e, f, g, h])), attacks)
     self.assertIn(Semantics.Attack(b, set([e, f, i])), attacks)
     self.assertEqual(4, len(attacks))
Ejemplo n.º 7
0
import unittest

from PythonSemantics import ExampleFrameworks, Semantics

a = Semantics.Sentence('a')
b = Semantics.Sentence('b')
c = Semantics.Sentence('c')
d = Semantics.Sentence('d')
e = Semantics.Sentence('e')
f = Semantics.Sentence('f')
g = Semantics.Sentence('g')
h = Semantics.Sentence('h')
i = Semantics.Sentence('i')
j = Semantics.Sentence('j')

larger_baba = ExampleFrameworks.larger_framework()
venice_baba = ExampleFrameworks.venice_framework()
s_baba = ExampleFrameworks.s_framework()


class TestSemantics(unittest.TestCase):
    def test_rule_initialises_with_no_body(self):
        head = 0
        rule = Semantics.Rule(head)

        self.assertEqual(head, rule.head)
        self.assertEqual([], rule.body, [])

    def test_rule_initialises_with_body(self):
        head = 0
        body = [1, 2, 3]