PAN-10 code & tests. 100% coverage.
Node class extracted from ParserService class. ParserConfig deleted because it wasn't being used.
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
package edu.msudenver.tsp.services.parser;
|
||||
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
//@PropertySource("classpath:development.properties")
|
||||
public class ParserConfig {
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class ParserService {
|
||||
public void driveParsingProcess(final String userInput)
|
||||
{
|
||||
final Node tree;
|
||||
ArrayList<String> statements = new ArrayList<>();
|
||||
final ArrayList<String> statements;
|
||||
|
||||
tree = parseRawInput(userInput);
|
||||
statements = retrieveStatements(tree);
|
||||
@@ -41,6 +41,12 @@ class ParserService {
|
||||
// convert to the same case for easier processing
|
||||
input = input.toLowerCase();
|
||||
|
||||
// eliminate periods at the end of the input
|
||||
/*if(input.charAt(input.length()-1) == '.')
|
||||
{
|
||||
input.substring(0, input.length()-1);
|
||||
}*/
|
||||
|
||||
root = new Node(input, null);
|
||||
|
||||
// special case: nothing is submitted
|
||||
@@ -49,12 +55,6 @@ class ParserService {
|
||||
return root;
|
||||
}
|
||||
|
||||
// eliminate periods at the end of the input
|
||||
if(input.charAt(input.length()-1) == '.')
|
||||
{
|
||||
input = input.substring(0, input.length()-1);
|
||||
}
|
||||
|
||||
recurse(root);
|
||||
|
||||
return root;
|
||||
@@ -68,7 +68,14 @@ class ParserService {
|
||||
{
|
||||
current.left = new Node("let",
|
||||
current);
|
||||
iContain = (current.statement.contains("if") ? current.statement.indexOf("if") : current.statement.length());
|
||||
|
||||
if(current.statement.contains("if")){
|
||||
iContain = current.statement.indexOf("if");
|
||||
} else if(current.statement.contains("then")){
|
||||
iContain = current.statement.indexOf("then");
|
||||
} else {
|
||||
iContain = current.statement.length();
|
||||
}
|
||||
|
||||
current.left.center = new Node(current.statement.substring(current.statement.indexOf("let")+3,
|
||||
iContain),
|
||||
@@ -102,9 +109,9 @@ class ParserService {
|
||||
|
||||
public ArrayList<String> retrieveStatements(final Node parsedTree)
|
||||
{
|
||||
ArrayList<String> statementList = new ArrayList<>();
|
||||
final ArrayList<String> statementList = new ArrayList<>();
|
||||
|
||||
statementList = traverse(parsedTree, statementList);
|
||||
traverse(parsedTree, statementList);
|
||||
|
||||
return statementList;
|
||||
}
|
||||
|
||||
@@ -53,13 +53,50 @@ public class ParserServiceTest {
|
||||
assertEquals(expected, ps.parseRawInput(testCase).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLetXBeEvenThenXSquaredIsEven() {
|
||||
final String expected = "0: let x be even. then x^2 is even.\n" +
|
||||
"... 1: let\n" +
|
||||
"... 2: x be even. \n" +
|
||||
"... 1: then\n" +
|
||||
"... 2: x^2 is even.\n\n";
|
||||
|
||||
final String testCase = "Let x be even. Then x^2 is even.";
|
||||
|
||||
assertEquals(expected, ps.parseRawInput(testCase).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLetIfThen() {
|
||||
final String expected = "0: let a. if b, then c.\n" +
|
||||
"... 1: let\n" +
|
||||
"... 2: a. \n" +
|
||||
"... 1: if\n" +
|
||||
"... 2: b, \n" +
|
||||
"... 1: then\n" +
|
||||
"... 2: c.\n\n";
|
||||
|
||||
final String testCase = "Let a. If b, then c.";
|
||||
|
||||
assertEquals(expected, ps.parseRawInput(testCase).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLetAlone() {
|
||||
final String expected = "0: let a be equal to b.\n" +
|
||||
"... 1: let\n" +
|
||||
"... 2: a be equal to b.\n\n";
|
||||
|
||||
final String testCase = "Let a be equal to b.";
|
||||
|
||||
assertEquals(expected, ps.parseRawInput(testCase).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyStringReturnsEmptyList() {
|
||||
final ArrayList<String> expectedList = new ArrayList<>();
|
||||
expectedList.add("");
|
||||
|
||||
|
||||
|
||||
when(mps.parseRawInput(anyString())).thenReturn(new Node("", null));
|
||||
|
||||
assertEquals(expectedList, ps.retrieveStatements(mps.parseRawInput("")));
|
||||
@@ -80,4 +117,14 @@ public class ParserServiceTest {
|
||||
|
||||
assertEquals(expectation, ps.retrieveStatements(mps.parseRawInput("baseCase")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDriveParsingProcess() {
|
||||
mps.root = new Node("", null);
|
||||
final ArrayList<String> testdummy = new ArrayList<>();
|
||||
when(mps.parseRawInput(anyString())).thenReturn(mps.root);
|
||||
when(mps.retrieveStatements(mps.root)).thenReturn(testdummy);
|
||||
|
||||
ps.driveParsingProcess("");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user