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)
|
public void driveParsingProcess(final String userInput)
|
||||||
{
|
{
|
||||||
final Node tree;
|
final Node tree;
|
||||||
ArrayList<String> statements = new ArrayList<>();
|
final ArrayList<String> statements;
|
||||||
|
|
||||||
tree = parseRawInput(userInput);
|
tree = parseRawInput(userInput);
|
||||||
statements = retrieveStatements(tree);
|
statements = retrieveStatements(tree);
|
||||||
@@ -41,6 +41,12 @@ class ParserService {
|
|||||||
// convert to the same case for easier processing
|
// convert to the same case for easier processing
|
||||||
input = input.toLowerCase();
|
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);
|
root = new Node(input, null);
|
||||||
|
|
||||||
// special case: nothing is submitted
|
// special case: nothing is submitted
|
||||||
@@ -49,12 +55,6 @@ class ParserService {
|
|||||||
return root;
|
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);
|
recurse(root);
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
@@ -68,7 +68,14 @@ class ParserService {
|
|||||||
{
|
{
|
||||||
current.left = new Node("let",
|
current.left = new Node("let",
|
||||||
current);
|
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,
|
current.left.center = new Node(current.statement.substring(current.statement.indexOf("let")+3,
|
||||||
iContain),
|
iContain),
|
||||||
@@ -102,9 +109,9 @@ class ParserService {
|
|||||||
|
|
||||||
public ArrayList<String> retrieveStatements(final Node parsedTree)
|
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;
|
return statementList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,13 +53,50 @@ public class ParserServiceTest {
|
|||||||
assertEquals(expected, ps.parseRawInput(testCase).toString());
|
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
|
@Test
|
||||||
public void testEmptyStringReturnsEmptyList() {
|
public void testEmptyStringReturnsEmptyList() {
|
||||||
final ArrayList<String> expectedList = new ArrayList<>();
|
final ArrayList<String> expectedList = new ArrayList<>();
|
||||||
expectedList.add("");
|
expectedList.add("");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
when(mps.parseRawInput(anyString())).thenReturn(new Node("", null));
|
when(mps.parseRawInput(anyString())).thenReturn(new Node("", null));
|
||||||
|
|
||||||
assertEquals(expectedList, ps.retrieveStatements(mps.parseRawInput("")));
|
assertEquals(expectedList, ps.retrieveStatements(mps.parseRawInput("")));
|
||||||
@@ -80,4 +117,14 @@ public class ParserServiceTest {
|
|||||||
|
|
||||||
assertEquals(expectation, ps.retrieveStatements(mps.parseRawInput("baseCase")));
|
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