PAN-54 Clean slate that runs
This commit is contained in:
@@ -20,7 +20,7 @@ repositories {
|
||||
dependencies {
|
||||
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.11'
|
||||
compile group: 'org.apache.httpcomponents', name: 'fluent-hc', version: '4.5.7'
|
||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.2'
|
||||
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
|
||||
compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.0.5.RELEASE'
|
||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.5.RELEASE'
|
||||
compile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
|
||||
|
||||
@@ -39,8 +39,10 @@ class ParserService {
|
||||
return root;
|
||||
}
|
||||
|
||||
public void recurse(final Node current)
|
||||
private void recurse(final Node current)
|
||||
{
|
||||
int startIndex;
|
||||
int endIndex;
|
||||
final String statement;
|
||||
|
||||
if (current != null) {
|
||||
@@ -49,80 +51,60 @@ class ParserService {
|
||||
return;
|
||||
}
|
||||
|
||||
String nextStatement;
|
||||
|
||||
if(statement.contains("let"))
|
||||
{
|
||||
separateByLet(current, statement);
|
||||
current.setLeft(new Node("let", current));
|
||||
|
||||
startIndex = statement.indexOf("let")+"let".length();
|
||||
|
||||
if(statement.contains("if")){
|
||||
endIndex = statement.indexOf("if");
|
||||
} else if(statement.contains("then")){
|
||||
endIndex = statement.indexOf("then");
|
||||
} else {
|
||||
endIndex = statement.length();
|
||||
}
|
||||
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getLeft().setCenter(new Node(nextStatement, current.getLeft()));
|
||||
recurse(current.getLeft().getCenter());
|
||||
}
|
||||
|
||||
|
||||
if(statement.contains("if"))
|
||||
{
|
||||
separateByIf(current, statement);
|
||||
current.setCenter(new Node("if", current));
|
||||
|
||||
startIndex = statement.indexOf("if")+"if".length();
|
||||
endIndex = (statement.contains("then") ? statement.indexOf("then") : statement.length());
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getCenter().setCenter(new Node(nextStatement, current.getCenter()));
|
||||
recurse(current.getCenter().getCenter());
|
||||
}
|
||||
|
||||
|
||||
if(current.getStatement().contains("then"))
|
||||
{
|
||||
separateByThen(current, statement);
|
||||
current.setRight(new Node("then", current));
|
||||
|
||||
startIndex = statement.indexOf("then")+"then".length();
|
||||
nextStatement = statement.substring(startIndex);
|
||||
|
||||
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
||||
recurse(current.getRight().getCenter());
|
||||
}
|
||||
}
|
||||
|
||||
public void separateByLet(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final int endIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setLeft(new Node("let", current));
|
||||
|
||||
startIndex = statement.indexOf("let")+"let".length();
|
||||
|
||||
if(statement.contains("if")){
|
||||
endIndex = statement.indexOf("if");
|
||||
} else if(statement.contains("then")){
|
||||
endIndex = statement.indexOf("then");
|
||||
} else {
|
||||
endIndex = statement.length();
|
||||
}
|
||||
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getLeft().setCenter(new Node(nextStatement, current.getLeft()));
|
||||
recurse(current.getLeft().getCenter());
|
||||
}
|
||||
|
||||
public void separateByIf(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final int endIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setCenter(new Node("if", current));
|
||||
|
||||
startIndex = statement.indexOf("if")+"if".length();
|
||||
endIndex = (statement.contains("then") ? statement.indexOf("then") : statement.length());
|
||||
nextStatement = statement.substring(startIndex, endIndex);
|
||||
|
||||
current.getCenter().setCenter(new Node(nextStatement, current.getCenter()));
|
||||
recurse(current.getCenter().getCenter());
|
||||
}
|
||||
|
||||
public void separateByThen(final Node current, final String statement){
|
||||
final int startIndex;
|
||||
final String nextStatement;
|
||||
|
||||
current.setRight(new Node("then", current));
|
||||
|
||||
startIndex = statement.indexOf("then")+"then".length();
|
||||
nextStatement = statement.substring(startIndex);
|
||||
|
||||
current.getRight().setCenter(new Node(nextStatement, current.getRight()));
|
||||
recurse(current.getRight().getCenter());
|
||||
}
|
||||
|
||||
public List<String> retrieveStatements(final Node parsedTree)
|
||||
{
|
||||
return populateStatementList(parsedTree, new ArrayList<>());
|
||||
}
|
||||
|
||||
public ArrayList<String> populateStatementList(final Node node, final ArrayList<String> statementList)
|
||||
private ArrayList<String> populateStatementList(final Node node, final ArrayList<String> statementList)
|
||||
{
|
||||
if(node == null)
|
||||
{
|
||||
|
||||
@@ -21,19 +21,7 @@ public class ParserServiceTest {
|
||||
@InjectMocks private ParserService parserService;
|
||||
|
||||
@Test
|
||||
public void testParseRawInput_EmptyString() {
|
||||
final String expected = "0: \n";
|
||||
final String actual;
|
||||
|
||||
when(parserService.parseRawInput("")).thenReturn(new Node("", null));
|
||||
|
||||
actual = parserService.parseRawInput("").toString();
|
||||
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRawInputAndRecurse_EmptyStringEqualsEmptyString() {
|
||||
public void testEmptyStringEqualsEmptyString() {
|
||||
final String expected = "0: \n";
|
||||
final String actual = parserService.parseRawInput("").toString();
|
||||
|
||||
@@ -41,7 +29,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRawInput_UselessStringEqualsUselessString() {
|
||||
public void testUselessStringEqualsUselessString() {
|
||||
final String expected = "0: cat\n";
|
||||
final String actual = parserService.parseRawInput("cat").toString();
|
||||
|
||||
@@ -49,7 +37,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRawInput_SingleIfReturnsIfPlusEmptyString() {
|
||||
public void testSingleIfReturnsIfPlusEmptyString() {
|
||||
final String expected = "0: if\n... 1: if\n... 2: \n\n";
|
||||
final String actual = parserService.parseRawInput("if").toString();
|
||||
|
||||
@@ -57,7 +45,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRawInput_BaseCaseIfXIsEvenThenXSquaredIsEven() {
|
||||
public void testBaseCaseIfXIsEvenThenXSquaredIsEven() {
|
||||
final String expected = "0: if x is even then x^2 is even\n" +
|
||||
"... 1: if\n" +
|
||||
"... 2: x is even \n" +
|
||||
@@ -70,7 +58,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRawInput_LetXBeEvenThenXSquaredIsEven() {
|
||||
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" +
|
||||
@@ -83,7 +71,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRawInput_LetIfThen() {
|
||||
public void testLetIfThen() {
|
||||
final String expected = "0: let a. if b, then c.\n" +
|
||||
"... 1: let\n" +
|
||||
"... 2: a. \n" +
|
||||
@@ -98,7 +86,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseRawInput_LetStatementWithoutAnyIfOrThenStatements() {
|
||||
public void testLetStatementWithoutAnyIfOrThenStatements() {
|
||||
final String expected = "0: let a be equal to b.\n" +
|
||||
"... 1: let\n" +
|
||||
"... 2: a be equal to b.\n\n";
|
||||
@@ -109,7 +97,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveStatements_EmptyStringReturnsEmptyList() {
|
||||
public void testEmptyStringReturnsEmptyList() {
|
||||
final List<String> expectedList = new ArrayList<>();
|
||||
expectedList.add("");
|
||||
|
||||
@@ -120,7 +108,7 @@ public class ParserServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveStatements_BaseCaseReturnsXIsEven() {
|
||||
public void testBaseCaseReturnsXIsEven() {
|
||||
final List<String> expectedList = new ArrayList<>();
|
||||
expectedList.add("x is even");
|
||||
expectedList.add("x^2 is even");
|
||||
|
||||
Reference in New Issue
Block a user