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

WordProblemSolverTest.java 3.4KB

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