예제 #1
0
 def test_double_tilde(self):
     """Test the double-tilde rule"""
     runner = validtnt.TNTRunner('''~~<a=b&b=a> premise
                                 <a=b&~~b=a> double-tilde''')
     self.assertIsNone(runner.rule_double_tilde(1, runner.text[1]))
     with self.assertRaises(validtnt.TooManyReferrals,
                            msg="double-tilde only takes 1 ref"):
         runner = validtnt.TNTRunner('''a=b double-tilde (lines 1, 2)''')
         runner.rule_double_tilde(0, runner.text[0])
     with self.assertRaises(validtnt.InvalidReferral,
                            msg="wrong referral should raise"):
         runner = validtnt.TNTRunner('''~~<a=b&b=a> premise
                                     ~<a=b&b=a> double-tilde''')
         runner.rule_double_tilde(1, runner.text[1])
예제 #2
0
 def test_at_most_refs(self):
     """Test checking for too many referrals"""
     runner = validtnt.TNTRunner()
     line = self.parser.parse_line(0, 'a=b premise')
     self.assertIsNone(runner.at_most_refs(line, 2, 'none'))
     with self.assertRaises(validtnt.TooManyReferrals, msg="no raise?"):
         runner.at_most_refs(line, -1, 'rule')
예제 #3
0
 def test_raise_fantasy(self):
     """Test fantasy level checking"""
     runner = validtnt.TNTRunner('''a=b premise
                                 [ push
                                     b=a premise
                                     a=b carry over line 0
                                 ] pop
                                 <b=a]a=b> fantasy rule''')
     self.assertTrue(
         runner.raise_fantasy(2, runner.text.vals[-1].fantasy, 'none',
                              'none'),
         "Statement from inner fantasy should be skipped")
     self.assertFalse(
         runner.raise_fantasy(2, runner.text[3].fantasy, 'none', 'none'),
         "Statement in same fantasy should be checked")
     with self.assertRaisesRegex(validtnt.MissingArgument,
                                 'rule missing corresponding arg',
                                 msg="Statement in outer fantasy raises"):
         runner.raise_fantasy(0, runner.text[2].fantasy, 'rule', 'arg')
     with self.assertRaisesRegex(validtnt.MissingArgument,
                                 'rule missing corresponding arg',
                                 msg="Out of range statement raises"):
         runner.raise_fantasy(-1, runner.text[2].fantasy, 'rule', 'arg')
     with self.assertRaisesRegex(validtnt.MissingArgument,
                                 'rule missing corresponding arg',
                                 msg="Out of range statement raises"):
         runner.raise_fantasy(10, runner.text[2].fantasy, 'rule', 'arg')
예제 #4
0
 def test_get_arg(self):
     """Test getting a direct or indirect referral"""
     runner = validtnt.TNTRunner('''a=b premise
                                 b=a symmetry''')
     self.assertIs(runner.get_arg(1, runner.text[1]),
                   runner.text[0],
                   msg="indirect referral to previous line failed")
     runner = validtnt.TNTRunner('''a=b premise
                                 b=a symmetry (line 0)''')
     self.assertIs(runner.get_arg(1, runner.text[1]), runner.text[0])
     with self.assertRaises(validtnt.MissingArgument,
                            msg="referral should not transcend fantasy"):
         runner = validtnt.TNTRunner('''0 a=b axiom 1
                                     1 [ push
                                     2   a=c premise
                                     3 ] pop''')
         runner.get_arg(2, runner.text[2])
