1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
require 'spec_helper'
describe Immutable::Set do
[:reduce, :inject].each do |method|
describe "##{method}" do
[
[[], 10, 10],
[[1], 10, 9],
[[1, 2, 3], 10, 4],
].each do |values, initial, expected|
describe "on #{values.inspect}" do
let(:set) { S[*values] }
context "with an initial value of #{initial}" do
context 'and a block' do
it "returns #{expected.inspect}" do
set.send(method, initial) { |memo, item| memo - item }.should == expected
end
end
end
end
end
[
[[], nil],
[[1], 1],
[[1, 2, 3], 6],
].each do |values, expected|
describe "on #{values.inspect}" do
let(:set) { S[*values] }
context 'with no initial value' do
context 'and a block' do
it "returns #{expected.inspect}" do
set.send(method) { |memo, item| memo + item }.should == expected
end
end
end
end
end
describe 'with no block and a symbol argument' do
it 'uses the symbol as the name of a method to reduce with' do
S[1, 2, 3].reduce(:+).should == 6
end
end
describe 'with no block and a string argument' do
it 'uses the string as the name of a method to reduce with' do
S[1, 2, 3].reduce('+').should == 6
end
end
end
end
end
|