-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrouper_test.rb
155 lines (135 loc) · 3.64 KB
/
grouper_test.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
require 'test/unit'
require 'grouper'
class Array
def swap(i, j)
temp = self[i]
self[i] = self[j]
self[j] = temp
end
end
class GrouperTest < Test::Unit::TestCase
def setup
@grouper = Grouper.new(5, 3)
end
def test_binomials
assert_equal 15, @grouper.binom(6, 2)
end
def test_combine_indexes_when_n_is_2_and_k_is_0
assert_equal [[0],[1]], Grouper.new(2,0).combine_indexes
end
def test_combine_indexes_when_n_is_2_and_k_is_1
assert_equal [[0],[1]], Grouper.new(2,1).combine_indexes
end
def test_combine_indexes_when_n_is_4_and_k_is_2
assert_equal [[0, 1],
[0, 2],
[0, 3],
[1, 2],
[1, 3],
[2, 3]], Grouper.new(4,2).combine_indexes
end
def test_combine_indexes_when_n_is_5_and_k_is_3
assert_equal [[0, 1, 2],
[0, 1, 3],
[0, 1, 4],
[0, 2, 3],
[0, 2, 4],
[0, 3, 4],
[1, 2, 3],
[1, 2, 4],
[1, 3, 4],
[2, 3, 4]], Grouper.new(5,3).combine_indexes
end
def test_permute
assert_equal [4,0,1,2,3,5], Grouper.new(nil, 0).permute([0,1,2,3,4,5])
assert_equal [4,0,2,1,3,5], Grouper.new(nil, 4).permute([0,1,2,3,4,5])
end
def test_off_by_1
g = Grouper.new(5, 2)
assert g.only_off_by_1([[1,2], [3,4]], [])
assert g.only_off_by_1([1,2], [3,4])
assert !g.only_off_by_1([[1,2]], [3,4], [2,3] )
end
def test_off_by_1_with_9_C_3
g = Grouper.new(9, 3)
assert ! g.only_off_by_1([[0,1,2]],[0,1,3])
end
def xxxtest_permute_with_10_C_2
g = Grouper.new(10, 2)
g.apply_rules
end
def test_permutation_of_2
g = Grouper.new(3, 2)
g.apply_rules
g = Grouper.new(4, 2)
g.apply_rules
g = Grouper.new(5, 2)
g.apply_rules
g = Grouper.new(6, 2)
g.apply_rules
g = Grouper.new(7, 2)
g.apply_rules
g = Grouper.new(8, 2)
g.apply_rules
g = Grouper.new(9, 2)
g.apply_rules
g = Grouper.new(10, 2)
g.apply_rules
g = Grouper.new(11, 2)
g.apply_rules
end
def test_permutation_of_3
g = Grouper.new(5, 3)
g.apply_rules
g = Grouper.new(7, 3)
g.apply_rules
g = Grouper.new(8, 3)
g.apply_rules
g = Grouper.new(9, 3)
g.apply_rules
g = Grouper.new(10, 3)
g.apply_rules
g = Grouper.new(11, 3)
g.apply_rules
g = Grouper.new(12, 3)
g.apply_rules
g = Grouper.new(13, 3)
g.apply_rules
end
def test_permutation_of_4
g = Grouper.new(5, 4)
g.apply_rules
g = Grouper.new(6, 4)
g.apply_rules
g = Grouper.new(7, 4)
g.apply_rules
g = Grouper.new(8, 4)
g.apply_rules
g = Grouper.new(9, 4)
g.apply_rules
g = Grouper.new(10, 4)
g.apply_rules
end
# Steiner system S(t, k, v)
def steiner_ternary(n)
t = n*(n-1)/6
(1..n).each do |x|
#
# Variables: X = {Xi | i an integer in [1,t]}.
# Domain: for all Xi in X, D(Xi) = {1,...,n}.
# Constraints:
# every set variable Xi has a cardinality of 3:
# for all i in [1,t], |Xi| = 3.
# the cardinality of the intersection of every two distinct sets must not exceed 1:
# for all i,j in [1,t], |intersection(Xi,Xj)|<=1.
end
end
=begin
for j = 2 to length(s) {
swap s[(k mod j) + 1] with s[j]; // note that our array is indexed starting at 1
k := k / j; // integer division cuts off the remainder
}
return s;
}
=end
end