From 8f809ff422979e94f7551646aee095b0defafb03 Mon Sep 17 00:00:00 2001 From: BrittanyBi Date: Mon, 29 Apr 2019 12:46:33 -0600 Subject: [PATCH] PAN-54 Clean slate that runs --- services/build.gradle | 2 +- .../tsp/services/parser/ParserService.java | 94 ++++++++----------- .../services/parser/ParserServiceTest.java | 30 ++---- .../msudenver/tsp/website/Application.java | 8 -- .../controller/UserCreationController.java | 2 - .../UserCreationControllerTest.java | 1 - 6 files changed, 48 insertions(+), 89 deletions(-) diff --git a/services/build.gradle b/services/build.gradle index a81a98e..0873510 100644 --- a/services/build.gradle +++ b/services/build.gradle @@ -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' diff --git a/services/src/main/java/edu/msudenver/tsp/services/parser/ParserService.java b/services/src/main/java/edu/msudenver/tsp/services/parser/ParserService.java index e2d94a0..c3f37e1 100644 --- a/services/src/main/java/edu/msudenver/tsp/services/parser/ParserService.java +++ b/services/src/main/java/edu/msudenver/tsp/services/parser/ParserService.java @@ -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 retrieveStatements(final Node parsedTree) { return populateStatementList(parsedTree, new ArrayList<>()); } - public ArrayList populateStatementList(final Node node, final ArrayList statementList) + private ArrayList populateStatementList(final Node node, final ArrayList statementList) { if(node == null) { diff --git a/services/src/test/java/edu/msudenver/tsp/services/parser/ParserServiceTest.java b/services/src/test/java/edu/msudenver/tsp/services/parser/ParserServiceTest.java index f3607b3..597fbc2 100644 --- a/services/src/test/java/edu/msudenver/tsp/services/parser/ParserServiceTest.java +++ b/services/src/test/java/edu/msudenver/tsp/services/parser/ParserServiceTest.java @@ -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 expectedList = new ArrayList<>(); expectedList.add(""); @@ -120,7 +108,7 @@ public class ParserServiceTest { } @Test - public void testRetrieveStatements_BaseCaseReturnsXIsEven() { + public void testBaseCaseReturnsXIsEven() { final List expectedList = new ArrayList<>(); expectedList.add("x is even"); expectedList.add("x^2 is even"); diff --git a/src/main/java/edu/msudenver/tsp/website/Application.java b/src/main/java/edu/msudenver/tsp/website/Application.java index dbbbb00..54da024 100644 --- a/src/main/java/edu/msudenver/tsp/website/Application.java +++ b/src/main/java/edu/msudenver/tsp/website/Application.java @@ -9,12 +9,4 @@ public class Application { public static void main(final String[] args) { SpringApplication.run(Application.class, args); } - - /* - @Bean - @Autowired - public UserService userService(@Autowired final RestService restService) { - return new UserService(restService); - } - */ } diff --git a/src/main/java/edu/msudenver/tsp/website/controller/UserCreationController.java b/src/main/java/edu/msudenver/tsp/website/controller/UserCreationController.java index 2636314..6a1c6a9 100644 --- a/src/main/java/edu/msudenver/tsp/website/controller/UserCreationController.java +++ b/src/main/java/edu/msudenver/tsp/website/controller/UserCreationController.java @@ -16,8 +16,6 @@ import org.springframework.web.servlet.ModelAndView; @AllArgsConstructor @RequestMapping("/createuser") public class UserCreationController { - //@Autowired private final UserService userService; - @GetMapping({"/",""}) public ModelAndView createUserPage() { LOG.info("Received request to display the user creation page: returning model with name 'User'"); diff --git a/src/test/java/edu/msudenver/tsp/website/controller/UserCreationControllerTest.java b/src/test/java/edu/msudenver/tsp/website/controller/UserCreationControllerTest.java index 5eea996..27ec8b9 100644 --- a/src/test/java/edu/msudenver/tsp/website/controller/UserCreationControllerTest.java +++ b/src/test/java/edu/msudenver/tsp/website/controller/UserCreationControllerTest.java @@ -14,7 +14,6 @@ import static org.mockito.Mockito.mock; public class UserCreationControllerTest { private final UserService userService = mock(UserService.class); - //@Autowired private final UserCreationController userCreationController = new UserCreationController();//userService); @Test