Skip to content

Commit 23a2c67

Browse files
committed
Merge branch 'master' into dev
2 parents 1ea24e1 + 82d8d09 commit 23a2c67

File tree

1 file changed

+12
-49
lines changed

1 file changed

+12
-49
lines changed

test/iterators_test.jl

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@testitem "iterators.jl" begin
22
@testset "SubsetGrayCode iterates over all weight k subsets of {1,..,n} (single iterator)" begin
3-
len = 15
4-
weight = 7
5-
sgc = CodingTheory.SubsetGrayCode(len, weight)
3+
len = 7
4+
weight = 5
5+
sgc = CodingTheory.SubsetGrayCode(len, weight, UInt(21), UInt(0))
66
all_subsets_gray = fill(fill(0, weight), length(sgc))
77
subset = collect(1:sgc.k)
88
state = (subset, 1, fill(-1, 3))
@@ -16,44 +16,7 @@
1616
sort!(all_subsets_gray)
1717
all_subsets_hecke = CodingTheory.Oscar.subsets(collect(1:len), weight)
1818
sort!(all_subsets_hecke)
19-
@test length(all_subsets_gray) == 6435
20-
@test all_subsets_gray == all_subsets_hecke
21-
end
22-
23-
@testset "SubsetGrayCode iterates over all weight k subsets of {1,..,n} (split iterator)" begin
24-
len = 15
25-
weight = 7
26-
num_threads = 3 # split the iterator into 3 parts
27-
itrs = CodingTheory._subset_gray_codes_from_num_threads(len, weight, num_threads)
28-
@test length(itrs) == num_threads
29-
initial_subset_vecs = fill(fill(0, weight), length(itrs))
30-
bin = extended_binomial(len, weight)
31-
for j in eachindex(itrs)
32-
itr = itrs[j]
33-
@test length(itr) == fld(bin, num_threads)
34-
subset_vec = zeros(Int, itr.k)
35-
CodingTheory._subset_unrank!(itr.init_rank, UInt(itr.n), subset_vec)
36-
initial_subset_vecs[j] = subset_vec
37-
end
38-
39-
all_subsets_gray = fill(fill(0, weight), bin)
40-
41-
for j in 0:length(itrs)-1
42-
sgc = itrs[j + 1]
43-
subset_vec = initial_subset_vecs[j + 1]
44-
state = (subset_vec, 1, fill(-1, 3))
45-
for i in 1:length(sgc)
46-
all_subsets_gray[j * fld(bin, num_threads) + i] = deepcopy(subset_vec)
47-
next = iterate(sgc, state)
48-
isnothing(next) && break
49-
(_, state) = next
50-
(subset_vec, _, _) = state
51-
end
52-
end
53-
sort!(all_subsets_gray)
54-
all_subsets_hecke = CodingTheory.Oscar.subsets(collect(1:len), weight)
55-
sort!(all_subsets_hecke)
56-
@test length(all_subsets_gray) == 6435
19+
@test length(all_subsets_gray) == 21
5720
@test all_subsets_gray == all_subsets_hecke
5821
end
5922

@@ -79,28 +42,28 @@
7942
k1 = UInt(3)
8043
n1 = UInt(5)
8144
rank1 = CodingTheory._subset_rank(subset1, k1)
82-
@test rank1 == 0
45+
@test rank1 == 1
8346
result1 = zeros(Int, k1)
84-
CodingTheory._subset_unrank!(rank1, n1, result1)
47+
CodingTheory._subset_unrank!(UInt128(rank1), n1, result1)
8548
@test result1 == subset1
8649

8750
subset2 = UInt.([1, 3, 5])
8851
k2 = UInt(3)
8952
n2 = UInt(5)
9053
rank2 = CodingTheory._subset_rank(subset2, k2)
91-
@test rank2 == 7
54+
@test rank2 == 8
9255
result2 = zeros(Int, k2)
93-
CodingTheory._subset_unrank!(rank2, n2, result2)
56+
CodingTheory._subset_unrank!(UInt128(rank2), n2, result2)
9457
@test result2 == subset2
9558

9659
k3 = UInt(3)
9760
n3 = UInt(5)
9861
result3 = zeros(Int, k3)
99-
results = Set()
62+
results = Set{Vector{UInt64}}()
10063
bin = binomial(n3, k3)
101-
for i::BigInt in collect(0: bin - 1)
102-
CodingTheory._subset_unrank!(i, n3, result3)
103-
pushOrDel!(results, deepcopy(result3))
64+
for i::BigInt in collect(1: bin)
65+
CodingTheory._subset_unrank!(UInt128(i), n3, result3)
66+
pushOrDel!(results, deepcopy(Vector{UInt64}(result3)))
10467
end
10568
all_subsets_hecke = Set(CodingTheory.Hecke.subsets(collect(1:n3), Int(k3)))
10669
@test results == all_subsets_hecke

0 commit comments

Comments
 (0)