예제 #5
0
 def test_separation(self):
     """Test the separation rule"""
     runner = validtnt.TNTRunner('''<a=b&b=a> premise
                                 a=b separation''')
     self.assertIsNone(runner.rule_separation(1, runner.text[1]))
     with self.assertRaises(validtnt.TooManyReferrals,
                            msg="separation only takes 1 ref"):
         runner = validtnt.TNTRunner('''a=b separation (lines 1,2)''')
         runner.rule_separation(0, runner.text[0])
     with self.assertRaises(validtnt.InvalidReferral,
                            msg="wrong operator should raise"):
         runner = validtnt.TNTRunner('''<a=b|b=a> premise
                                     a=b separation''')
         runner.rule_separation(1, runner.text[1])
     with self.assertRaises(validtnt.InvalidReferral,
                            msg="wrong referral should raise"):
         runner = validtnt.TNTRunner('''<a=b&b=a> premise
                                     a=c separation''')
         runner.rule_separation(1, runner.text[1])
예제 #6
0
 def test_find_fantasy(self):
     """Test finding a fantasy in its ancestors"""
     runner = validtnt.TNTRunner()
     stmt = self.parser.parse_line(0, 'a=b premise')
     stmt.fantasy = validtnt.Fantasy(content=validtnt.Text([(stmt.lineno,
                                                             stmt)]))
     stmt.fantasy.fantasy = validtnt.Fantasy(content=validtnt.Text())
     self.assertTrue(runner.find_fantasy(stmt.fantasy.fantasy, stmt))
     self.assertFalse(
         runner.find_fantasy(validtnt.Fantasy(content=validtnt.Text()),
                             stmt))
예제 #7
0
    def test_find_arg(self):
        """Test finding an argument that passes a cmp test"""
        runner = validtnt.TNTRunner('''a=b premise
                                    b=a symmetry''')
        line = runner.find_arg(
            1, runner.text[1], lambda ln, st:
            (ln.formula.arg.arg1 is st.formula.arg.arg2 and ln.formula.arg.arg2
             is st.formula.arg.arg1), 'none', 'none')
        self.assertIsInstance(line, validtnt.Statement, 'uh oh stinky')
        self.assertEqual(str(line), '0 a=b\tpremise')

        with self.assertRaises(validtnt.MissingArgument,
                               msg="How did a constant-False cmp work?"):
            runner.find_arg(1, runner.text[1], lambda ln, st: False, '', '')
예제 #8
0
 def test_carry(self):
     """Test the carry over line n rule"""
     runner = validtnt.TNTRunner('''0 a=b premise
                                 1 [ push
                                 2     b=a premise
                                 3     a=b carry over line 0
                                 4 ] pop''')
     runner.rule_carry(3, runner.text[3])
     with self.assertRaises(validtnt.TooManyReferrals,
                            msg="carry takes one parser-given ref"):
         runner = validtnt.TNTRunner('''a=b carry over line 0 (line 1)''')
         runner.rule_carry(0, runner.text[0])
     with self.assertRaises(validtnt.InvalidReferral,
                            msg="carry comes from direct parent"):
         runner = validtnt.TNTRunner('''0 [ push
                                     1     a=b premise
                                     2 ] pop
                                     3 <a=b]a=b> fantasy rule
                                     4 [ push
                                     5     b=a premise
                                     6     [ push
                                     7         a=b carry over line 1
                                     8     ] pop
                                     9     <a=b]a=b> fantasy rule
                                     10 ] pop
                                     11 <b=a]<a=b]a=b>> fantasy rule''')
         runner.rule_carry(7, runner.text[7])
     with self.assertRaises(validtnt.InvalidReferral,
                            msg="carry must be a copy"):
         runner = validtnt.TNTRunner('''0 a=b premise
                                     1 [ push
                                     2     b=a premise
                                     3     a=c carry over line 0
                                     4 ] pop
                                     5 <b=a]a=c> fantasy rule''')
         runner.rule_carry(3, runner.text[3])
