Skip to content

Commit bb606ae

Browse files
committed
Sync exercise wordy with problem spec
1 parent 883e45d commit bb606ae

File tree

4 files changed

+139
-70
lines changed

4 files changed

+139
-70
lines changed

exercises/practice/wordy/.docs/instructions.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ Now, perform the other three operations.
4040

4141
Handle a set of operations, in sequence.
4242

43-
Since these are verbal word problems, evaluate the expression from
44-
left-to-right, _ignoring the typical order of operations._
43+
Since these are verbal word problems, evaluate the expression from left-to-right, _ignoring the typical order of operations._
4544

4645
> What is 5 plus 13 plus 6?
4746
@@ -55,14 +54,6 @@ left-to-right, _ignoring the typical order of operations._
5554

5655
The parser should reject:
5756

58-
* Unsupported operations ("What is 52 cubed?")
59-
* Non-math questions ("Who is the President of the United States")
60-
* Word problems with invalid syntax ("What is 1 plus plus 2?")
61-
62-
## Bonus — Exponentials
63-
64-
If you'd like, handle exponentials.
65-
66-
> What is 2 raised to the 5th power?
67-
68-
32
57+
- Unsupported operations ("What is 52 cubed?")
58+
- Non-math questions ("Who is the President of the United States")
59+
- Word problems with invalid syntax ("What is 1 plus plus 2?")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% for test in cases %}
2+
#[test]
3+
{% if loop.index != 1 -%}
4+
#[ignore]
5+
{% endif -%}
6+
fn {{ test.description | lower | replace(from=" ", to="_") }}() {
7+
let input = "{{ test.input.question }}";
8+
let output = {{ crate_name }}::{{ fn_names[0] }}(input);
9+
let expected = {% if test.expected is object -%}
10+
None
11+
{%- else -%}
12+
Some({{ test.expected }})
13+
{%- endif %};
14+
assert_eq!(output, expected);
15+
}
16+
{% endfor -%}

exercises/practice/wordy/.meta/tests.toml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[88bf4b28-0de3-4883-93c7-db1b14aa806e]
613
description = "just a number"
@@ -38,9 +45,15 @@ description = "multiple subtraction"
3845
[4f4a5749-ef0c-4f60-841f-abcfaf05d2ae]
3946
description = "subtraction then addition"
4047

48+
[312d908c-f68f-42c9-aa75-961623cc033f]
49+
description = "multiple multiplication"
50+
4151
[38e33587-8940-4cc1-bc28-bfd7e3966276]
4252
description = "addition and multiplication"
4353

54+
[3c854f97-9311-46e8-b574-92b60d17d394]
55+
description = "multiple division"
56+
4457
[3ad3e433-8af7-41ec-aa9b-97b42ab49357]
4558
description = "unknown operation"
4659

Lines changed: 103 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,226 @@
1-
use wordy::answer;
2-
1+
#![deny(warnings)]
32
#[test]
43
fn just_a_number() {
5-
let command = "What is 5?";
6-
assert_eq!(Some(5), answer(command));
4+
let input = "What is 5?";
5+
let output = wordy::answer(input);
6+
let expected = Some(5);
7+
assert_eq!(output, expected);
78
}
89

910
#[test]
1011
#[ignore]
1112
fn addition() {
12-
let command = "What is 1 plus 1?";
13-
assert_eq!(Some(2), answer(command));
13+
let input = "What is 1 plus 1?";
14+
let output = wordy::answer(input);
15+
let expected = Some(2);
16+
assert_eq!(output, expected);
1417
}
1518

1619
#[test]
1720
#[ignore]
1821
fn more_addition() {
19-
let command = "What is 53 plus 2?";
20-
assert_eq!(Some(55), answer(command));
22+
let input = "What is 53 plus 2?";
23+
let output = wordy::answer(input);
24+
let expected = Some(55);
25+
assert_eq!(output, expected);
2126
}
2227

2328
#[test]
2429
#[ignore]
2530
fn addition_with_negative_numbers() {
26-
let command = "What is -1 plus -10?";
27-
assert_eq!(Some(-11), answer(command));
31+
let input = "What is -1 plus -10?";
32+
let output = wordy::answer(input);
33+
let expected = Some(-11);
34+
assert_eq!(output, expected);
2835
}
2936

