-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Some test coverage (combinatorics and intfuncs) #9620
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
@test factorial(7) == 5040 | ||
@test factorial(7,3) == 7*6*5*4 | ||
@test binomial(5,-1) == 0 | ||
@test binomial(5,10) == 0 | ||
@test binomial(5,3) == 10 | ||
@test binomial(2,1) == 2 | ||
@test binomial(1,2) == 0 | ||
@test binomial(-2,1) == -2 | ||
@test binomial(2,-1) == 0 | ||
|
||
#Issue 6154 | ||
@test binomial(int32(34), int32(15)) == binomial(BigInt(34), BigInt(15)) == 1855967520 | ||
@test binomial(int64(67), int64(29)) == binomial(BigInt(67), BigInt(29)) == 7886597962249166160 | ||
@test binomial(int128(131), int128(62)) == binomial(BigInt(131), BigInt(62)) == 157311720980559117816198361912717812000 | ||
@test_throws InexactError binomial(int64(67), int64(30)) | ||
|
||
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] | ||
|
||
@test collect(combinations("abc",3)) == ["abc"] | ||
@test collect(combinations("abc",2)) == ["ab","ac","bc"] | ||
@test collect(combinations("abc",1)) == ["a","b","c"] | ||
@test collect(combinations("abc",0)) == [""] | ||
@test collect(permutations("abc")) == ["abc","acb","bac","bca","cab","cba"] | ||
|
||
@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 collect(filter(x->(iseven(x[1])),combinations([1,2,3],2))) == Any[[2,3]] | ||
|
||
@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]] | ||
|
@@ -36,18 +53,16 @@ for n = 0:7, k = 1:factorial(n) | |
@test nthperm(p) == k | ||
end | ||
|
||
#Issue 6154 | ||
@test binomial(int32(34), int32(15)) == binomial(BigInt(34), BigInt(15)) == 1855967520 | ||
@test binomial(int64(67), int64(29)) == binomial(BigInt(67), BigInt(29)) == 7886597962249166160 | ||
@test binomial(int128(131), int128(62)) == binomial(BigInt(131), BigInt(62)) == 157311720980559117816198361912717812000 | ||
|
||
# issue #6579 | ||
@test factorial(7) == 5040 | ||
@test factorial(7,3) == 7*6*5*4 | ||
@test factorial(0) == 1 | ||
@test_throws DomainError factorial(-1) | ||
|
||
@test factorial(int64(20)) == 2432902008176640000 | ||
# issue #6579 | ||
@test_throws OverflowError factorial(int64(21)) | ||
@test_throws DomainError factorial(-1) | ||
@test typeof(factorial(int8(2))) == typeof(factorial(int8(1))) | ||
if Int === Int32 | ||
@test factorial(int32(12)) === int32(479001600) | ||
@test_throws OverflowError factorial(int32(13)) | ||
@test factorial(int32(12)) === int32(479001600) | ||
@test_throws OverflowError factorial(int32(13)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whitespace here and above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is indented since it's inside an if block. ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, didn't notice the |
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this makes sense, but I found it surprising. Add a comment to make sure someone doesn't delete it out of puzzlement later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was adding some edge cases this seems to agree with Wolfram Alpha!