lots of exercises in java... from https://github.com/exercism/java

WordProblemSolverTest.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import org.junit.Ignore;
  2. import org.junit.Rule;
  3. import org.junit.Test;
  4. import org.junit.Before;
  5. import org.junit.rules.ExpectedException;
  6. import static org.junit.Assert.assertEquals;
  7. public final class WordProblemSolverTest {
  8. /*
  9. * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
  10. * ExpectedExceptions in particular.
  11. */
  12. @Rule
  13. public ExpectedException expectedException = ExpectedException.none();
  14. WordProblemSolver solver;
  15. @Before
  16. public void setup() {
  17. solver = new WordProblemSolver();
  18. }
  19. @Test
  20. public void testSingleAddition1() {
  21. assertEquals(2, solver.solve("What is 1 plus 1?"));
  22. }
  23. @Ignore
  24. @Test
  25. public void testSingleAddition2() {
  26. assertEquals(55, solver.solve("What is 53 plus 2?"));
  27. }
  28. @Ignore
  29. @Test
  30. public void testSingleAdditionWithNegativeNumbers() {
  31. assertEquals(-11, solver.solve("What is -1 plus -10?"));
  32. }
  33. @Ignore
  34. @Test
  35. public void testSingleAdditionOfLargeNumbers() {
  36. assertEquals(45801, solver.solve("What is 123 plus 45678?"));
  37. }
  38. @Ignore
  39. @Test
  40. public void testSingleSubtraction() {
  41. assertEquals(16, solver.solve("What is 4 minus -12?"));
  42. }
  43. @Ignore
  44. @Test
  45. public void testSingleMultiplication() {
  46. assertEquals(-75, solver.solve("What is -3 multiplied by 25?"));
  47. }
  48. @Ignore
  49. @Test
  50. public void testSingleDivision() {
  51. assertEquals(-11, solver.solve("What is 33 divided by -3?"));
  52. }
  53. @Ignore
  54. @Test
  55. public void testMultipleAdditions() {
  56. assertEquals(3, solver.solve("What is 1 plus 1 plus 1?"));
  57. }
  58. @Ignore
  59. @Test
  60. public void testAdditionThenSubtraction() {
  61. assertEquals(8, solver.solve("What is 1 plus 5 minus -2?"));
  62. }
  63. @Ignore
  64. @Test
  65. public void testMultipleSubtractions() {
  66. assertEquals(3, solver.solve("What is 20 minus 4 minus 13?"));
  67. }
  68. @Ignore
  69. @Test
  70. public void testSubtractionThenAddition() {
  71. assertEquals(14, solver.solve("What is 17 minus 6 plus 3?"));
  72. }
  73. @Ignore
  74. @Test
  75. public void testMultipleMultiplications() {
  76. assertEquals(-12, solver.solve("What is 2 multiplied by -2 multiplied by 3?"));
  77. }
  78. @Ignore
  79. @Test
  80. public void testAdditionThenMultiplication() {
  81. assertEquals(-8, solver.solve("What is -3 plus 7 multiplied by -2?"));
  82. }
  83. @Ignore
  84. @Test
  85. public void testMultipleDivisions() {
  86. assertEquals(2, solver.solve("What is -12 divided by 2 divided by -3?"));
  87. }
  88. @Ignore
  89. @Test
  90. public void testUnknownOperation() {
  91. expectedException.expect(IllegalArgumentException.class);
  92. expectedException.expectMessage("I'm sorry, I don't understand the question!");
  93. solver.solve("What is 52 cubed?");
  94. }
  95. @Ignore
  96. @Test
  97. public void testInvalidQuestionFormat() {
  98. expectedException.expect(IllegalArgumentException.class);
  99. expectedException.expectMessage("I'm sorry, I don't understand the question!");
  100. // See https://en.wikipedia.org/wiki/President_of_the_United_States if you really need to know!
  101. solver.solve("Who is the President of the United States?");
  102. }
  103. }