Skip to content

Commit

Permalink
TST intfuncs more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hayd committed Jan 5, 2015
1 parent ff0470c commit 3d376d1
Showing 1 changed file with 72 additions and 1 deletion.
73 changes: 72 additions & 1 deletion test/intfuncs.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
# issue #8266
@test gcd(3, 5) == 1
@test gcd(3, 15) == 3
@test gcd(0, 15) == 15
@test gcd(3, -15) == 3
@test gcd(-3, -15) == 3
@test gcd(0, 0) == 0

@test gcd(2, 4, 6) == 2

@test typeof(gcd(int32(3), int32(15))) == Int32

@test lcm(2, 3) == 6
@test lcm(4, 6) == 12
@test lcm(3, 0) == 0
@test lcm(0, 0) == 0
@test lcm(4, -6) == 12
@test lcm(-4, -6) == 12

@test lcm(2, 4, 6) == 12

@test typeof(lcm(int32(2), int32(3))) == Int32

@test gcdx(5, 12) == (1, 5, -2)
@test gcdx(5, -12) == (1, 5, 2)
@test gcdx(-25, -4) == (1, -1, 6)

@test invmod(6, 31) == 26
@test invmod(-1, 3) == 2
@test invmod(-1, -3) == 2
@test_throws ErrorException invmod(0, 3)

@test powermod(2, 3, 5) == 3
@test powermod(2, 3, -5) == -2
@test_throws DomainError powermod(2, -3, 5)

@test nextpow2(3) == 4
@test nextpow(2, 3) == 4
@test nextpow(2, 4) == 4
@test nextpow(2, 7) == 8
@test_throws DomainError nextpow(0, 3)
@test_throws DomainError nextpow(3, 0)

@test prevpow2(3) == 2
@test prevpow(2, 4) == 4
@test prevpow(2, 5) == 4
@test_throws DomainError prevpow(0, 3)
@test_throws DomainError prevpow(0, 3)

# issue #8266
@test ndigits(-15, 10) == 2
@test ndigits(-15, -10) == 2
@test ndigits(-1, 10) == 1
Expand All @@ -14,3 +61,27 @@

@test ndigits(146, -3) == 5

@test bin(3) == "11"
@test bin(3, 2) == "11"
@test bin(3, 3) == "011"
@test bin(-3) == "-11"
@test bin(-3, 3) == "-011"

@test oct(9) == "11"
@test oct(-9) == "-11"

@test dec(121) == "121"

@test hex(12) == "c"
@test hex(-12, 3) == "-00c"
@test num2hex(1243) == "00000000000004db"

@test base(2, 5, 7) == "0000101"

@test bits(1035) == "0000000000000000000000000000000000000000000000000000010000001011"

@test digits(4, 2) == [0, 0, 1]
@test digits(5, 3) == [2, 1]

@test isqrt(4) == 2
@test isqrt(5) == 2

0 comments on commit 3d376d1

Please sign in to comment.