def test_condition_fail(self): aA = jp.PathEqPredicate('a', 'A') b2 = jp.PathEqPredicate('b', '2') ifAthen2 = jc.IF(aA, b2) demorgan = jc.OR([jc.NOT(aA), b2]) expect = demorgan(_LETTER_DICT) result = ifAthen2(_LETTER_DICT) self.assertFalse(result) self.assertEqual(expect, result)
def test_not_success(self): context = ExecutionContext() a1 = jp.PathEqPredicate('a', '1') not_a1 = jc.NOT(a1) expect = jc.CompositePredicateResult( valid=True, pred=not_a1, results=[a1(context, _LETTER_DICT)]) result = not_a1(context, _LETTER_DICT) self.assertTrue(result) self.assertEqual(expect, result) b2 = jp.PathEqPredicate('b', '2') b2_or_a1 = jc.OR([b2, a1]) not_b2_or_a1 = jc.NOT(b2_or_a1) expect = jc.CompositePredicateResult( valid=True, pred=not_b2_or_a1, results=[b2_or_a1(context, _LETTER_DICT)]) result = not_b2_or_a1(context, _LETTER_DICT) self.assertTrue(result) self.assertEqual(expect, result)
def test_not_fail(self): context = ExecutionContext() aA = jp.PathEqPredicate('a', 'A') not_aA = jc.NOT(aA) expect = jc.CompositePredicateResult( valid=False, pred=not_aA, results=[aA(context, _LETTER_DICT)]) result = not_aA(context, _LETTER_DICT) self.assertFalse(result) self.assertEqual(expect, result) bB = jp.PathEqPredicate('b', 'B') bB_or_aA = jc.OR([bB, aA]) not_bB_or_aA = jc.NOT(bB_or_aA) expect = jc.CompositePredicateResult( valid=False, pred=not_bB_or_aA, results=[bB_or_aA(context, _LETTER_DICT)]) result = not_bB_or_aA(context, _LETTER_DICT) self.assertFalse(result) self.assertEqual(expect, result)
def test_condition_success(self): aA = jp.PathEqPredicate('a', 'A') bB = jp.PathEqPredicate('b', 'B') ifAthenB = jc.IF(aA, bB) demorgan = jc.OR([jc.NOT(aA), bB]) test_cases = [_LETTER_DICT, {'a': 'X', 'b': 'Y'}, {'a': 'X', 'b': 'B'}] for test in test_cases: expect = demorgan(test) result = ifAthenB(test) self.assertTrue(result) self.assertEqual(expect, result)
def test_condition_indirect_success(self): context = ExecutionContext(a='A', b='B') aA = jp.PathEqPredicate('a', lambda x: x['a']) bB = jp.PathEqPredicate('b', lambda x: x['b']) ifAthenB = jc.IF(aA, bB) demorgan = jc.OR([jc.NOT(aA), bB]) test_cases = [_LETTER_DICT, {'a':'X', 'b':'Y'}, {'a':'X', 'b':'B'}] for test in test_cases: expect = demorgan(context, test) result = ifAthenB(context, test) self.assertTrue(result) self.assertEqual(expect, result)