Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests based on python's itertools #130

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
66 changes: 66 additions & 0 deletions test/combinations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
35 changes: 34 additions & 1 deletion test/permutations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Combinatorics
using Test
using PyCall: pyimport
pyitertools = pyimport("itertools")

include("numbers.jl")
include("factorials.jl")
Expand Down