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


class NonterminalNotInGrammarTest(TestCase):
    pass


if __name__ == '__main__':
    main()


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


class A(Nonterminal):
    pass


class B(Nonterminal):
    pass


class NonterminalNotInGrammarTest(TestCase):
    def test_shouldNotSetStartSymbol(self):
        g = Grammar(nonterminals=[A])
        self.assertFalse(g.start_isSet())
        with self.assertRaises(NonterminalDoesNotExistsException):
            g.start_set(B)
        self.assertFalse(g.start_isSet())
        self.assertFalse(g.start_is(B))

    def test_shouldNotSetStartSymbolWhenCreate(self):
        with self.assertRaises(NonterminalDoesNotExistsException):
            g = Grammar(nonterminals=[B],
                        start_symbol=A)

    def test_oldStartSymbolShouldStaySame(self):
        g = Grammar(nonterminals=[A], start_symbol=A)
        self.assertTrue(g.start_isSet())
        with self.assertRaises(NonterminalDoesNotExistsException):
            g.start_set(B)
        self.assertTrue(g.start_isSet())
        self.assertTrue(g.start_is(A))
        self.assertEqual(g.start_get(), A)


if __name__ == '__main__':
    main()

Add tests of setting nonterminal, which is not in grammar, as start symbol
Add tests of setting nonterminal, which is not in grammar, as start symbol

  
  from unittest import TestCase, main
  from grammpy import *
  from grammpy.exceptions import NonterminalDoesNotExistsException
  
  
+ class A(Nonterminal):
+     pass
+ 
+ 
+ class B(Nonterminal):
+     pass
+ 
+ 
  class NonterminalNotInGrammarTest(TestCase):
-     pass
+     def test_shouldNotSetStartSymbol(self):
+         g = Grammar(nonterminals=[A])
+         self.assertFalse(g.start_isSet())
+         with self.assertRaises(NonterminalDoesNotExistsException):
+             g.start_set(B)
+         self.assertFalse(g.start_isSet())
+         self.assertFalse(g.start_is(B))
+ 
+     def test_shouldNotSetStartSymbolWhenCreate(self):
+         with self.assertRaises(NonterminalDoesNotExistsException):
+             g = Grammar(nonterminals=[B],
+                         start_symbol=A)
+ 
+     def test_oldStartSymbolShouldStaySame(self):
+         g = Grammar(nonterminals=[A], start_symbol=A)
+         self.assertTrue(g.start_isSet())
+         with self.assertRaises(NonterminalDoesNotExistsException):
+             g.start_set(B)
+         self.assertTrue(g.start_isSet())
+         self.assertTrue(g.start_is(A))
+         self.assertEqual(g.start_get(), A)
  
  
  if __name__ == '__main__':
      main()
  
Add tests of setting nonterminal, which is not in grammar, as start symbol
## Code Before:

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


class NonterminalNotInGrammarTest(TestCase):
    pass


if __name__ == '__main__':
    main()

## Instruction:
Add tests of setting nonterminal, which is not in grammar, as start symbol
## Code After:

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


class A(Nonterminal):
    pass


class B(Nonterminal):
    pass


class NonterminalNotInGrammarTest(TestCase):
    def test_shouldNotSetStartSymbol(self):
        g = Grammar(nonterminals=[A])
        self.assertFalse(g.start_isSet())
        with self.assertRaises(NonterminalDoesNotExistsException):
            g.start_set(B)
        self.assertFalse(g.start_isSet())
        self.assertFalse(g.start_is(B))

    def test_shouldNotSetStartSymbolWhenCreate(self):
        with self.assertRaises(NonterminalDoesNotExistsException):
            g = Grammar(nonterminals=[B],
                        start_symbol=A)

    def test_oldStartSymbolShouldStaySame(self):
        g = Grammar(nonterminals=[A], start_symbol=A)
        self.assertTrue(g.start_isSet())
        with self.assertRaises(NonterminalDoesNotExistsException):
            g.start_set(B)
        self.assertTrue(g.start_isSet())
        self.assertTrue(g.start_is(A))
        self.assertEqual(g.start_get(), A)


if __name__ == '__main__':
    main()