3037
#[test]
3138
#[ignore]
3239
fn large_addition() {
33-
let command = "What is 123 plus 45678?";
34-
assert_eq!(Some(45_801), answer(command));
40+
let input = "What is 123 plus 45678?";
41+
let output = wordy::answer(input);
42+
let expected = Some(45801);
43+
assert_eq!(output, expected);
3544
}
3645

3746
#[test]
3847
#[ignore]
3948
fn subtraction() {
40-
let command = "What is 4 minus -12?";
41-
assert_eq!(Some(16), answer(command));
49+
let input = "What is 4 minus -12?";
50+
let output = wordy::answer(input);
51+
let expected = Some(16);
52+
assert_eq!(output, expected);
4253
}
4354

4455
#[test]
4556
#[ignore]
4657
fn multiplication() {
47-
let command = "What is -3 multiplied by 25?";
48-
assert_eq!(Some(-75), answer(command));
58+
let input = "What is -3 multiplied by 25?";
59+
let output = wordy::answer(input);
60+
let expected = Some(-75);
61+
assert_eq!(output, expected);
4962
}
5063

5164
#[test]
5265
#[ignore]
5366
fn division() {
54-
let command = "What is 33 divided by -3?";
55-
assert_eq!(Some(-11), answer(command));
67+
let input = "What is 33 divided by -3?";
68+
let output = wordy::answer(input);
69+
let expected = Some(-11);
70+
assert_eq!(output, expected);
5671
}
5772

5873
#[test]
5974
#[ignore]
6075
fn multiple_additions() {
61-
let command = "What is 1 plus 1 plus 1?";
62-
assert_eq!(Some(3), answer(command));
76+
let input = "What is 1 plus 1 plus 1?";
77+
let output = wordy::answer(input);
78+
let expected = Some(3);
79+
assert_eq!(output, expected);
6380
}
6481

6582
#[test]
6683
#[ignore]
6784
fn addition_and_subtraction() {
68-
let command = "What is 1 plus 5 minus -2?";
69-
assert_eq!(Some(8), answer(command));
85+
let input = "What is 1 plus 5 minus -2?";
86+
let output = wordy::answer(input);
87+
let expected = Some(8);
88+
assert_eq!(output, expected);
7089
}
7190

7291
#[test]
7392
#[ignore]
7493
fn multiple_subtraction() {
75-
let command = "What is 20 minus 4 minus 13?";
76-
assert_eq!(Some(3), answer(command));
94+
let input = "What is 20 minus 4 minus 13?";
95+
let output = wordy::answer(input);
96+
let expected = Some(3);
97+
assert_eq!(output, expected);
7798
}
7899

79100
#[test]
80101
#[ignore]
81102
fn subtraction_then_addition() {
82-
let command = "What is 17 minus 6 plus 3?";
83-
assert_eq!(Some(14), answer(command));
103+
let input = "What is 17 minus 6 plus 3?";
104+
let output = wordy::answer(input);
105+
let expected = Some(14);
106+
assert_eq!(output, expected);
84107
}
85108

