From c08c624ed6f31493a8e31d4c3afdb7d9090d7803 Mon Sep 17 00:00:00 2001 From: Nate McIntosh <40805156+natemcintosh@users.noreply.github.com> Date: Tue, 2 Aug 2022 08:58:48 -0400 Subject: [PATCH 1/8] Add PyCall as a test dependency --- test/Project.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/Project.toml diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..0cdae0f --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,4 @@ +[deps] +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From f2dcba246ada50c42da9be38287fd4736c004415 Mon Sep 17 00:00:00 2001 From: Nate McIntosh <40805156+natemcintosh@users.noreply.github.com> Date: Tue, 2 Aug 2022 08:59:25 -0400 Subject: [PATCH 2/8] add 3 property tests for combinations --- test/combinations.jl | 37 +++++++++++++++++++++++++++++++++++++ test/runtests.jl | 2 ++ 2 files changed, 39 insertions(+) diff --git a/test/combinations.jl b/test/combinations.jl index 2e7c74c..f127cb0 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -41,3 +41,40 @@ @test collect(powerset(['a', 'b', 'c'])) == Any[[],['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] @test collect(powerset(['a', 'b', 'c'], 1)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] @test collect(powerset(['a', 'b', 'c'], 1, 2)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c']] + +@testset "combinations fuzzing n=10, k=5" begin + n = 1:10 + k = 5 + for (jl, py) in zip( + combinations(n, k), + pyitertools.combinations(n, k), + ) + @test jl == collect(py) + end +end + +@testset "combinations fuzzing n=100, k=2" begin + n = 1:100 + k = 2 + for (jl, py) in zip( + combinations(n, k), + pyitertools.combinations(n, k), + ) + @test jl == collect(py) + end +end + +@testset "string combinations fuzzing n=20, k=3" begin + function pairwise(x) + zip(x, Iterators.drop(x, 1)) + end + s = "abcdefghijklmnopqrstu" + s2 = pairwise(s) + k = 3 + for (jl, py) in zip( + combinations(s2, k), + pyitertools.combinations(s2, k), + ) + @test jl == collect(py) + end +end diff --git a/test/runtests.jl b/test/runtests.jl index d790670..cc9552f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,7 @@ using Combinatorics using Test +using PyCall: pyimport +pyitertools = pyimport("itertools") include("numbers.jl") include("factorials.jl") From 0c9cbb50d3e08ef2fe1ae1923140c7c3b1a3d6d7 Mon Sep 17 00:00:00 2001 From: Nate McIntosh <40805156+natemcintosh@users.noreply.github.com> Date: Fri, 12 Aug 2022 20:44:19 -0400 Subject: [PATCH 3/8] added tests for combinations with replacement --- test/combinations.jl | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/test/combinations.jl b/test/combinations.jl index f127cb0..9e5b137 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -69,7 +69,7 @@ end zip(x, Iterators.drop(x, 1)) end s = "abcdefghijklmnopqrstu" - s2 = pairwise(s) + s2 = collect(pairwise(s)) k = 3 for (jl, py) in zip( combinations(s2, k), @@ -78,3 +78,40 @@ end @test jl == collect(py) end end + +@testset "with_replacement_combinations fuzzing n=10, k=5" begin + n = 1:10 + k = 5 + for (jl, py) in zip( + with_replacement_combinations(n, k), + pyitertools.combinations_with_replacement(n, k), + ) + @test jl == collect(py) + end +end + +@testset "with_replacement_combinations fuzzing n=100, k=2" begin + n = 1:100 + k = 2 + for (jl, py) in zip( + with_replacement_combinations(n, k), + pyitertools.combinations_with_replacement(n, k), + ) + @test jl == collect(py) + end +end + +@testset "string with_replacement_combinations fuzzing n=20, k=3" begin + function pairwise(x) + zip(x, Iterators.drop(x, 1)) + end + s = "abcdefghijklmnopqrstu" + s2 = collect(pairwise(s)) + k = 3 + for (jl, py) in zip( + with_replacement_combinations(s2, k), + pyitertools.combinations_with_replacement(s2, k), + ) + @test jl == collect(py) + end +end From 6ee6092242c673b26c01f78d9a63c2a8caaf48f9 Mon Sep 17 00:00:00 2001 From: Nate McIntosh <40805156+natemcintosh@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:24:41 -0500 Subject: [PATCH 4/8] Fix up testset indents --- test/combinations.jl | 126 +++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 66 deletions(-) diff --git a/test/combinations.jl b/test/combinations.jl index 396b916..7632d9d 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -37,82 +37,76 @@ @test [CoolLexCombinations(4, 2)...] == Vector[[1, 2], [2, 3], [1, 3], [2, 4], [3, 4], [1, 4]] @test isa(iterate(CoolLexCombinations(1000, 20))[2], Combinatorics.CoolLexIterState{BigInt}) -# Power set -@test collect(powerset([])) == Any[[]] -@test collect(powerset(['a', 'b', 'c'])) == Any[[],['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] -@test collect(powerset(['a', 'b', 'c'], 1)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] -@test collect(powerset(['a', 'b', 'c'], 1, 2)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c']] + # Power set + @test collect(powerset([])) == Any[[]] + @test collect(powerset(['a', 'b', 'c'])) == Any[[],['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] + @test collect(powerset(['a', 'b', 'c'], 1)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] + @test collect(powerset(['a', 'b', 'c'], 1, 2)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c']] -@testset "combinations fuzzing n=10, k=5" begin - n = 1:10 - k = 5 - for (jl, py) in zip( - combinations(n, k), - pyitertools.combinations(n, k), - ) - @test jl == collect(py) + @testset "combinations fuzzing n=10, k=5" begin + n = 1:10 + k = 5 + for (jl, py) in zip( + combinations(n, k), + pyitertools.combinations(n, k), + ) + @test jl == collect(py) + end end -end -@testset "combinations fuzzing n=100, k=2" begin - n = 1:100 - k = 2 - for (jl, py) in zip( - combinations(n, k), - pyitertools.combinations(n, k), - ) - @test jl == collect(py) + @testset "combinations fuzzing n=100, k=2" begin + n = 1:100 + k = 2 + for (jl, py) in zip( + combinations(n, k), + pyitertools.combinations(n, k), + ) + @test jl == collect(py) + end end -end -@testset "string combinations fuzzing n=20, k=3" begin - function pairwise(x) - zip(x, Iterators.drop(x, 1)) + @testset "string combinations fuzzing n=20, k=3" begin + s = collect("abcdefghijklmnopqrstu") + k = 3 + for (jl, py) in zip( + combinations(s, k), + pyitertools.combinations(s, k), + ) + @test jl == collect(py) + end end - s = "abcdefghijklmnopqrstu" - s2 = collect(pairwise(s)) - k = 3 - for (jl, py) in zip( - combinations(s2, k), - pyitertools.combinations(s2, k), - ) - @test jl == collect(py) - end -end -@testset "with_replacement_combinations fuzzing n=10, k=5" begin - n = 1:10 - k = 5 - for (jl, py) in zip( - with_replacement_combinations(n, k), - pyitertools.combinations_with_replacement(n, k), - ) - @test jl == collect(py) + @testset "with_replacement_combinations fuzzing n=10, k=5" begin + n = 1:10 + k = 5 + for (jl, py) in zip( + with_replacement_combinations(n, k), + pyitertools.combinations_with_replacement(n, k), + ) + @test jl == collect(py) + end end -end -@testset "with_replacement_combinations fuzzing n=100, k=2" begin - n = 1:100 - k = 2 - for (jl, py) in zip( - with_replacement_combinations(n, k), - pyitertools.combinations_with_replacement(n, k), - ) - @test jl == collect(py) + @testset "with_replacement_combinations fuzzing n=100, k=2" begin + n = 1:100 + k = 2 + for (jl, py) in zip( + with_replacement_combinations(n, k), + pyitertools.combinations_with_replacement(n, k), + ) + @test jl == collect(py) + end end -end -@testset "string with_replacement_combinations fuzzing n=20, k=3" begin - function pairwise(x) - zip(x, Iterators.drop(x, 1)) - end - s = "abcdefghijklmnopqrstu" - s2 = collect(pairwise(s)) - k = 3 - for (jl, py) in zip( - with_replacement_combinations(s2, k), - pyitertools.combinations_with_replacement(s2, k), - ) - @test jl == collect(py) + @testset "string with_replacement_combinations fuzzing n=20, k=3" begin + s = collect("abcdefghijklmnopqrstu") + k = 3 + for (jl, py) in zip( + with_replacement_combinations(s, k), + pyitertools.combinations_with_replacement(s, k), + ) + @test jl == collect(py) + end end + end From a0e4c309c95ed24fe6b58bc02ea51fbb087b6ac2 Mon Sep 17 00:00:00 2001 From: Nate McIntosh <40805156+natemcintosh@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:27:39 -0500 Subject: [PATCH 5/8] change name --- test/combinations.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/combinations.jl b/test/combinations.jl index 7632d9d..3b4300d 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -43,7 +43,7 @@ @test collect(powerset(['a', 'b', 'c'], 1)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] @test collect(powerset(['a', 'b', 'c'], 1, 2)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c']] - @testset "combinations fuzzing n=10, k=5" begin + @testset "combinations prop test n=10, k=5" begin n = 1:10 k = 5 for (jl, py) in zip( @@ -54,7 +54,7 @@ end end - @testset "combinations fuzzing n=100, k=2" begin + @testset "combinations prop test n=100, k=2" begin n = 1:100 k = 2 for (jl, py) in zip( @@ -65,7 +65,7 @@ end end - @testset "string combinations fuzzing n=20, k=3" begin + @testset "string combinations prop test n=20, k=3" begin s = collect("abcdefghijklmnopqrstu") k = 3 for (jl, py) in zip( @@ -76,7 +76,7 @@ end end - @testset "with_replacement_combinations fuzzing n=10, k=5" begin + @testset "with_replacement_combinations prop test n=10, k=5" begin n = 1:10 k = 5 for (jl, py) in zip( @@ -87,7 +87,7 @@ end end - @testset "with_replacement_combinations fuzzing n=100, k=2" begin + @testset "with_replacement_combinations prop test n=100, k=2" begin n = 1:100 k = 2 for (jl, py) in zip( @@ -98,7 +98,7 @@ end end - @testset "string with_replacement_combinations fuzzing n=20, k=3" begin + @testset "string with_replacement_combinations prop test n=20, k=3" begin s = collect("abcdefghijklmnopqrstu") k = 3 for (jl, py) in zip( From a484697ce37eaf9163a8dd970642ab2bdc0ff573 Mon Sep 17 00:00:00 2001 From: Nate McIntosh <40805156+natemcintosh@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:31:12 -0500 Subject: [PATCH 6/8] add permutation property tests --- test/permutations.jl | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/test/permutations.jl b/test/permutations.jl index ae18b48..e683f19 100644 --- a/test/permutations.jl +++ b/test/permutations.jl @@ -30,7 +30,7 @@ end @test collect(permutations([], -1)) == Any[] @test collect(permutations([], 0)) == [Any[]] @test collect(permutations([], 1)) == Any[] - + @testset "permutation lengths" begin expected_lengths = [1, 5, 20, 60, 120, 120] ks = 0:5 @@ -105,4 +105,37 @@ end @test Combinatorics.nsetpartitions(-1) == 0 @test collect(permutations([])) == [[]] + @testset "permutations prop test n=10, k=5" begin + n = 1:10 + k = 5 + for (jl, py) in zip( + permutations(n, k), + pyitertools.permutations(n, k), + ) + @test jl == collect(py) + end + end + + @testset "permutations prop test n=100, k=2" begin + n = 1:100 + k = 2 + for (jl, py) in zip( + permutations(n, k), + pyitertools.permutations(n, k), + ) + @test jl == collect(py) + end + end + + @testset "string permutations prop test n=20, k=3" begin + s = collect("abcdefghijklmnopqrstu") + k = 3 + for (jl, py) in zip( + permutations(s, k), + pyitertools.permutations(s, k), + ) + @test jl == collect(py) + end + end + end From 2c6655b2ca7c0265656e4c985162ff5459c95c76 Mon Sep 17 00:00:00 2001 From: Nate McIntosh <40805156+natemcintosh@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:38:47 -0500 Subject: [PATCH 7/8] Master has the spaces --- test/combinations.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/combinations.jl b/test/combinations.jl index 3b4300d..dfa7917 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -39,9 +39,9 @@ # Power set @test collect(powerset([])) == Any[[]] - @test collect(powerset(['a', 'b', 'c'])) == Any[[],['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] - @test collect(powerset(['a', 'b', 'c'], 1)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] - @test collect(powerset(['a', 'b', 'c'], 1, 2)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c']] + @test collect(powerset(['a', 'b', 'c'])) == Any[[], ['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']] + @test collect(powerset(['a', 'b', 'c'], 1)) == Any[['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']] + @test collect(powerset(['a', 'b', 'c'], 1, 2)) == Any[['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c']] @testset "combinations prop test n=10, k=5" begin n = 1:10 From a597eb0d071baee5a1178cb3f9461b5d7260495d Mon Sep 17 00:00:00 2001 From: Nate McIntosh <40805156+natemcintosh@users.noreply.github.com> Date: Wed, 1 Feb 2023 12:52:34 -0500 Subject: [PATCH 8/8] get test dependencies working for 1.0-1.1 --- Project.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 89c2c24..e38acc9 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ julia = "1" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" [targets] -test = ["LinearAlgebra", "OffsetArrays", "Test"] +test = ["LinearAlgebra", "OffsetArrays", "Test", "PyCall"]