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

WordProblemSolverTest.java 3.3KB

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