spec/lib/numeron/calculator_spec.rb in numeron-1.2.0 vs spec/lib/numeron/calculator_spec.rb in numeron-1.3.0

- old
+ new

@@ -74,10 +74,40 @@ it "1e0b" do calc.input('123', 1, 0) calc.shuffle calc.possibilities.should have(378).items end + + it "mays[0] is 3 and shuffle" do + calc.mays[0] = [3] + calc.shuffle + # 3が利用されているのは確定 + calc.mays[0].should =~ (0..9).to_a + calc.mays[1].should =~ (0..9).to_a + calc.mays[2].should =~ (0..9).to_a + + calc.possibilities.should have(216).items + end + + context 'using slash' do + it 'slash 2' do + calc.slash(2) + calc.possibilities.should have(48).items + calc.shuffle + calc.possibilities.should have(48).items + end + + it '1e1b, slash 2, shuffle' do + calc.input('123', 1, 1) + calc.possibilities.should have(42).items + calc.slash(2) + calc.possibilities.should =~ %w(021 102 243 324) + calc.shuffle + # 数字の組み合わせは 012 or 234のみなので、 (3 * 2 * 1) * 2 = 12パターン + calc.possibilities.should =~ %W(021 012 201 210 102 120 243 234 342 324 432 423) + end + end end describe '#slash' do # slashを使った場合は、解の可能性は 6 * (10 - n) * (n - 1)に絞られる # 正しくは、 s! * (10 - n) * (n - s + 2) (sはカードの枚数、 nはslash number, s!はsの階乗) @@ -117,9 +147,129 @@ end it 'slash 9' do calc.slash(9) calc.possibilities.should have(48).items + end + end + + describe '#change' do + it '0, true' do + calc.change(0, true) + calc.mays[0].should == (5..9).to_a + end + + it '1, false' do + calc.change(1, false) + calc.mays[1].should == (0..4).to_a + end + + it '234(0e3b), change(0, false)' do + calc.input('234', 0, 3) # answer 342 + calc.change(0, false) # answer 142 + calc.mays[0].should =~ [0, 1] + calc.mays[1].should =~ [2, 4] + calc.mays[2].should =~ [2, 3] + calc.possibilities.should =~ %w(023 042 043 123 142 143) + end + + it '345(0e3b), change(0, false), shuffle' do + calc.input('345', 0, 3) # answer 453 + calc.change(0, false) # 253 + calc.mays[0].should == [0, 1, 2] + calc.mays[1].should == [5] + calc.mays[2].should == [3, 4] + calc.possibilities.should =~ %w(054 053 153 154 253 254) + calc.shuffle + calc.mays[0].should =~ [0, 1, 2, 3, 4, 5] + calc.mays[1].should =~ [0, 1, 2, 3, 4, 5] + calc.mays[2].should =~ [0, 1, 2, 3, 4, 5] + # 5確定なので、 3 * 5 * 4 = 60 (5の位置3箇所) * (5を除く可能性数) * (5を除く可能性数 - 1つ前の数値) + calc.possibilities.should have(60).items + end + + it '456(0e3b), change(0, false)' do + calc.input('456', 0, 3) # answer 564 + calc.change(2, false) + calc.mays[0].should == [5] + calc.mays[1].should == [6] + calc.mays[2].should == [0, 1, 2, 3] + calc.possibilities.should =~ %w(560 561 562 563) + end + + it '1e2b, 0, false' do + calc.input('123', 1, 2) # 132 + calc.change(0, false) # 432 + calc.mays[0].should == [0, 4] + calc.mays[1].should == [1, 2, 3] + calc.mays[2].should == [1, 2, 3] + calc.possibilities.should =~ %w(012 013 021 023 031 032 412 413 421 423 431 432) + end + end + + describe '#high_and_low' do + it 'simple' do + calc.high_and_low([true, false, true]) + calc.mays[0].should =~ [5, 6, 7, 8, 9] + calc.mays[1].should =~ [0, 1, 2, 3, 4] + calc.mays[2].should =~ [5, 6, 7, 8, 9] + calc.possibilities.should have(100).items + end + + it '345(0e3b), high_and_low' do + calc.input('345', 0, 3) # 4 5 3 + calc.high_and_low([false, true, false]) + calc.mays[0].should =~ [4] + calc.mays[1].should =~ [5] + calc.mays[2].should =~ [3] + calc.possibilities.should == %w(453) + end + + it '345(1e2b), high_and_low' do + calc.input('354', 1, 2) # 4 5 3 + calc.high_and_low([false, true, false]) + calc.mays[0].should =~ [3, 4] + calc.mays[1].should =~ [5] + calc.mays[2].should =~ [3, 4] + calc.possibilities.should == %w(453) + end + + it '345(0e1b), high_and_low' do + calc.input('354', 0, 1) # 4 6 2 + calc.high_and_low([false, true, false]) + calc.mays[0].should =~ [0, 1, 2, 4] + calc.mays[1].should =~ [6, 7, 8, 9] + calc.mays[2].should =~ [0, 1, 2, 3] + + # [4] * [6, 7, 8, 9] * [0, 1, 2] + [0, 1, 2] * [6, 7, 8, 9] * [3] = 4 * 3 * 2 = 24 + calc.possibilities.should have(24).items + end + end + + describe '#target' do + it 'simple' do + calc.target(0, 0) + calc.mays[0].should =~ [0] + calc.mays[1].should =~ (1..9).to_a + calc.mays[2].should =~ (1..9).to_a + calc.possibilities.should have(72).items + end + + it 'target(0, nil)' do + calc.target(0) + calc.mays[0].should =~ (1..9).to_a + calc.mays[1].should =~ (1..9).to_a + calc.mays[2].should =~ (1..9).to_a + calc.possibilities.should have(504).items + end + + it '123(0e3b), target(1, 1)' do + calc.input('123', 0, 3) + calc.target(1, 1) + calc.mays[0].should =~ [3] + calc.mays[1].should =~ [1] + calc.mays[2].should =~ [2] + calc.possibilities.should =~ %w(312) end end describe "scenario" do it "1e0b, 1e2b" do \ No newline at end of file