86109
#[test]
87110
#[ignore]
88-
fn multiple_multiplications() {
89-
let command = "What is 2 multiplied by -2 multiplied by 3?";
90-
assert_eq!(Some(-12), answer(command));
111+
fn multiple_multiplication() {
112+
let input = "What is 2 multiplied by -2 multiplied by 3?";
113+
let output = wordy::answer(input);
114+
let expected = Some(-12);
115+
assert_eq!(output, expected);
91116
}
92117

93118
#[test]
94119
#[ignore]
95120
fn addition_and_multiplication() {
96-
let command = "What is -3 plus 7 multiplied by -2?";
97-
assert_eq!(Some(-8), answer(command));
121+
let input = "What is -3 plus 7 multiplied by -2?";
122+
let output = wordy::answer(input);
123+
let expected = Some(-8);
124+
assert_eq!(output, expected);
98125
}
99126

100127
#[test]
101128
#[ignore]
102-
fn multiple_divisions() {
103-
let command = "What is -12 divided by 2 divided by -3?";
104-
assert_eq!(Some(2), answer(command));
129+
fn multiple_division() {
130+
let input = "What is -12 divided by 2 divided by -3?";
131+
let output = wordy::answer(input);
132+
let expected = Some(2);
133+
assert_eq!(output, expected);
105134
}
106135

107136
#[test]
108137
#[ignore]
109138
fn unknown_operation() {
110-
let command = "What is 52 cubed?";
111-
assert_eq!(None, answer(command));
139+
let input = "What is 52 cubed?";
140+
let output = wordy::answer(input);
141+
let expected = None;
142+
assert_eq!(output, expected);
112143
}
113144

114145
#[test]
115146
#[ignore]
116147
fn non_math_question() {
117-
let command = "Who is the President of the United States?";
118-
assert_eq!(None, answer(command));
148+
let input = "Who is the President of the United States?";
149+
let output = wordy::answer(input);
150+
let expected = None;
151+
assert_eq!(output, expected);
119152
}
120153

121154
#[test]
122155
#[ignore]
123156
fn reject_problem_missing_an_operand() {
124-
let command = "What is 1 plus?";
125-
assert_eq!(None, answer(command));
157+
let input = "What is 1 plus?";
158+
let output = wordy::answer(input);
159+
let expected = None;
160+
assert_eq!(output, expected);
126161
}
127162

128163
#[test]
129164
#[ignore]
130165
fn reject_problem_with_no_operands_or_operators() {
131-
let command = "What is?";
132-
assert_eq!(None, answer(command));
166+
let input = "What is?";
167+
let output = wordy::answer(input);
168+
let expected = None;
169+
assert_eq!(output, expected);
133170
}
134171

135172
#[test]
136173
#[ignore]
137174
fn reject_two_operations_in_a_row() {
138-
let command = "What is 1 plus plus 2?";
139-
assert_eq!(None, answer(command));
175+
let input = "What is 1 plus plus 2?";
176+
let output = wordy::answer(input);
177+
let expected = None;
178+
assert_eq!(output, expected);
140179
}
141180

142181
#[test]
143182
#[ignore]
144183
fn reject_two_numbers_in_a_row() {
145-
let command = "What is 1 plus 2 1?";
146-
assert_eq!(None, answer(command));
184+
let input = "What is 1 plus 2 1?";
185+
let output = wordy::answer(input);
186+
let expected = None;
187+
assert_eq!(output, expected);
147188
}
148189

149190
#[test]
150191
#[ignore]
151192
fn reject_postfix_notation() {
152-
let command = "What is 1 2 plus?";
153-
assert_eq!(None, answer(command));
193+
let input = "What is 1 2 plus?";
194+
let output = wordy::answer(input);
195+
let expected = None;
196+
assert_eq!(output, expected);
154197
}
155198

156199
#[test]
157200
#[ignore]
158201
fn reject_prefix_notation() {
159-
let command = "What is plus 1 2?";
160-
assert_eq!(None, answer(command));
202+
let input = "What is plus 1 2?";
203+
let output = wordy::answer(input);
204+
let expected = None;
205+
assert_eq!(output, expected);
161206
}
162207

163208
#[test]
164209
#[ignore]
165210
#[cfg(feature = "exponentials")]
166211
fn exponential() {
167-
let command = "What is 2 raised to the 5th power?";
168-
assert_eq!(Some(32), answer(command));
212+
let input = "What is 2 raised to the 5th power?";
213+
let output = wordy::answer(input);
214+
let expected = Some(32);
215+
assert_eq!(output, expected);
169216
}
170217

171218
#[test]
172219
#[ignore]
173220
#[cfg(feature = "exponentials")]
174221
fn addition_and_exponential() {
175-
let command = "What is 1 plus 2 raised to the 2nd power?";
176-
assert_eq!(Some(9), answer(command));
222+
let input = "What is 1 plus 2 raised to the 2nd power?";
223+
let output = wordy::answer(input);
224+
let expected = Some(9);
225+
assert_eq!(output, expected);
177226
}

0 commit comments

Comments
 (0)