I noticed Hangman does not have canonical data. (I am adding missing exercises to Go and it’s easier to add exercises with data.)
It is implemented on 7 tracks: csharp fsharp java ocaml powershell python tcl.
Based on the tests in those tracks, I propose the following test cases (plus the rest of the canonical data JSON file).
I would love feedback on this proposal, and/or a vote to implement this.
{
"description": "game state",
"comments": [
"The expected values may be returned from the guess function, or returned from a separate game state call.",
"They may also be accessed from a different call for each value, based on what is most idiomatic for the language.",
"To explore objects, each guessed letter should be a separate call."
],
"cases": [
{
"description": "Initially 9 failures are allowed and no letters are guessed",
"property": "guess",
"input": {
"word": "loot",
"guesses": []
},
"expected": {
"state": "Ongoing",
"maskedWord": "____",
"remainingFailures": 9
}
},
{
"description": "After 10 failures the game is over",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j"
]
},
"expected": {
"state": "Lose",
"maskedWord": "____",
"remainingFailures": 0
}
},
{
"description": "Losing with several correct guesses",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"t",
"o",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j"
]
},
"expected": {
"state": "Lose",
"maskedWord": "_oot",
"remainingFailures": 0
}
},
{
"description": "Feeding a correct letter removes underscores",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"t"
]
},
"expected": {
"state": "Ongoing",
"maskedWord": "___t",
"remainingFailures": 9
}
},
{
"description": "Feeding a correct letter twice counts as a failure",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"t",
"t"
]
},
"expected": {
"state": "Ongoing",
"maskedWord": "___t",
"remainingFailures": 8
}
},
{
"description": "Guessing a repeated letter reveals all instances",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"t",
"t",
"o"
]
},
"expected": {
"state": "Ongoing",
"maskedWord": "_oot",
"remainingFailures": 8
}
},
{
"description": "Getting all the letters right makes for a win",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"t",
"t",
"o",
"l"
]
},
"expected": {
"state": "Win",
"maskedWord": "loot",
"remainingFailures": 8
}
},
{
"description": "Winning on the last guess is still a win",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"t",
"o",
"l"
]
},
"expected": {
"state": "Win",
"maskedWord": "loot",
"remainingFailures": 0
}
},
{
"description": "Guessing after a lose is error",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k"
]
},
"expected": {
"error": "cannot guess after the game is lost"
}
},
{
"description": "Guessing after a win is error",
"property": "guess",
"input": {
"word": "loot",
"guesses": [
"t",
"o",
"l",
"l"
]
},
"expected": {
"error": "cannot guess after the game is won"
}
}
]
}