lp.parse
Class LpParserTest

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by lp.parse.LpParserTest
All Implemented Interfaces:
Test
Direct Known Subclasses:
DlpParserTest, EvolpParserTest

public class LpParserTest
extends TestCase

Contains tests of the LpParser class.

Version:
1.0.0
Author:
Martin Slota
See Also:
LpParser

Field Summary
protected  LpParser parser
          The LpParser instance used in the tests.
protected  LpBuffer printer
          The printer used in the tests.
private  LpRule rule1
          A container for the rule constructed by getRule1().
private  LpRule rule2
          A container for the rule constructed by getRule2().
 
Constructor Summary
LpParserTest(String testName)
          A default test case constructor.
 
Method Summary
protected  void doRulesFromFileTest(String filename)
          Parses rules from a file and checks that they are what they should be (through the LpAbstractStructureUnit.toString() method)
private  void doTestException(String source, LpParserException expected)
          Checks that an LpParser instance actually throws the specified LpParserException on the given source.
protected  LpRule getRule1()
          Returns a rule corresponding to the string a <- b, not c.
protected  LpRule getRule2()
          Returns a rule corresponding to the string human(X) :- lives(X), not colour(green, X), not assert(rule(dead(X))).
 void testBothRules()
          Tests the parser on an input containing the rules returned by getRule1() and getRule2().
 void testExceptions()
          Tests exceptions thrown by LpParser.
 void testInvalidRule()
          Tests the parser on a ":- ." rule -- a constraint with no literal in its body.
 void testNormalRule()
          Tests the parser on an input containing the rule returned by getRule2().
 void testPropositionalRule()
          Tests the parser on an input containing the rule returned by getRule1().
 void testRulesFromFile()
          Parses rules from a file and checks that they are what they should be (through the LpBuffer instance)
 void testSetInputExceptions()
          Tests the parser on null input (a IllegalArgumentException should be thrown).
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

rule1

private LpRule rule1
A container for the rule constructed by getRule1().


rule2

private LpRule rule2
A container for the rule constructed by getRule2().


parser

protected LpParser parser
The LpParser instance used in the tests.


printer

protected LpBuffer printer
The printer used in the tests.

Constructor Detail

LpParserTest

public LpParserTest(String testName)
A default test case constructor.

Parameters:
testName - the name of the test case
Method Detail

testSetInputExceptions

public void testSetInputExceptions()
Tests the parser on null input (a IllegalArgumentException should be thrown).

Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)

getRule1

protected LpRule getRule1()
Returns a rule corresponding to the string
a <- b, not c.


getRule2

protected LpRule getRule2()
Returns a rule corresponding to the string
human(X) :- lives(X), not colour(green, X), not assert(rule(dead(X))).


testPropositionalRule

public void testPropositionalRule()
Tests the parser on an input containing the rule returned by getRule1().

Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)
if - a LpParserException is thrown while parsing the input (should never happen)

testNormalRule

public void testNormalRule()
Tests the parser on an input containing the rule returned by getRule2().

Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)
if - a LpParserException is thrown while parsing the input (should never happen)

testBothRules

public void testBothRules()
Tests the parser on an input containing the rules returned by getRule1() and getRule2().

Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)
if - a LpParserException is thrown while parsing the input (should never happen)

testRulesFromFile

public void testRulesFromFile()
                       throws IOException
Parses rules from a file and checks that they are what they should be (through the LpBuffer instance)

Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)
if - a LpParserException is thrown while parsing the input (should never happen)

doRulesFromFileTest

protected void doRulesFromFileTest(String filename)
                            throws IOException
Parses rules from a file and checks that they are what they should be (through the LpAbstractStructureUnit.toString() method)

Parameters:
filename - path to the text file with rules
Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)
if - a LpParserException is thrown while parsing the input (should never happen)

testExceptions

public void testExceptions()
Tests exceptions thrown by LpParser.

Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)

testInvalidRule

public void testInvalidRule()
Tests the parser on a ":- ." rule -- a constraint with no literal in its body. An LpParserException is expected to be thrown

Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)

doTestException

private void doTestException(String source,
                             LpParserException expected)
Checks that an LpParser instance actually throws the specified LpParserException on the given source.

Parameters:
source - the given source
expected - the exception to be thrown
Throws:
IOException - (wrapped in an ExceptionAdapter) if an I/O exception occurs while parsing the input (should never happen)