-
Notifications
You must be signed in to change notification settings - Fork 2
/
split_the_loot_spec.rb
83 lines (65 loc) · 2.1 KB
/
split_the_loot_spec.rb
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require "./split_the_loot"
describe "SplitTheLoot" do
before :each do
@splitter = SplitTheLoot.new
end
describe "Validation" do
it "should not devide when sum is not divisible by the number of pirates" do
@splitter.split([2,3],2).should == nil
end
it "should not divide when the number of pirates is greater than the number of gems" do
@splitter.split([3,3],3).should == nil
end
end
it "should return an empty treasure for a single pirate" do
@splitter.split([],1).should == [[]]
end
it "should return the treasure for a single pirate" do
@splitter.split([2,3],1).should == [[2,3]]
end
it "should distribuite one gem to each pirate" do
@splitter.split([2,2],2).should == [[2],[2]]
end
it "should distribuite two gems to each pirate" do
@splitter.split([2,1,2,1],2).each do |bucket|
bucket.sum.should == 3
end
end
it "should distribute two gems to each pirate in desc order" do
@splitter.split([2,2,1,1],2).each do |bucket|
bucket.sum.should == 3
end
end
it "should distribute different number of gems" do
@splitter.split([1,6,3,2],2).each do |bucket|
bucket.sum.should == 6
end
end
it "should distribute when the next gem is not a good choice" do
@splitter.split([8,1, 9,2 ,2,8],3).each do |bucket|
bucket.sum.should == 10
end
end
it "should distribute when the next gem is not a good choice for " do
@splitter.split([8,1, 8,2 ,2,9],3).each do |bucket|
bucket.sum.should == 10
end
end
it "should distribute when the next gem is not a good choice for the second time" do
@splitter.split([1, 8,2 ,9],2).each do |bucket|
bucket.sum.should == 10
end
end
#TODO motherfocker example
# it "should distribute when there is a bad choice for the second pirate" do
# @splitter.split([6,2,2,8,4],2).each do |bucket|
# bucket.sum.should == 10
# end
# end
it "should not distribute the undistribuitable" do
@splitter.split([8,2],2).should == nil
end
it "should work for a fucking example" do
@splitter.split([3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2],3).should == [[3, 2, 2, 2],[3, 2, 2, 2],[3, 2, 2, 2]]
end
end