Skip to content

Commit

Permalink
Reorganize tests
Browse files Browse the repository at this point in the history
Functions from src/foo.jl are now tested in test/foo.jl
  • Loading branch information
jiahao committed Nov 6, 2015
1 parent 9328ef1 commit 78b31c3
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 124 deletions.
55 changes: 0 additions & 55 deletions test/basic.jl

This file was deleted.

17 changes: 17 additions & 0 deletions test/combinations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Combinatorics
using Base.Test

import Combinatorics: combinations


@test collect(combinations([])) == []
@test collect(combinations(['a', 'b', 'c'])) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']]

@test collect(combinations("abc",3)) == Any[['a','b','c']]
@test collect(combinations("abc",2)) == Any[['a','b'],['a','c'],['b','c']]
@test collect(combinations("abc",1)) == Any[['a'],['b'],['c']]
@test collect(combinations("abc",0)) == Any[Char[]]
@test collect(combinations("abc",-1)) == Any[]

@test collect(filter(x->(iseven(x[1])),combinations([1,2,3],2))) == Any[[2,3]]

23 changes: 23 additions & 0 deletions test/factorials.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Combinatorics
using Base.Test

# derangement
@test derangement(4) == 9
@test derangement(24) == parse(BigInt,"228250211305338670494289")

# doublefactorial
@test doublefactorial(70) == parse(BigInt,"355044260642859198243475901411974413130137600000000")

# hyperfactorial
@test hyperfactorial(8) == parse(BigInt,"55696437941726556979200000")

# multifactorial
@test multifactorial(40,2) == doublefactorial(40)

# multinomial
@test multinomial(1,4,4,2) == 34650

# primorial
@test primorial(17) == 510510


67 changes: 0 additions & 67 deletions test/frombase.jl

This file was deleted.

30 changes: 30 additions & 0 deletions test/numbers.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Combinatorics
using Base.Test

# catalan
@test catalannum(5) == 42
@test catalannum(30) == parse(BigInt,"3814986502092304")

# fibonacci
@test fibonaccinum(5) == 5
@test fibonaccinum(101) == parse(BigInt,"573147844013817084101")

# lassalle
@test lassallenum(14) == parse(BigInt,"270316008395632253340")

# legendresymbol
@test legendresymbol(1001,9907) == jacobisymbol(1001,9907) == -1

# lucas
@test lucasnum(10) == 123
@test lucasnum(100) == parse(BigInt,"792070839848372253127")

# stirlings1
@test sum([abs(stirlings1(8, i)) for i = 0:8]) == factorial(8)

# bell
@test bellnum(7) == 877
@test bellnum(42) == parse(BigInt,"35742549198872617291353508656626642567")
@test_throws DomainError bellnum(-1)


23 changes: 23 additions & 0 deletions test/partitions.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Combinatorics
using Base.Test

@test collect(partitions(4)) == Any[[4], [3,1], [2,2], [2,1,1], [1,1,1,1]]
@test collect(partitions(8,3)) == Any[[6,1,1], [5,2,1], [4,3,1], [4,2,2], [3,3,2]]
@test collect(partitions(8, 1)) == Any[[8]]
@test collect(partitions(8, 9)) == []
@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]]]
@test collect(partitions([1,2,3,4],3)) == Any[Any[[1,2],[3],[4]], Any[[1,3],[2],[4]], Any[[1],[2,3],[4]],
Any[[1,4],[2],[3]], Any[[1],[2,4],[3]], Any[[1],[2],[3,4]]]
@test collect(partitions([1,2,3,4],1)) == Any[Any[[1, 2, 3, 4]]]
@test collect(partitions([1,2,3,4],5)) == []

@test length(partitions(0)) == 1
@test length(partitions(-1)) == 0
@test length(collect(partitions(30))) == length(partitions(30))
@test length(collect(partitions(90,4))) == length(partitions(90,4))
@test length(collect(partitions('a':'h'))) == length(partitions('a':'h'))
@test length(collect(partitions('a':'h',5))) == length(partitions('a':'h',5))

# integer_partitions
@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]]
@test_throws DomainError integer_partitions(-1)
45 changes: 45 additions & 0 deletions test/permutations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Combinatorics
using Base.Test

import Combinatorics: invperm, ipermute!, isperm, levicivita, nthperm, nthperm!, parity, permutations, permute!

p = shuffle([1:1000;])
@test isperm(p)
@test all(invperm(invperm(p)) .== p)

push!(p, 1)
@test !isperm(p)

a = randcycle(10)
@test ipermute!(permute!([1:10;], a),a) == [1:10;]

# PR 12785
let a = 2:-1:1
@test ipermute!(permute!([1, 2], a), a) == [1, 2]
end

@test collect(permutations("abc")) == Any[['a','b','c'],['a','c','b'],['b','a','c'],
['b','c','a'],['c','a','b'],['c','b','a']]

@test collect(filter(x->(iseven(x[1])),permutations([1,2,3]))) == Any[[2,1,3],[2,3,1]]
@test collect(filter(x->(iseven(x[3])),permutations([1,2,3]))) == Any[[1,3,2],[3,1,2]]

@test length(permutations(0)) == 1

for n = 0:7, k = 1:factorial(n)
p = nthperm!([1:n;], k)
@test isperm(p)
@test nthperm(p) == k
end

@test_throws ArgumentError parity([0])
@test_throws ArgumentError parity([1,2,3,3])
@test levicivita([1,1,2,3]) == 0
@test levicivita([1]) == 1 && parity([1]) == 0
@test map(levicivita, collect(permutations([1,2,3]))) == [1, -1, -1, 1, 1, -1]
@test let p = [3, 4, 6, 10, 5, 2, 1, 7, 8, 9]; levicivita(p) == 1 && parity(p) == 0; end
@test let p = [4, 3, 6, 10, 5, 2, 1, 7, 8, 9]; levicivita(p) == -1 && parity(p) == 1; end

@test Combinatorics.nsetpartitions(-1) == 0
@test collect(permutations([])) == Vector[[]]

7 changes: 5 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Combinatorics
using Base.Test

include("basic.jl")
include("frombase.jl")
include("numbers.jl")
include("factorials.jl")
include("combinations.jl")
include("permutations.jl")
include("partitions.jl")
include("youngdiagrams.jl")

0 comments on commit 78b31c3

Please sign in to comment.