~ubuntu-branches/ubuntu/wily/julia/wily

« back to all changes in this revision

Viewing changes to test/numbers.jl

  • Committer: Package Import Robot
  • Author(s): Sébastien Villemot
  • Date: 2013-11-17 19:32:52 UTC
  • mfrom: (1.1.12)
  • Revision ID: package-import@ubuntu.com-20131117193252-tkrpclguqqebqa35
Tags: 0.2.0+dfsg-3
testsuite-i386.patch: loosen the numerical precision for yet another test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
752
752
@test Complex(1,2) + 1//2 == Complex(3//2,2//1)
753
753
@test Complex(1,2) + 1//2 * 0.5 == Complex(1.25,2.0)
754
754
@test (Complex(1,2) + 1//2) * 0.5 == Complex(0.75,1.0)
755
 
@test (Complex(1,2)/Complex(2.5,3.0))*Complex(2.5,3.0) == Complex(1,2)
 
755
@test_approx_eq (Complex(1,2)/Complex(2.5,3.0))*Complex(2.5,3.0) Complex(1,2)
756
756
@test 0.7 < real(sqrt(Complex(0,1))) < 0.707107
757
757
 
758
758
for T in {Int8,Int16,Int32,Int64,Int128}
1511
1511
# overflow in rational comparison
1512
1512
@test 3//2 < typemax(Int)
1513
1513
@test 3//2 <= typemax(Int)
 
1514
 
 
1515
# check gcd and related functions against GMP
 
1516
for i = -20:20, j = -20:20
 
1517
    local d = gcd(i,j)
 
1518
    @test d >= 0
 
1519
    @test lcm(i,j) >= 0
 
1520
    local ib = big(i)
 
1521
    local jb = big(j)
 
1522
    @test d == gcd(ib,jb)
 
1523
    @test lcm(i,j) == lcm(ib,jb)
 
1524
    @test gcdx(i,j) == gcdx(ib,jb)
 
1525
    if j == 0
 
1526
        @test_throws invmod(i,j)
 
1527
        @test_throws invmod(ib,jb)
 
1528
    elseif d == 1
 
1529
        n = invmod(i,j)
 
1530
        @test n == invmod(ib,jb)
 
1531
        @test mod(n*i,j) == mod(1,j)
 
1532
    end
 
1533
end
 
1534
 
 
1535
# check powermod function against GMP
 
1536
for i = -10:10, p = 0:5, m = -10:10
 
1537
    if m != 0
 
1538
        @test powermod(i,p,m) == powermod(i,p,big(m)) == powermod(big(i),big(p),big(m))
 
1539
        @test mod(i^p,m) == powermod(i,p,m) == mod(big(i)^p,big(m))
 
1540
    end
 
1541
end
 
1542
 
 
1543
# with m==1 should give 0
 
1544
@test powermod(1,0,1) == 0
 
1545
@test powermod(big(1),0,1) == 0
 
1546
@test powermod(1,0,-1) == 0
 
1547
@test powermod(big(1),0,-1) == 0
 
1548
# divide by zero error
 
1549
@test_throws powermod(1,0,0)
 
1550
@test_throws powermod(big(1),0,0)
 
1551
# negative power domain error
 
1552
@test_throws powermod(1,-2,1)
 
1553
@test_throws powermod(big(1),-2,1)
 
1554
 
 
1555
# prevpow2/nextpow2:
 
1556
@test nextpow2(0) == prevpow2(0) == 0
 
1557
for i = -2:2
 
1558
    @test nextpow2(i) == prevpow2(i) == i
 
1559
end
 
1560
@test nextpow2(56789) == -nextpow2(-56789) == 65536
 
1561
@test prevpow2(56789) == -prevpow2(-56789) == 32768
 
1562
for i = -100:100
 
1563
    @test nextpow2(i) == nextpow2(big(i))
 
1564
    @test prevpow2(i) == prevpow2(big(i))
 
1565
end