예제 #9
0
 def test_fantasy_rule(self):
     """Test the fantasy rule"""
     runner = validtnt.TNTRunner('''0 [ push
                                 1     a=b premise
                                 2 ] pop
                                 3 <a=b]a=b> fantasy rule''')
     self.assertIsNone(runner.rule_fantasy_rule(3, runner.text[3]))
     with self.assertRaises(validtnt.TooManyReferrals,
                            msg="fantasy rule takes no refs"):
         runner = validtnt.TNTRunner('''a=b fantasy rule (line 1)''')
         runner.rule_fantasy_rule(0, runner.text[0])
     with self.assertRaises(validtnt.MissingArgument,
                            msg="fantasy rule needs a fantasy"):
         runner = validtnt.TNTRunner('''a=b fantasy rule''')
         runner.rule_fantasy_rule(0, runner.text[0])
     with self.assertRaises(validtnt.MissingArgument,
                            msg="fantasy rule should not search "
                            "infinitely far back"):
         runner = validtnt.TNTRunner('''0 [ push
                                     1     a=b premise
                                     2 ] pop
                                     3 b=a symmetry
                                     4 <a=b]a=b> fantasy rule''')
         runner.rule_fantasy_rule(4, runner.text[4])
     with self.assertRaises(validtnt.InvalidRule,
                            msg="at least if I'm not mistaken, "
                            "the only way for this to happen is if "
                            "the fantasy rule was used instead of "
                            "premise, which would have the push "
                            "as the previous statement"):
         runner = validtnt.TNTRunner('''0 [ push
                                     1     a=b fantasy rule
                                     2 ] pop''')
         runner.rule_fantasy_rule(1, runner.text[1])
     with self.assertRaises(validtnt.InvalidFantasy,
                            msg="premise should match condition"):
         runner = validtnt.TNTRunner('''0 [ push
                                     1     a=b premise
                                     2 ] pop
                                     3 <a=c]a=b> fantasy rule''')
         runner.rule_fantasy_rule(3, runner.text[3])
     with self.assertRaises(validtnt.InvalidFantasy,
                            msg="outcome should match result"):
         runner = validtnt.TNTRunner('''0 [ push
                                     1     a=b premise
                                     2 ] pop
                                     3 <a=b]a=c> fantasy rule''')
         runner.rule_fantasy_rule(3, runner.text[3])
예제 #10
0
 def test_joining(self):
     """Test the joining rule"""
     runner = validtnt.TNTRunner('''a=b premise
                                 b=a premise
                                 <a=b&b=a> joining''')
     # if this fails, it will be an error
     self.assertIsNone(runner.rule_joining(2, runner.text[2]))
     with self.assertRaises(validtnt.InvalidRule,
                            msg="wrong operator should raise"):
         # this check should be performed first
         runner = validtnt.TNTRunner('''<a=b|b=a> joining''')
         runner.rule_joining(0, runner.text[0])
     with self.assertRaises(validtnt.TooManyReferrals,
                            msg="joining only allows 2 referrals"):
         runner = validtnt.TNTRunner('''<a=b&b=a> joining (lines 1,2,3)''')
         runner.rule_joining(0, runner.text[0])
     with self.assertRaises(validtnt.InvalidReferral,
                            msg="directly wrong referral should raise"):
         runner = validtnt.TNTRunner('''a=b premise
                                     b=a premise
                                     <a=b&b=c> joining (lines 0, 1)''')
         runner.rule_joining(2, runner.text[2])
     with self.assertRaises(validtnt.MissingArgument,
                            msg="indirectly referring prev wrongly raises"):
         runner = validtnt.TNTRunner('''
             [ Indirect referrals should not search infinitely far back. ]
             [ They should only look at the directly previous couple. ]
             1 a=b premise
             2 b=a premise
             3 c=d premise
             4 d=c premise
             5 <a=b&b=a> joining
         '''.strip())
         runner.rule_joining(4, runner.text[5])
     runner = validtnt.TNTRunner('''
         [ Direct and indirect referrals should be combinable. ]
         1 a=b premise
         2 c=d premise
         3 b=a premise
         4 <a=b&b=a> joining (line 1)
     '''.strip())
     self.assertIsNone(runner.rule_joining(3, runner.text[4]))