Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions exercises/practice/wordy/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"vasouv",
"vivshaw",
"vpondala",
"Xinri",
"Zaldrick"
],
"files": {
Expand Down
25 changes: 22 additions & 3 deletions exercises/practice/wordy/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[88bf4b28-0de3-4883-93c7-db1b14aa806e]
description = "just a number"

[18983214-1dfc-4ebd-ac77-c110dde699ce]
description = "just a zero"

[607c08ee-2241-4288-916d-dae5455c87e6]
description = "just a negative number"

[bb8c655c-cf42-4dfc-90e0-152fcfd8d4e0]
description = "addition"

[bb9f2082-171c-46ad-ad4e-c3f72087c1b5]
description = "addition with a left hand zero"

[6fa05f17-405a-4742-80ae-5d1a8edb0d5d]
description = "addition with a right hand zero"

[79e49e06-c5ae-40aa-a352-7a3a01f70015]
description = "more addition"

Expand Down
66 changes: 58 additions & 8 deletions exercises/practice/wordy/src/test/java/WordProblemSolverTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -9,129 +10,175 @@ public class WordProblemSolverTest {
WordProblemSolver solver = new WordProblemSolver();

@Test
@DisplayName("just a number")
public void testJustANumber() {
assertThat(solver.solve("What is 5?")).isEqualTo(5);
}

@Test
@DisplayName("just a zero")
public void testJustAZero() {
assertThat(solver.solve("What is 0?")).isEqualTo(0);
}

@Test
@DisplayName("just a negative number")
public void testJustANegativeNumber() {
assertThat(solver.solve("What is -123?")).isEqualTo(-123);
}

@Disabled("Remove to run test")
@Test
@DisplayName("addition")
public void testSingleAddition1() {
assertThat(solver.solve("What is 1 plus 1?")).isEqualTo(2);
}

@Disabled("Remove to run test")
@Test
@DisplayName("addition with a left hand zero")
public void testAdditionWithALeftHandZero() {
assertThat(solver.solve("What is 0 plus 2?")).isEqualTo(2);
}

@Disabled("Remove to run test")
@Test
@DisplayName("addition with a right hand zero")
public void testAdditionWithARightHandZero() {
assertThat(solver.solve("What is 3 plus 0?")).isEqualTo(3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("more addition")
public void testSingleAddition2() {
assertThat(solver.solve("What is 53 plus 2?")).isEqualTo(55);
}

@Disabled("Remove to run test")
@Test
@DisplayName("addition with negative numbers")
public void testSingleAdditionWithNegativeNumbers() {
assertThat(solver.solve("What is -1 plus -10?")).isEqualTo(-11);
}

@Disabled("Remove to run test")
@Test
@DisplayName("large addition")
public void testSingleAdditionOfLargeNumbers() {
assertThat(solver.solve("What is 123 plus 45678?")).isEqualTo(45801);
}

@Disabled("Remove to run test")
@Test
@DisplayName("subtraction")
public void testSingleSubtraction() {
assertThat(solver.solve("What is 4 minus -12?")).isEqualTo(16);
}

@Disabled("Remove to run test")
@Test
@DisplayName("multiplication")
public void testSingleMultiplication() {
assertThat(solver.solve("What is -3 multiplied by 25?")).isEqualTo(-75);
}

@Disabled("Remove to run test")
@Test
@DisplayName("division")
public void testSingleDivision() {
assertThat(solver.solve("What is 33 divided by -3?")).isEqualTo(-11);
}

@Disabled("Remove to run test")
@Test
@DisplayName("multiple additions")
public void testMultipleAdditions() {
assertThat(solver.solve("What is 1 plus 1 plus 1?")).isEqualTo(3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("addition and subtraction")
public void testAdditionThenSubtraction() {
assertThat(solver.solve("What is 1 plus 5 minus -2?")).isEqualTo(8);
}

@Disabled("Remove to run test")
@Test
@DisplayName("multiple subtraction")
public void testMultipleSubtractions() {
assertThat(solver.solve("What is 20 minus 4 minus 13?")).isEqualTo(3);
}

@Disabled("Remove to run test")
@Test
@DisplayName("subtraction then addition")
public void testSubtractionThenAddition() {
assertThat(solver.solve("What is 17 minus 6 plus 3?")).isEqualTo(14);
}

@Disabled("Remove to run test")
@Test
@DisplayName("multiple multiplication")
public void testMultipleMultiplications() {
assertThat(solver.solve("What is 2 multiplied by -2 multiplied by 3?")).isEqualTo(-12);
}

@Disabled("Remove to run test")
@Test
@DisplayName("addition and multiplication")
public void testAdditionThenMultiplication() {
assertThat(solver.solve("What is -3 plus 7 multiplied by -2?")).isEqualTo(-8);
}

@Disabled("Remove to run test")
@Test
@DisplayName("multiple division")
public void testMultipleDivisions() {
assertThat(solver.solve("What is -12 divided by 2 divided by -3?")).isEqualTo(2);
}

@Disabled("Remove to run test")
@Test
@DisplayName("unknown operation")
public void testUnknownOperation() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> solver.solve("What is 52 cubed?"))
.withMessage("I'm sorry, I don't understand the question!");
.isThrownBy(() -> solver.solve("What is 52 cubed?"))
.withMessage("I'm sorry, I don't understand the question!");
}

@Disabled("Remove to run test")
@Test
@DisplayName("Non math question")
public void testNonMathQuestion() {
// See https://en.wikipedia.org/wiki/President_of_the_United_States if you really need to know!
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> solver.solve("Who is the President of the United States?"))
.withMessage("I'm sorry, I don't understand the question!");
.isThrownBy(() -> solver.solve("Who is the President of the United States?"))
.withMessage("I'm sorry, I don't understand the question!");
}

@Disabled("Remove to run test")
@Test
@DisplayName("reject problem missing an operand")
public void testMissingAnOperand() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> solver.solve("What is 1 plus?"))
.withMessage("I'm sorry, I don't understand the question!");
.isThrownBy(() -> solver.solve("What is 1 plus?"))
.withMessage("I'm sorry, I don't understand the question!");
}

@Disabled("Remove to run test")
@Test
@DisplayName("reject problem with no operands or operator")
public void testNoOperandsOrOperators() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> solver.solve("What is?"))
.withMessage("I'm sorry, I don't understand the question!");
.isThrownBy(() -> solver.solve("What is?"))
.withMessage("I'm sorry, I don't understand the question!");
}

@Disabled("Remove to run test")
@Test
@DisplayName("reject two operations in a row")
public void testTwoOperationsInARow() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> solver.solve("What is 1 plus plus 2?"))
Expand All @@ -140,6 +187,7 @@ public void testTwoOperationsInARow() {

@Disabled("Remove to run test")
@Test
@DisplayName("reject two numbers in a row")
public void testTwoNumbersAfterOperation() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> solver.solve("What is 1 plus 2 1?"))
Expand All @@ -148,6 +196,7 @@ public void testTwoNumbersAfterOperation() {

@Disabled("Remove to run test")
@Test
@DisplayName("reject postfix notation")
public void testPostfixNotation() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> solver.solve("What is 1 2 plus?"))
Expand All @@ -156,6 +205,7 @@ public void testPostfixNotation() {

@Disabled("Remove to run test")
@Test
@DisplayName("reject prefix notation")
public void testPrefixNotation() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> solver.solve("What is plus 1 2?"))
Expand Down