Skip to content

Commit 5d5ee5a

Browse files
committed
wordy 1.3.0: Reject syntax errors
I unfortunately considered the existing example solution not quite up to the task of doing this, so I was forced to write a new implementation from scratch. exercism/problem-specifications#1383
1 parent e669aef commit 5d5ee5a

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

exercises/wordy/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[package]
22
name = "wordy"
3-
version = "1.2.0"
3+
version = "1.3.0"

exercises/wordy/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ left-to-right, _ignoring the typical order of operations._
4343
4444
15 (i.e. not 9)
4545

46+
## Iteration 4 — Errors
47+
48+
The parser should reject:
49+
50+
* Unsupported operations ("What is 52 cubed?")
51+
* Non-math questions ("Who is the President of the United States")
52+
* Word problems with invalid syntax ("What is 1 plus plus 2?")
53+
4654
## Bonus — Exponentials
4755

4856
If you'd like, handle exponentials.

exercises/wordy/tests/wordy.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,38 @@ fn non_math_question() {
112112
let command = "Who is the President of the United States?";
113113
assert!(answer(command).is_none());
114114
}
115+
116+
#[test]
117+
#[ignore]
118+
fn reject_incomplete_problem() {
119+
let command = "What is 1 plus?";
120+
assert!(answer(command).is_none());
121+
}
122+
123+
#[test]
124+
#[ignore]
125+
fn reject_two_operations_in_a_row() {
126+
let command = "What is 1 plus plus 2?";
127+
assert!(answer(command).is_none());
128+
}
129+
130+
#[test]
131+
#[ignore]
132+
fn reject_two_numbers_in_a_row() {
133+
let command = "What is 1 plus 2 1?";
134+
assert!(answer(command).is_none());
135+
}
136+
137+
#[test]
138+
#[ignore]
139+
fn reject_postfix_notation() {
140+
let command = "What is 1 2 plus?";
141+
assert!(answer(command).is_none());
142+
}
143+
144+
#[test]
145+
#[ignore]
146+
fn reject_prefix_notation() {
147+
let command = "What is plus 1 2?";
148+
assert!(answer(command).is_none());
149+
}

0 commit comments

Comments
 (0)