Permalink
Browse files

Removed original app example. Added a few more tests to shunting yard…

… algorithm.
  • Loading branch information...
1 parent 0efd041 commit 1ab62473191540fd3fccb84df913bf5c8232b361 @schuchert committed Nov 26, 2013
@@ -1,7 +0,0 @@
-package shoe.example.firstproject;
-
-public class App {
- public static void main(String[] args) {
- System.out.println("Hello World!");
- }
-}
@@ -1,7 +1,11 @@
package shoe.example.firstproject;
+
public class ShuntingYardAlgorithm {
public String translate(String infixExpression) {
- return infixExpression != null ? infixExpression : "";
+ String result = infixExpression != null ? infixExpression : "";
+ if(!result.matches("\\d*"))
+ throw new IllegalArgumentException("Badly formed expression");
+ return result;
}
}
@@ -1,35 +0,0 @@
-package shoe.example.firstproject;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
-public class AppTest {
- private ByteArrayOutputStream byteArrayOutputStream;
- private PrintStream originalSystemOut;
-
- @Before
- public void redirectOutput() {
- byteArrayOutputStream = new ByteArrayOutputStream();
- PrintStream printStream = new PrintStream(byteArrayOutputStream);
- originalSystemOut = System.out;
- System.setOut(printStream);
- }
-
- @After
- public void restoreOutput() {
- System.setOut(originalSystemOut);
- }
-
- @Test
- public void testApp() {
- App.main(null);
- assertThat(byteArrayOutputStream.toString(), is("Hello World!\n"));
- }
-}
@@ -31,4 +31,9 @@ public void shouldReturnNumberUnchanged() {
String result = shuntingYardAlgorithm.translate("45");
assertThat(result, is("45"));
}
+
+ @Test(expected=RuntimeException.class)
+ public void shouldRejectOperatorOnly() {
+ shuntingYardAlgorithm.translate("+");
+ }
}

0 comments on commit 1ab6247

Please sign in to comment.