-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Functions from src/foo.jl are now tested in test/foo.jl
- Loading branch information
Showing
8 changed files
with
143 additions
and
124 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[[]] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
|