
from unittest import TestCase, main
from grammpy import *


class NonterminalAddingTest(TestCase):
    pass


if __name__ == '__main__':
    main()


from unittest import TestCase, main
from grammpy import *
from grammpy.exceptions import NotNonterminalException


class A(Nonterminal):
    pass


class B(Nonterminal):
    pass


class C(Nonterminal):
    pass


class D(Nonterminal):
    pass


class NonterminalAddingTest(TestCase):
    def test_shouldAddOneNonterminal(self):
        g = Grammar(nonterminals=[A])
        self.assertTrue(g.have_nonterm(A))
        self.assertFalse(g.have_nonterm(B))
        self.assertFalse(g.have_nonterm([A, B]))

    def test_shouldAddMoreNonterminals(self):
        g = Grammar(nonterminals=[A, B, C])
        self.assertTrue(g.have_nonterm(A))
        self.assertTrue(g.have_nonterm([A, B, C]))
        self.assertFalse(g.have_nonterm(D))

    def test_shouldNotAddInvalidNonterminal(self):
        with self.assertRaises(NotNonterminalException):
            Grammar(nonterminals=[0])

    def test_shouldNotAddOneInvalidNonterminal(self):
        with self.assertRaises(NotNonterminalException):
            Grammar(nonterminals=[A, B, 1])


if __name__ == '__main__':
    main()

Add test of adding nonterminals when grammar is create
Add test of adding nonterminals when grammar is create

  
  from unittest import TestCase, main
  from grammpy import *
+ from grammpy.exceptions import NotNonterminalException
+ 
+ 
+ class A(Nonterminal):
+     pass
+ 
+ 
+ class B(Nonterminal):
+     pass
+ 
+ 
+ class C(Nonterminal):
+     pass
+ 
+ 
+ class D(Nonterminal):
+     pass
  
  
  class NonterminalAddingTest(TestCase):
-     pass
+     def test_shouldAddOneNonterminal(self):
+         g = Grammar(nonterminals=[A])
+         self.assertTrue(g.have_nonterm(A))
+         self.assertFalse(g.have_nonterm(B))
+         self.assertFalse(g.have_nonterm([A, B]))
+ 
+     def test_shouldAddMoreNonterminals(self):
+         g = Grammar(nonterminals=[A, B, C])
+         self.assertTrue(g.have_nonterm(A))
+         self.assertTrue(g.have_nonterm([A, B, C]))
+         self.assertFalse(g.have_nonterm(D))
+ 
+     def test_shouldNotAddInvalidNonterminal(self):
+         with self.assertRaises(NotNonterminalException):
+             Grammar(nonterminals=[0])
+ 
+     def test_shouldNotAddOneInvalidNonterminal(self):
+         with self.assertRaises(NotNonterminalException):
+             Grammar(nonterminals=[A, B, 1])
  
  
  if __name__ == '__main__':
      main()
  
Add test of adding nonterminals when grammar is create
## Code Before:

from unittest import TestCase, main
from grammpy import *


class NonterminalAddingTest(TestCase):
    pass


if __name__ == '__main__':
    main()

## Instruction:
Add test of adding nonterminals when grammar is create
## Code After:

from unittest import TestCase, main
from grammpy import *
from grammpy.exceptions import NotNonterminalException


class A(Nonterminal):
    pass


class B(Nonterminal):
    pass


class C(Nonterminal):
    pass


class D(Nonterminal):
    pass


class NonterminalAddingTest(TestCase):
    def test_shouldAddOneNonterminal(self):
        g = Grammar(nonterminals=[A])
        self.assertTrue(g.have_nonterm(A))
        self.assertFalse(g.have_nonterm(B))
        self.assertFalse(g.have_nonterm([A, B]))

    def test_shouldAddMoreNonterminals(self):
        g = Grammar(nonterminals=[A, B, C])
        self.assertTrue(g.have_nonterm(A))
        self.assertTrue(g.have_nonterm([A, B, C]))
        self.assertFalse(g.have_nonterm(D))

    def test_shouldNotAddInvalidNonterminal(self):
        with self.assertRaises(NotNonterminalException):
            Grammar(nonterminals=[0])

    def test_shouldNotAddOneInvalidNonterminal(self):
        with self.assertRaises(NotNonterminalException):
            Grammar(nonterminals=[A, B, 1])


if __name__ == '__main__':
    main()
