Skip to content

Commit ef83525

Browse files
committed
Add tests for derangements
Two tests are currently broken because `derangements` returns an empty vector of the wrong type `Int[]` instead of `[Int[]]`.
1 parent 7a54fe5 commit ef83525

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/permutations.jl

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ end
6666
@test collect(multiset_permutations("", -1)) == Any[]
6767
@test length(multiset_permutations("aaaaaaaaaaaaaaaaaaaaab", 21)) == 22
6868

69+
# derangements
70+
@test length(collect(derangements(1:4))) == 9
71+
@test length(collect(derangements(1:8))) == derangement(8) == 14833
72+
@test collect(derangements(Int[])) == [Int[]]
73+
@test_broken collect(derangements([1, 1])) == [Int[]] # currently returns Int[]
74+
@test_broken collect(derangements([1, 1, 2])) == [Int[]] # currently returns Int[]
75+
@test collect(derangements([1, 1, 2, 2])) == [[2, 2, 1, 1]]
76+
@test map(join, derangements("aabbc")) == ["bbaca", "bbcaa", "bcaab", "cbaab"]
77+
@test map(join, derangements("aaabbbc")) == ["bbbaaca", "bbbacaa", "bbbcaaa", "bbcaaab", "bcbaaab", "cbbaaab"]
78+
6979
#nthperm!
7080
for n = 0:7, k = 1:factorial(n)
7181
p = nthperm!([1:n;], k)

0 commit comments

Comments
 (0)