Skip to content

Instantly share code, notes, and snippets.

@jhannes
Created December 21, 2011 15:28
Show Gist options
  • Save jhannes/1506426 to your computer and use it in GitHub Desktop.
Save jhannes/1506426 to your computer and use it in GitHub Desktop.
minefield_spec
describe "Explored minefield", ->
expectHints = (mines) ->
expect(new exports.Minefield(mines:mines,explored:true).hints())
it "shows rows and columns", ->
expectHints(["...","..."]).toEqual ["000", "000"]
it "shows minefield shape", ->
expectHints(["..","..",".."]).toEqual ["00","00","00"]
it "shows mines", ->
expectHints(["**"]).toEqual ["**"]
it "shows hint right of mine", ->
expectHints(["*."]).toEqual ["*1"]
it "shows hint left of mine", ->
expectHints([".*"]).toEqual ["1*"]
it "shows hint below mine", ->
expectHints(["*","."]).toEqual ["*","1"]
it "shows hint above mine", ->
expectHints([".","*"]).toEqual ["1","*"]
it "shows hints around mine", ->
expectHints(["...", ".*.", "..."]).toEqual ["111","1*1", "111"]
it "counts mines around cell", ->
expectHints(["***", "*.*", "***"]).toEqual ["***","*8*", "***"]
describe "Unexplored minefiled", ->
it "hides minefield at start", ->
minefield = new exports.Minefield(mines:["**"], explored:false)
expect(minefield.hints()).toEqual ["??"]
it "reveals explored cells", ->
minefield = new exports.Minefield(mines:[".."], explored:false)
minefield.explore(0,1)
expect(minefield.hints()).toEqual ["?0"]
@jhannes
Copy link
Author

jhannes commented Dec 21, 2011

A much polished set of sets for the Minesweeper kata, based on a version pair programmed with Oleg Lutsensko in Kiev, who came up with the wording "it shows hint right of mine" (previous wording: "it indicates mine to the left")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment