def test_minimum(self): self.assertTrue( pcabuilder.InitProp('A or false').minimum() == pcaprop.Variable( 'A')) self.assertTrue( pcabuilder.InitProp('false or (A iff B)').minimum() == pcaprop. EquivalenceOp(pcaprop.Variable('A'), pcaprop.Variable('B'))) self.assertTrue( pcabuilder.InitProp('A and false').minimum() == pcaprop.FalseProp()) self.assertTrue( pcabuilder.InitProp('false and (A iff B)').minimum() == pcaprop.FalseProp()) self.assertTrue( pcabuilder.InitProp( 'B iff (A and (false and (A iff B)))').minimum() == pcaprop.EquivalenceOp(pcaprop.Variable('B'), pcaprop.FalseProp())) self.assertTrue( pcabuilder.InitProp('Z iff (A and (B and bot))').minimum() == pcaprop.EquivalenceOp(pcaprop.Variable('Z'), pcaprop.FalseProp())) self.assertTrue( pcabuilder.InitProp('Z iff (not A or not(B or bot))').minimum() == pcaprop.EquivalenceOp( pcaprop.Variable('Z'), pcaprop.DisjunctionOp( pcaprop.NegationOp(pcaprop.Variable('A')), pcaprop.NegationOp(pcaprop.Variable('B')))))
def test_multiples(self): a = pcaparser.PARSER.parse('A and B and C or D or F') to_assert = pcaprop.DisjunctionOp(pcaprop.DisjunctionOp( pcaprop.ConjunctionOp(pcaprop.ConjunctionOp(pcaprop.Variable('A'), pcaprop.Variable('B')), pcaprop.Variable('C')), pcaprop.Variable('D')), pcaprop.Variable('F')) self.assertEqual(a, to_assert) a = pcaparser.PARSER.parse('A implies B implies C iff D iff F') to_assert = pcaprop.EquivalenceOp(pcaprop.EquivalenceOp( pcaprop.ImplicationOp(pcaprop.ImplicationOp(pcaprop.Variable('A'), pcaprop.Variable('B')), pcaprop.Variable('C')), pcaprop.Variable('D')), pcaprop.Variable('F')) self.assertEqual(a, to_assert)
def test_maximum(self): self.assertTrue( pcabuilder.InitProp('A or true').maximum() == pcaprop.TrueProp()) self.assertTrue( pcabuilder.InitProp('true or (A iff B)').maximum() == pcaprop.TrueProp()) self.assertTrue( pcabuilder.InitProp('B iff (A and (true or (A iff B)))').maximum() == pcaprop.EquivalenceOp(pcaprop.Variable('B'), pcaprop.Variable('A'))) self.assertTrue( pcabuilder.InitProp('A and true').maximum() == pcaprop.Variable( 'A')) self.assertTrue( pcabuilder.InitProp('true and (A iff B)').maximum() == pcaprop. EquivalenceOp(pcaprop.Variable('A'), pcaprop.Variable('B'))) self.assertTrue( pcabuilder.InitProp('A and (B and top)').maximum() == pcaprop. ConjunctionOp(pcaprop.Variable('A'), pcaprop.Variable('B'))) self.assertTrue( pcabuilder.InitProp('Z iff (A or (B or top))').maximum() == pcaprop.EquivalenceOp(pcaprop.Variable('Z'), pcaprop.TrueProp()))
def test_prop(self): a = pcaparser.PARSER.parse('P or B iff C and A implies (P and C)') to_assert = pcaprop.EquivalenceOp(pcaprop.DisjunctionOp(pcaprop.Variable('P'), pcaprop.Variable('B')), pcaprop.ImplicationOp( pcaprop.ConjunctionOp(pcaprop.Variable('C'), pcaprop.Variable('A')), pcaprop.ConjunctionOp(pcaprop.Variable('P'), pcaprop.Variable('C')))) self.assertEqual(a, to_assert) a = pcaparser.PARSER.parse('true or not A implies false and not not not B or A') to_assert = pcaprop.ImplicationOp( pcaprop.DisjunctionOp(pcaprop.TrueProp(), pcaprop.NegationOp(pcaprop.Variable('A'))), pcaprop.DisjunctionOp( pcaprop.ConjunctionOp(pcaprop.FalseProp(), pcaprop.NegationOp( pcaprop.NegationOp(pcaprop.NegationOp(pcaprop.Variable('B'))))), pcaprop.Variable('A'))) self.assertEqual(a, to_assert)
def exp_iff(self, value): if len(value) == 3: return pcaprop.EquivalenceOp(value[0], value[2]) return self._rec_object(value, 'exp_iff')