-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync exercise wordy with problem spec
- Loading branch information
Showing
4 changed files
with
139 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% for test in cases %} | ||
#[test] | ||
{% if loop.index != 1 -%} | ||
#[ignore] | ||
{% endif -%} | ||
fn {{ test.description | lower | replace(from=" ", to="_") }}() { | ||
let input = "{{ test.input.question }}"; | ||
let output = {{ crate_name }}::{{ fn_names[0] }}(input); | ||
let expected = {% if test.expected is object -%} | ||
None | ||
{%- else -%} | ||
Some({{ test.expected }}) | ||
{%- endif %}; | ||
assert_eq!(output, expected); | ||
} | ||
{% endfor -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,177 +1,226 @@ | ||
use wordy::answer; | ||
|
||
#![deny(warnings)] | ||
#[test] | ||
fn just_a_number() { | ||
let command = "What is 5?"; | ||
assert_eq!(Some(5), answer(command)); | ||
let input = "What is 5?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(5); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn addition() { | ||
let command = "What is 1 plus 1?"; | ||
assert_eq!(Some(2), answer(command)); | ||
let input = "What is 1 plus 1?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(2); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn more_addition() { | ||
let command = "What is 53 plus 2?"; | ||
assert_eq!(Some(55), answer(command)); | ||
let input = "What is 53 plus 2?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(55); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn addition_with_negative_numbers() { | ||
let command = "What is -1 plus -10?"; | ||
assert_eq!(Some(-11), answer(command)); | ||
let input = "What is -1 plus -10?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(-11); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn large_addition() { | ||
let command = "What is 123 plus 45678?"; | ||
assert_eq!(Some(45_801), answer(command)); | ||
let input = "What is 123 plus 45678?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(45801); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn subtraction() { | ||
let command = "What is 4 minus -12?"; | ||
assert_eq!(Some(16), answer(command)); | ||
let input = "What is 4 minus -12?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(16); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn multiplication() { | ||
let command = "What is -3 multiplied by 25?"; | ||
assert_eq!(Some(-75), answer(command)); | ||
let input = "What is -3 multiplied by 25?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(-75); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn division() { | ||
let command = "What is 33 divided by -3?"; | ||
assert_eq!(Some(-11), answer(command)); | ||
let input = "What is 33 divided by -3?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(-11); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn multiple_additions() { | ||
let command = "What is 1 plus 1 plus 1?"; | ||
assert_eq!(Some(3), answer(command)); | ||
let input = "What is 1 plus 1 plus 1?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(3); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn addition_and_subtraction() { | ||
let command = "What is 1 plus 5 minus -2?"; | ||
assert_eq!(Some(8), answer(command)); | ||
let input = "What is 1 plus 5 minus -2?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(8); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn multiple_subtraction() { | ||
let command = "What is 20 minus 4 minus 13?"; | ||
assert_eq!(Some(3), answer(command)); | ||
let input = "What is 20 minus 4 minus 13?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(3); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn subtraction_then_addition() { | ||
let command = "What is 17 minus 6 plus 3?"; | ||
assert_eq!(Some(14), answer(command)); | ||
let input = "What is 17 minus 6 plus 3?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(14); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn multiple_multiplications() { | ||
let command = "What is 2 multiplied by -2 multiplied by 3?"; | ||
assert_eq!(Some(-12), answer(command)); | ||
fn multiple_multiplication() { | ||
let input = "What is 2 multiplied by -2 multiplied by 3?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(-12); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn addition_and_multiplication() { | ||
let command = "What is -3 plus 7 multiplied by -2?"; | ||
assert_eq!(Some(-8), answer(command)); | ||
let input = "What is -3 plus 7 multiplied by -2?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(-8); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn multiple_divisions() { | ||
let command = "What is -12 divided by 2 divided by -3?"; | ||
assert_eq!(Some(2), answer(command)); | ||
fn multiple_division() { | ||
let input = "What is -12 divided by 2 divided by -3?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(2); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn unknown_operation() { | ||
let command = "What is 52 cubed?"; | ||
assert_eq!(None, answer(command)); | ||
let input = "What is 52 cubed?"; | ||
let output = wordy::answer(input); | ||
let expected = None; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn non_math_question() { | ||
let command = "Who is the President of the United States?"; | ||
assert_eq!(None, answer(command)); | ||
let input = "Who is the President of the United States?"; | ||
let output = wordy::answer(input); | ||
let expected = None; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn reject_problem_missing_an_operand() { | ||
let command = "What is 1 plus?"; | ||
assert_eq!(None, answer(command)); | ||
let input = "What is 1 plus?"; | ||
let output = wordy::answer(input); | ||
let expected = None; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn reject_problem_with_no_operands_or_operators() { | ||
let command = "What is?"; | ||
assert_eq!(None, answer(command)); | ||
let input = "What is?"; | ||
let output = wordy::answer(input); | ||
let expected = None; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn reject_two_operations_in_a_row() { | ||
let command = "What is 1 plus plus 2?"; | ||
assert_eq!(None, answer(command)); | ||
let input = "What is 1 plus plus 2?"; | ||
let output = wordy::answer(input); | ||
let expected = None; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn reject_two_numbers_in_a_row() { | ||
let command = "What is 1 plus 2 1?"; | ||
assert_eq!(None, answer(command)); | ||
let input = "What is 1 plus 2 1?"; | ||
let output = wordy::answer(input); | ||
let expected = None; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn reject_postfix_notation() { | ||
let command = "What is 1 2 plus?"; | ||
assert_eq!(None, answer(command)); | ||
let input = "What is 1 2 plus?"; | ||
let output = wordy::answer(input); | ||
let expected = None; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
fn reject_prefix_notation() { | ||
let command = "What is plus 1 2?"; | ||
assert_eq!(None, answer(command)); | ||
let input = "What is plus 1 2?"; | ||
let output = wordy::answer(input); | ||
let expected = None; | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
#[cfg(feature = "exponentials")] | ||
fn exponential() { | ||
let command = "What is 2 raised to the 5th power?"; | ||
assert_eq!(Some(32), answer(command)); | ||
let input = "What is 2 raised to the 5th power?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(32); | ||
assert_eq!(output, expected); | ||
} | ||
|
||
#[test] | ||
#[ignore] | ||
#[cfg(feature = "exponentials")] | ||
fn addition_and_exponential() { | ||
let command = "What is 1 plus 2 raised to the 2nd power?"; | ||
assert_eq!(Some(9), answer(command)); | ||
let input = "What is 1 plus 2 raised to the 2nd power?"; | ||
let output = wordy::answer(input); | ||
let expected = Some(9); | ||
assert_eq!(output, expected); | ||
} |