from .generic import GrammarTest

def test_np():
    grammar = GrammarTest('grammars/test_np.fcfg',
        'grammars/nounphrase.sample', 
        'grammars/nounphrase.sample.negative')
    grammar.check_positive()
    grammar.check_negative()

def test_subject():
    grammar = GrammarTest('grammars/test_subject.fcfg',
        'grammars/subjectphrase.sample',
        'grammars/subjectphrase.sample.negative')
    grammar.check_positive()
    grammar.check_negative()

def test_object():
    grammar = GrammarTest('grammars/test_object.fcfg',
        'grammars/object.sample',
        'grammars/object.sample.negative')
    grammar.check_positive()
    grammar.check_negative()

from .generic import GrammarTest

def add_grammar(grammar, positive_sample, negative_sample):
    grammar = GrammarTest(grammar, positive_sample,
        negative_sample)
    grammar.check_positive()
    grammar.check_negative()

def test_np():
    add_grammar('grammars/test_np.fcfg',
        'grammars/nounphrase.sample', 
        'grammars/nounphrase.sample.negative')

def test_subject():
    add_grammar('grammars/test_subject.fcfg',
        'grammars/subjectphrase.sample',
        'grammars/subjectphrase.sample.negative')

def test_object():
    add_grammar('grammars/test_object.fcfg',
        'grammars/object.sample',
        'grammars/object.sample.negative')

Refactor grammar tests to be easily extensible
Refactor grammar tests to be easily extensible

  from .generic import GrammarTest
  
- def test_np():
+ def add_grammar(grammar, positive_sample, negative_sample):
-     grammar = GrammarTest('grammars/test_np.fcfg',
+     grammar = GrammarTest(grammar, positive_sample,
+         negative_sample)
-         'grammars/nounphrase.sample', 
-         'grammars/nounphrase.sample.negative')
      grammar.check_positive()
      grammar.check_negative()
  
+ def test_np():
+     add_grammar('grammars/test_np.fcfg',
+         'grammars/nounphrase.sample', 
+         'grammars/nounphrase.sample.negative')
+ 
  def test_subject():
-     grammar = GrammarTest('grammars/test_subject.fcfg',
+     add_grammar('grammars/test_subject.fcfg',
          'grammars/subjectphrase.sample',
          'grammars/subjectphrase.sample.negative')
-     grammar.check_positive()
-     grammar.check_negative()
  
  def test_object():
-     grammar = GrammarTest('grammars/test_object.fcfg',
+     add_grammar('grammars/test_object.fcfg',
          'grammars/object.sample',
          'grammars/object.sample.negative')
-     grammar.check_positive()
-     grammar.check_negative()
  
Refactor grammar tests to be easily extensible
## Code Before:
from .generic import GrammarTest

def test_np():
    grammar = GrammarTest('grammars/test_np.fcfg',
        'grammars/nounphrase.sample', 
        'grammars/nounphrase.sample.negative')
    grammar.check_positive()
    grammar.check_negative()

def test_subject():
    grammar = GrammarTest('grammars/test_subject.fcfg',
        'grammars/subjectphrase.sample',
        'grammars/subjectphrase.sample.negative')
    grammar.check_positive()
    grammar.check_negative()

def test_object():
    grammar = GrammarTest('grammars/test_object.fcfg',
        'grammars/object.sample',
        'grammars/object.sample.negative')
    grammar.check_positive()
    grammar.check_negative()

## Instruction:
Refactor grammar tests to be easily extensible
## Code After:
from .generic import GrammarTest

def add_grammar(grammar, positive_sample, negative_sample):
    grammar = GrammarTest(grammar, positive_sample,
        negative_sample)
    grammar.check_positive()
    grammar.check_negative()

def test_np():
    add_grammar('grammars/test_np.fcfg',
        'grammars/nounphrase.sample', 
        'grammars/nounphrase.sample.negative')

def test_subject():
    add_grammar('grammars/test_subject.fcfg',
        'grammars/subjectphrase.sample',
        'grammars/subjectphrase.sample.negative')

def test_object():
    add_grammar('grammars/test_object.fcfg',
        'grammars/object.sample',
        'grammars/object.sample.negative')
