
from unittest import main, TestCase
from grammpy import *
from .grammar import *


class RulesTest(TestCase):
    def test_oneRules(self):
        class Tmp1(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        grammar.add_rule(Tmp1)


if __name__ == '__main__':
    main()


from unittest import main, TestCase
from grammpy import *
from .grammar import *


class RulesTest(TestCase):
    def setUp(self):
        self.g = Grammar(terminals=[0, 1, 2,
                                    'a', 'b', 'c',
                                    TFirst, TSecond, TThird,
                                    TInstFirst, TInstSecond, TInstThird],
                         nonterminals=[NFirst, NSecond, NThird, NFourth, NFifth])

    def test_oneInRules(self):
        class Tmp1(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        self.g.add_rule(Tmp1)
        self.assertEqual(self.g.rules_count(), 3)
        self.assertTrue(self.g.have_rule(Tmp1))

    def test_oneInRulesIteration(self):
        class Tmp1(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        self.g.add_rule(Tmp1)
        for rule in self.g.rule():
            self.assertIn(rule.rule, Tmp1.rules)

    def test_hashes(self):
        class Tmp1(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        class Tmp2(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        hash1 = hash(Tmp1)
        hash2 = hash(Tmp2)
        self.assertEqual(hash1, hash2)

if __name__ == '__main__':
    main()

Add test that check hash values of rule
Add test that check hash values of rule

  
  from unittest import main, TestCase
  from grammpy import *
  from .grammar import *
  
  
  class RulesTest(TestCase):
+     def setUp(self):
+         self.g = Grammar(terminals=[0, 1, 2,
+                                     'a', 'b', 'c',
+                                     TFirst, TSecond, TThird,
+                                     TInstFirst, TInstSecond, TInstThird],
+                          nonterminals=[NFirst, NSecond, NThird, NFourth, NFifth])
+ 
-     def test_oneRules(self):
+     def test_oneInRules(self):
          class Tmp1(Rule):
              rules = [([NFirst], [NSecond, 0]),
                       ([NThird], [0, 1]),
                       ([NSecond], [NSecond, 'a'])]
-         grammar.add_rule(Tmp1)
+         self.g.add_rule(Tmp1)
+         self.assertEqual(self.g.rules_count(), 3)
+         self.assertTrue(self.g.have_rule(Tmp1))
  
+     def test_oneInRulesIteration(self):
+         class Tmp1(Rule):
+             rules = [([NFirst], [NSecond, 0]),
+                      ([NThird], [0, 1]),
+                      ([NSecond], [NSecond, 'a'])]
+         self.g.add_rule(Tmp1)
+         for rule in self.g.rule():
+             self.assertIn(rule.rule, Tmp1.rules)
+ 
+     def test_hashes(self):
+         class Tmp1(Rule):
+             rules = [([NFirst], [NSecond, 0]),
+                      ([NThird], [0, 1]),
+                      ([NSecond], [NSecond, 'a'])]
+         class Tmp2(Rule):
+             rules = [([NFirst], [NSecond, 0]),
+                      ([NThird], [0, 1]),
+                      ([NSecond], [NSecond, 'a'])]
+         hash1 = hash(Tmp1)
+         hash2 = hash(Tmp2)
+         self.assertEqual(hash1, hash2)
  
  if __name__ == '__main__':
      main()
  
Add test that check hash values of rule
## Code Before:

from unittest import main, TestCase
from grammpy import *
from .grammar import *


class RulesTest(TestCase):
    def test_oneRules(self):
        class Tmp1(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        grammar.add_rule(Tmp1)


if __name__ == '__main__':
    main()

## Instruction:
Add test that check hash values of rule
## Code After:

from unittest import main, TestCase
from grammpy import *
from .grammar import *


class RulesTest(TestCase):
    def setUp(self):
        self.g = Grammar(terminals=[0, 1, 2,
                                    'a', 'b', 'c',
                                    TFirst, TSecond, TThird,
                                    TInstFirst, TInstSecond, TInstThird],
                         nonterminals=[NFirst, NSecond, NThird, NFourth, NFifth])

    def test_oneInRules(self):
        class Tmp1(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        self.g.add_rule(Tmp1)
        self.assertEqual(self.g.rules_count(), 3)
        self.assertTrue(self.g.have_rule(Tmp1))

    def test_oneInRulesIteration(self):
        class Tmp1(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        self.g.add_rule(Tmp1)
        for rule in self.g.rule():
            self.assertIn(rule.rule, Tmp1.rules)

    def test_hashes(self):
        class Tmp1(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        class Tmp2(Rule):
            rules = [([NFirst], [NSecond, 0]),
                     ([NThird], [0, 1]),
                     ([NSecond], [NSecond, 'a'])]
        hash1 = hash(Tmp1)
        hash2 = hash(Tmp2)
        self.assertEqual(hash1, hash2)

if __name__ == '__main__':
    main()
