Slide 108
Slide 108 text
describe 'natural numbers' do
specify { ADD[representation_of 2][representation_of 3].should represent 2 + 3 }
specify { MULTIPLY[representation_of 2][representation_of 3].should represent 2 * 3 }
specify { POWER[representation_of 2][representation_of 3].should represent 2 ** 3 }
specify { SUBTRACT[representation_of 3][representation_of 2].should represent 3 - 2 }
context 'with booleans' do
(0..3).each do |n|
specify { IS_ZERO[representation_of n].should represent n.zero? }
specify { IS_EQUAL[representation_of n][representation_of 2].should represent n == 2 }
end
end
context 'with recursion' do
(0..5).zip([1, 1, 2, 6, 24, 120]) do |n, n_factorial|
specify { FACTORIAL[representation_of n].should represent n_factorial }
end
[0, 1, 11, 27].product([1, 3, 11]) do |m, n|
specify { DIV[representation_of m][representation_of n].should represent m / n }
specify { MOD[representation_of m][representation_of n].should represent m % n }
end
end
context 'with strings' do
specify { TO_STRING[representation_of 42].should represent '42' }
end
end
https://github.com/tomstuart/nothing