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"] diff --git a/test/Project.toml b/test/Project.toml index 763c96d..566f586 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,5 @@ [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/combinations.jl b/test/combinations.jl index 612eecf..dfa7917 100644 --- a/test/combinations.jl +++ b/test/combinations.jl @@ -43,4 +43,70 @@ @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 + k = 5 + for (jl, py) in zip( + combinations(n, k), + pyitertools.combinations(n, k), + ) + @test jl == collect(py) + end + end + + @testset "combinations prop test 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 prop test 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 + + @testset "with_replacement_combinations prop test 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 prop test 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 prop test 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 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 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")