Skip to content

Commit

Permalink
two-bucket: test inability to reach the goal (#1580)
Browse files Browse the repository at this point in the history
1. A test where the goal is too large.

The student solution would need to either:

* (If searching the state space) Notice that there are no further states
  to be visited, and yet the solution has not been reached.
* Notice that the goal is larger than the larger bucket, therefore can
  be rejected immediately.

2. A test where the goal is not too large yet still can't be reached

The student solution would need to either:

* (If searching the state space) Notice that there are no further states
  to be visited, and yet the solution has not been reached.
* Notice that the goal is not divisible by the GCD of the bucket sizes,
  therefore can be rejected immediately.

In case the student assumes that all non-coprime bucket counts will
invalidate the goal, a counterexample to that is given as well (buckets
not coprime but goal is still possible).

There are ten implementing tracks:
bash csharp fsharp go java javascript python ruby rust typescript

Of these tracks, only two of them (Bash, Go) currently test the
condition where it is not possible to reach the goal.

Having this test serves as a reminder that it remains wise to handle the
situation where a search has not found its goal.

It doesn't seem like this was discussed in the original submission:
exercism/DEPRECATED.javascript#68
So it seems like it would be good to have a discussion of it on record.
petertseng authored Oct 31, 2020
1 parent 4d57825 commit 4482b50
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions exercises/two-bucket/canonical-data.json
Original file line number Diff line number Diff line change
@@ -96,6 +96,50 @@
"goalBucket": "two",
"otherBucket": 2
}
},
{
"uuid": "449be72d-b10a-4f4b-a959-ca741e333b72",
"description": "Not possible to reach the goal",
"property": "measure",
"input": {
"bucketOne": 6,
"bucketTwo": 15,
"goal": 5,
"startBucket": "one"
},
"expected": {
"error": "impossible"
}
},
{
"uuid": "aac38b7a-77f4-4d62-9b91-8846d533b054",
"description": "With the same buckets but a different goal, then it is possible",
"property": "measure",
"input": {
"bucketOne": 6,
"bucketTwo": 15,
"goal": 9,
"startBucket": "one"
},
"expected": {
"moves": 10,
"goalBucket": "two",
"otherBucket": 0
}
},
{
"uuid": "74633132-0ccf-49de-8450-af4ab2e3b299",
"description": "Goal larger than both buckets is impossible",
"property": "measure",
"input": {
"bucketOne": 5,
"bucketTwo": 7,
"goal": 8,
"startBucket": "one"
},
"expected": {
"error": "impossible"
}
}
]
}

0 comments on commit 4482b50

Please sign in to comment.