Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 12 additions & 49 deletions test/iterators_test.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@testitem "iterators.jl" begin
@testset "SubsetGrayCode iterates over all weight k subsets of {1,..,n} (single iterator)" begin
len = 15
weight = 7
sgc = CodingTheory.SubsetGrayCode(len, weight)
len = 7
weight = 5
sgc = CodingTheory.SubsetGrayCode(len, weight, UInt(21), UInt(0))
all_subsets_gray = fill(fill(0, weight), length(sgc))
subset = collect(1:sgc.k)
state = (subset, 1, fill(-1, 3))
Expand All @@ -16,44 +16,7 @@
sort!(all_subsets_gray)
all_subsets_hecke = CodingTheory.Oscar.subsets(collect(1:len), weight)
sort!(all_subsets_hecke)
@test length(all_subsets_gray) == 6435
@test all_subsets_gray == all_subsets_hecke
end

@testset "SubsetGrayCode iterates over all weight k subsets of {1,..,n} (split iterator)" begin
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this test b/c not breaking itr up this way anymore

len = 15
weight = 7
num_threads = 3 # split the iterator into 3 parts
itrs = CodingTheory._subset_gray_codes_from_num_threads(len, weight, num_threads)
@test length(itrs) == num_threads
initial_subset_vecs = fill(fill(0, weight), length(itrs))
bin = extended_binomial(len, weight)
for j in eachindex(itrs)
itr = itrs[j]
@test length(itr) == fld(bin, num_threads)
subset_vec = zeros(Int, itr.k)
CodingTheory._subset_unrank!(itr.init_rank, UInt(itr.n), subset_vec)
initial_subset_vecs[j] = subset_vec
end

all_subsets_gray = fill(fill(0, weight), bin)

for j in 0:length(itrs)-1
sgc = itrs[j + 1]
subset_vec = initial_subset_vecs[j + 1]
state = (subset_vec, 1, fill(-1, 3))
for i in 1:length(sgc)
all_subsets_gray[j * fld(bin, num_threads) + i] = deepcopy(subset_vec)
next = iterate(sgc, state)
isnothing(next) && break
(_, state) = next
(subset_vec, _, _) = state
end
end
sort!(all_subsets_gray)
all_subsets_hecke = CodingTheory.Oscar.subsets(collect(1:len), weight)
sort!(all_subsets_hecke)
@test length(all_subsets_gray) == 6435
@test length(all_subsets_gray) == 21
@test all_subsets_gray == all_subsets_hecke
end

Expand All @@ -79,28 +42,28 @@
k1 = UInt(3)
n1 = UInt(5)
rank1 = CodingTheory._subset_rank(subset1, k1)
@test rank1 == 0
@test rank1 == 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iterators were changed to index from 1 and Id forgeten to change the test

result1 = zeros(Int, k1)
CodingTheory._subset_unrank!(rank1, n1, result1)
CodingTheory._subset_unrank!(UInt128(rank1), n1, result1)
@test result1 == subset1

subset2 = UInt.([1, 3, 5])
k2 = UInt(3)
n2 = UInt(5)
rank2 = CodingTheory._subset_rank(subset2, k2)
@test rank2 == 7
@test rank2 == 8
result2 = zeros(Int, k2)
CodingTheory._subset_unrank!(rank2, n2, result2)
CodingTheory._subset_unrank!(UInt128(rank2), n2, result2)
@test result2 == subset2

k3 = UInt(3)
n3 = UInt(5)
result3 = zeros(Int, k3)
results = Set()
results = Set{Vector{UInt64}}()
bin = binomial(n3, k3)
for i::BigInt in collect(0: bin - 1)
CodingTheory._subset_unrank!(i, n3, result3)
pushOrDel!(results, deepcopy(result3))
for i::BigInt in collect(1: bin)
CodingTheory._subset_unrank!(UInt128(i), n3, result3)
pushOrDel!(results, deepcopy(Vector{UInt64}(result3)))
end
all_subsets_hecke = Set(CodingTheory.Hecke.subsets(collect(1:n3), Int(k3)))
@test results == all_subsets_hecke
Expand Down
Loading