
from unittest import TestCase, main
from grammpy import Grammar
from grammpy import Nonterminal


class TempClass(Nonterminal):
    pass


class Second(Nonterminal):
    pass


class Third(Nonterminal):
    pass


class TerminalGetTest(TestCase):
    pass

if __name__ == '__main__':
    main()


from unittest import TestCase, main
from grammpy import Grammar
from grammpy import Nonterminal


class TempClass(Nonterminal):
    pass


class Second(Nonterminal):
    pass


class Third(Nonterminal):
    pass


class TerminalGetTest(TestCase):
    def test_getNontermEmpty(self):
        gr = Grammar()
        self.assertIsNone(gr.get_nonterm(TempClass))
        self.assertIsNone(gr.get_nonterm(Second))
        self.assertIsNone(gr.get_nonterm(Third))

    def test_getNontermClass(self):
        gr = Grammar()
        gr.add_nonterm(TempClass)
        self.assertEqual(gr.get_nonterm(TempClass), TempClass)

    def test_getNontermArray(self):
        gr = Grammar()
        gr.add_nonterm([TempClass, Second, Third])
        g = gr.get_term([Second, TempClass])
        for i in g:
            self.assertTrue(i in [TempClass, Second, Third])
        self.assertEqual(g[0], Second)
        self.assertEqual(g[1], TempClass)

    def test_dontGetNontermArray(self):
        gr = Grammar()
        gr.add_term([TempClass, Second])
        g = gr.get_term([TempClass, Third])
        self.assertEqual(g[0], TempClass)
        self.assertIsNone(g[1])

    def test_getNontermTuple(self):
        gr = Grammar()
        gr.add_term([TempClass, Second, Third])
        g = gr.get_term((Third, TempClass))
        for i in g:
            self.assertTrue(i in [TempClass, Second, Third])
        self.assertEqual(g[0], Third)
        self.assertEqual(g[1], TempClass)

    def test_dontGetNontermTuple(self):
        gr = Grammar()
        gr.add_term([TempClass, Second])
        g = gr.get_term((TempClass, Third))
        self.assertEqual(g[0], TempClass)
        self.assertIsNone(g[1])


if __name__ == '__main__':
    main()

Add tests of get nonterms
Add tests of get nonterms

  
  from unittest import TestCase, main
  from grammpy import Grammar
  from grammpy import Nonterminal
  
  
  class TempClass(Nonterminal):
      pass
  
  
  class Second(Nonterminal):
      pass
  
  
  class Third(Nonterminal):
      pass
  
  
  class TerminalGetTest(TestCase):
-     pass
+     def test_getNontermEmpty(self):
+         gr = Grammar()
+         self.assertIsNone(gr.get_nonterm(TempClass))
+         self.assertIsNone(gr.get_nonterm(Second))
+         self.assertIsNone(gr.get_nonterm(Third))
+ 
+     def test_getNontermClass(self):
+         gr = Grammar()
+         gr.add_nonterm(TempClass)
+         self.assertEqual(gr.get_nonterm(TempClass), TempClass)
+ 
+     def test_getNontermArray(self):
+         gr = Grammar()
+         gr.add_nonterm([TempClass, Second, Third])
+         g = gr.get_term([Second, TempClass])
+         for i in g:
+             self.assertTrue(i in [TempClass, Second, Third])
+         self.assertEqual(g[0], Second)
+         self.assertEqual(g[1], TempClass)
+ 
+     def test_dontGetNontermArray(self):
+         gr = Grammar()
+         gr.add_term([TempClass, Second])
+         g = gr.get_term([TempClass, Third])
+         self.assertEqual(g[0], TempClass)
+         self.assertIsNone(g[1])
+ 
+     def test_getNontermTuple(self):
+         gr = Grammar()
+         gr.add_term([TempClass, Second, Third])
+         g = gr.get_term((Third, TempClass))
+         for i in g:
+             self.assertTrue(i in [TempClass, Second, Third])
+         self.assertEqual(g[0], Third)
+         self.assertEqual(g[1], TempClass)
+ 
+     def test_dontGetNontermTuple(self):
+         gr = Grammar()
+         gr.add_term([TempClass, Second])
+         g = gr.get_term((TempClass, Third))
+         self.assertEqual(g[0], TempClass)
+         self.assertIsNone(g[1])
+ 
  
  if __name__ == '__main__':
      main()
  
Add tests of get nonterms
## Code Before:

from unittest import TestCase, main
from grammpy import Grammar
from grammpy import Nonterminal


class TempClass(Nonterminal):
    pass


class Second(Nonterminal):
    pass


class Third(Nonterminal):
    pass


class TerminalGetTest(TestCase):
    pass

if __name__ == '__main__':
    main()

## Instruction:
Add tests of get nonterms
## Code After:

from unittest import TestCase, main
from grammpy import Grammar
from grammpy import Nonterminal


class TempClass(Nonterminal):
    pass


class Second(Nonterminal):
    pass


class Third(Nonterminal):
    pass


class TerminalGetTest(TestCase):
    def test_getNontermEmpty(self):
        gr = Grammar()
        self.assertIsNone(gr.get_nonterm(TempClass))
        self.assertIsNone(gr.get_nonterm(Second))
        self.assertIsNone(gr.get_nonterm(Third))

    def test_getNontermClass(self):
        gr = Grammar()
        gr.add_nonterm(TempClass)
        self.assertEqual(gr.get_nonterm(TempClass), TempClass)

    def test_getNontermArray(self):
        gr = Grammar()
        gr.add_nonterm([TempClass, Second, Third])
        g = gr.get_term([Second, TempClass])
        for i in g:
            self.assertTrue(i in [TempClass, Second, Third])
        self.assertEqual(g[0], Second)
        self.assertEqual(g[1], TempClass)

    def test_dontGetNontermArray(self):
        gr = Grammar()
        gr.add_term([TempClass, Second])
        g = gr.get_term([TempClass, Third])
        self.assertEqual(g[0], TempClass)
        self.assertIsNone(g[1])

    def test_getNontermTuple(self):
        gr = Grammar()
        gr.add_term([TempClass, Second, Third])
        g = gr.get_term((Third, TempClass))
        for i in g:
            self.assertTrue(i in [TempClass, Second, Third])
        self.assertEqual(g[0], Third)
        self.assertEqual(g[1], TempClass)

    def test_dontGetNontermTuple(self):
        gr = Grammar()
        gr.add_term([TempClass, Second])
        g = gr.get_term((TempClass, Third))
        self.assertEqual(g[0], TempClass)
        self.assertIsNone(g[1])


if __name__ == '__main__':
    main()
