The standard programming problem in a Code Retreat is Conway's Game of Life. Code Retreats involve using Test Driven Development in writing solutions to the problem.
Since solution-code is not all the code to be written under TDD, my purpose here it to recording the tests (or "checks," as I prefer to call them,) that I came up with in actually moving through this problem in a TDD manner. This was a solo task, not something I did during a Code Retreat. (In those events pair programming is always used, and code is erased at the end of each session.) Also, I do not claim authorship of any of the solution code below. The solution I use here is a variation of the J solution on Rosetta Code. (The difference is the verb 'pad' used here, which I consider Raul Miller's work.)
This does not count as a "textbook" example of TDD because I had the solution code memorized when I sat down to write this. Thus, instead of having the automated checks "drive" the solution code that then made them pass, I knew exactly what I was about to make and created checks in advance of actually writing those sections of the solution. The format of Code Retreats doesn't really deal with the tension between TDD ideals and the repetition of a single simple problem. I consider it not my problem that I can go into an exercise with the solution memorized.
Each of the checks seen here were written first, although the code that makes those checks pass occurs in front of it. The code must be so positioned in order for the checks to pass, given that this example is arranged as a single file.
I have relatively high misgivings about creating a check for the adverb 'ctess'. It's such a short program it may well not make sense to give it a name, or a check of its own. My use of "cryptic" abbreviation, rather than spelling out in full words, might also come under criticism. I happen think that (;. _3) is the best available abbreviation, as it is the one which is most consistently valuable to learn, but by using a name I made the check fail prior to defining that adverb.
pad =: _1 _1 |. ] {.~ 2 + $
'pads all around' 1 : 0
assert. (3 3 $ 4 1 4 # 0 1 0) -: pad 1 1 $ 1
)
ctess=: ;. _3
'makes complete tesselations' 1 : 0
expected=. ,: 2 2& $&.> 8 0 ; 0 8
actual=. _2 _2 < ctess 2 3 $ 0 8 0
assert. expected -: actual
)
centerWasLive=: 4&{
'qualifies whether center was alive' 1 : 0
CENTER0=. -. CENTER1=. 3 3 $ 4 1 4 # 0 1 0
assert. 0 -: centerWasLive , CENTER0
assert. 1 -: centerWasLive , CENTER1
)
lives=: (+/ e. 3 + 0,centerWasLive)@,
'qualifies whether center is alive' 1 : 0
CENTER0=. -. CENTER1=. 3 3 $ 4 1 4 # 0 1 0
assert. 0 -: lives 3 3 $ 1
assert. 1 -: lives #: 0 7 0
)
generate=: (_3 _3 lives ctess ])@ pad
'cycles blinker' 1 : 0
BLINKERVT=. |: BLINKERHZ=. #: 0 7 0
assert. BLINKERVT -: generate BLINKERHZ
assert. BLINKERHZ -: generate BLINKERVT
)
smoutput 'All checks passed.'