Skip to content

Commit 78b31c3

Browse files
committed
Reorganize tests
Functions from src/foo.jl are now tested in test/foo.jl
1 parent 9328ef1 commit 78b31c3

File tree

8 files changed

+143
-124
lines changed

8 files changed

+143
-124
lines changed

test/basic.jl

Lines changed: 0 additions & 55 deletions
This file was deleted.

test/combinations.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Combinatorics
2+
using Base.Test
3+
4+
import Combinatorics: combinations
5+
6+
7+
@test collect(combinations([])) == []
8+
@test collect(combinations(['a', 'b', 'c'])) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']]
9+
10+
@test collect(combinations("abc",3)) == Any[['a','b','c']]
11+
@test collect(combinations("abc",2)) == Any[['a','b'],['a','c'],['b','c']]
12+
@test collect(combinations("abc",1)) == Any[['a'],['b'],['c']]
13+
@test collect(combinations("abc",0)) == Any[Char[]]
14+
@test collect(combinations("abc",-1)) == Any[]
15+
16+
@test collect(filter(x->(iseven(x[1])),combinations([1,2,3],2))) == Any[[2,3]]
17+

test/factorials.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Combinatorics
2+
using Base.Test
3+
4+
# derangement
5+
@test derangement(4) == 9
6+
@test derangement(24) == parse(BigInt,"228250211305338670494289")
7+
8+
# doublefactorial
9+
@test doublefactorial(70) == parse(BigInt,"355044260642859198243475901411974413130137600000000")
10+
11+
# hyperfactorial
12+
@test hyperfactorial(8) == parse(BigInt,"55696437941726556979200000")
13+
14+
# multifactorial
15+
@test multifactorial(40,2) == doublefactorial(40)
16+
17+
# multinomial
18+
@test multinomial(1,4,4,2) == 34650
19+
20+
# primorial
21+
@test primorial(17) == 510510
22+
23+

test/frombase.jl

Lines changed: 0 additions & 67 deletions
This file was deleted.

test/numbers.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Combinatorics
2+
using Base.Test
3+
4+
# catalan
5+
@test catalannum(5) == 42
6+
@test catalannum(30) == parse(BigInt,"3814986502092304")
7+
8+
# fibonacci
9+
@test fibonaccinum(5) == 5
10+
@test fibonaccinum(101) == parse(BigInt,"573147844013817084101")
11+
12+
# lassalle
13+
@test lassallenum(14) == parse(BigInt,"270316008395632253340")
14+
15+
# legendresymbol
16+
@test legendresymbol(1001,9907) == jacobisymbol(1001,9907) == -1
17+
18+
# lucas
19+
@test lucasnum(10) == 123
20+
@test lucasnum(100) == parse(BigInt,"792070839848372253127")
21+
22+
# stirlings1
23+
@test sum([abs(stirlings1(8, i)) for i = 0:8]) == factorial(8)
24+
25+
# bell
26+
@test bellnum(7) == 877
27+
@test bellnum(42) == parse(BigInt,"35742549198872617291353508656626642567")
28+
@test_throws DomainError bellnum(-1)
29+
30+

test/partitions.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Combinatorics
2+
using Base.Test
3+
4+
@test collect(partitions(4)) == Any[[4], [3,1], [2,2], [2,1,1], [1,1,1,1]]
5+
@test collect(partitions(8,3)) == Any[[6,1,1], [5,2,1], [4,3,1], [4,2,2], [3,3,2]]
6+
@test collect(partitions(8, 1)) == Any[[8]]
7+
@test collect(partitions(8, 9)) == []
8+
@test collect(partitions([1,2,3])) == Any[Any[[1,2,3]], Any[[1,2],[3]], Any[[1,3],[2]], Any[[1],[2,3]], Any[[1],[2],[3]]]
9+
@test collect(partitions([1,2,3,4],3)) == Any[Any[[1,2],[3],[4]], Any[[1,3],[2],[4]], Any[[1],[2,3],[4]],
10+
Any[[1,4],[2],[3]], Any[[1],[2,4],[3]], Any[[1],[2],[3,4]]]
11+
@test collect(partitions([1,2,3,4],1)) == Any[Any[[1, 2, 3, 4]]]
12+
@test collect(partitions([1,2,3,4],5)) == []
13+
14+
@test length(partitions(0)) == 1
15+
@test length(partitions(-1)) == 0
16+
@test length(collect(partitions(30))) == length(partitions(30))
17+
@test length(collect(partitions(90,4))) == length(partitions(90,4))
18+
@test length(collect(partitions('a':'h'))) == length(partitions('a':'h'))
19+
@test length(collect(partitions('a':'h',5))) == length(partitions('a':'h',5))
20+
21+
# integer_partitions
22+
@test integer_partitions(5) == Any[[1, 1, 1, 1, 1], [2, 1, 1, 1], [2, 2, 1], [3, 1, 1], [3, 2], [4, 1], [5]]
23+
@test_throws DomainError integer_partitions(-1)

test/permutations.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Combinatorics
2+
using Base.Test
3+
4+
import Combinatorics: invperm, ipermute!, isperm, levicivita, nthperm, nthperm!, parity, permutations, permute!
5+
6+
p = shuffle([1:1000;])
7+
@test isperm(p)
8+
@test all(invperm(invperm(p)) .== p)
9+
10+
push!(p, 1)
11+
@test !isperm(p)
12+
13+
a = randcycle(10)
14+
@test ipermute!(permute!([1:10;], a),a) == [1:10;]
15+
16+
# PR 12785
17+
let a = 2:-1:1
18+
@test ipermute!(permute!([1, 2], a), a) == [1, 2]
19+
end
20+
21+
@test collect(permutations("abc")) == Any[['a','b','c'],['a','c','b'],['b','a','c'],
22+
['b','c','a'],['c','a','b'],['c','b','a']]
23+
24+
@test collect(filter(x->(iseven(x[1])),permutations([1,2,3]))) == Any[[2,1,3],[2,3,1]]
25+
@test collect(filter(x->(iseven(x[3])),permutations([1,2,3]))) == Any[[1,3,2],[3,1,2]]
26+
27+
@test length(permutations(0)) == 1
28+
29+
for n = 0:7, k = 1:factorial(n)
30+
p = nthperm!([1:n;], k)
31+
@test isperm(p)
32+
@test nthperm(p) == k
33+
end
34+
35+
@test_throws ArgumentError parity([0])
36+
@test_throws ArgumentError parity([1,2,3,3])
37+
@test levicivita([1,1,2,3]) == 0
38+
@test levicivita([1]) == 1 && parity([1]) == 0
39+
@test map(levicivita, collect(permutations([1,2,3]))) == [1, -1, -1, 1, 1, -1]
40+
@test let p = [3, 4, 6, 10, 5, 2, 1, 7, 8, 9]; levicivita(p) == 1 && parity(p) == 0; end
41+
@test let p = [4, 3, 6, 10, 5, 2, 1, 7, 8, 9]; levicivita(p) == -1 && parity(p) == 1; end
42+
43+
@test Combinatorics.nsetpartitions(-1) == 0
44+
@test collect(permutations([])) == Vector[[]]
45+

test/runtests.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using Combinatorics
22
using Base.Test
33

4-
include("basic.jl")
5-
include("frombase.jl")
4+
include("numbers.jl")
5+
include("factorials.jl")
6+
include("combinations.jl")
7+
include("permutations.jl")
8+
include("partitions.jl")
69
include("youngdiagrams.jl")
710

0 commit comments

Comments
 (0)