#!/usr/bin/ruby

assert_eq(      1.0 / 0.0 , Inf)
assert_eq(     -1.0 / 0.0 , -Inf)
assert(      0.0 / 0.0 -> is_nan)
assert_eq(          - 0.0 , 0)          # should be -0.0
assert_eq(        Inf + 1 , Inf)
assert_eq(        5 - Inf , -Inf)
assert_eq(        Inf * 5 , Inf)
assert_eq(        Inf / 5 , Inf)
assert(        Inf * 0 -> is_nan)
assert_eq(      1.0 / Inf , 0)
assert_eq(     -1.0 / Inf , 0)          # should be -0.0
assert_eq(   -Inf == -1/0 , true)
assert(      -Inf * 0  -> is_nan)
assert(       0 * -Inf -> is_nan)
assert(       0 * 1/0  -> is_nan)
assert_eq(     0/0 == 0/0 , false)
assert_eq(      Inf + Inf , Inf)
assert(      Inf - Inf -> is_nan)
assert_eq(      Inf * Inf , Inf)
assert(      Inf / Inf -> is_nan)
assert(      Inf * 0.0 -> is_nan)
assert_eq(        0 < Inf , true)
assert_eq(     Inf == Inf , true)
assert_eq(   -Inf == -Inf , true)
assert_eq(   -Inf <=> Inf , -1)
assert_eq(   Inf <=> -Inf ,  1)
assert_eq(    Inf <=> Inf ,  0)
assert_eq(  -Inf <=> -Inf ,  0)
assert_eq(     0 <=> -Inf ,  1)
assert(        NaN + 1 -> is_nan)
assert(        NaN * 5 -> is_nan)
assert(      NaN - NaN -> is_nan)
assert(      NaN * Inf -> is_nan)
assert(          - NaN -> is_nan)
assert_eq(     NaN == NaN , false)
assert_eq(        NaN > 0 , nil)
assert_eq(        NaN < 0 , nil)
assert_eq(       NaN == 0 , false)
assert_eq(    0.0 == -0.0 , true)

assert_eq(42 <=> 42, 0)
assert_eq(42 <=> 42.rat, 0)
assert_eq(42.rat <=> 42, 0)
assert_eq(42 <=> (41+1), 0)
assert_eq(42 <=> (42-1), 1)
assert_eq(42 <=> (42+1), -1)

assert(!defined(43 <=> NaN))
assert(!defined(NaN <=> 99))
assert(!defined(NaN <=> NaN))

with (NaN) {|x|

    assert(!defined(x <=> x))
    assert(!defined(x <=> 1))
    assert(!defined(x <=> 0))
    assert(!defined(0 <=> x))
    assert(!defined(1 <=> x))

    assert(!(x == x))
    assert(x != x)
    assert(x != 42)
    assert(42 != x)
    assert(!(x == 42))
    assert(!(42 == x))
}

with (Complex(NaN, NaN)) { |x|

    assert(!defined(x <=> x))
    assert(!defined(x <=> 0))
    assert(!defined(1 <=> x))
    assert(!defined(0 <=> x))
    assert(!defined(x <=> Complex(0, 0)))
    assert(!defined(Complex(0, 0) <=> x))

    assert(!(x == x))
    assert(x != x)
    assert(x != 11)
    assert(11 != x)
    assert(!(12 == x))
    assert(!(x == 13))
}

assert(22 == 22)
assert(!(22 != 22))
assert(!(22 == (22+1)))
assert(22 != (22+1))
assert(22 != (22-1))

assert(!(43 == NaN))
assert(!(NaN == NaN))
assert(NaN != NaN)
assert(NaN != 43)
assert(21 != NaN)

assert_eq([0.0], [0])
assert_eq([0_0], [0])
assert_eq([00], [0])
assert_eq([000], [0])
assert_eq([01], [1])
assert_eq([001], [1])

assert_eq(0_, 0)
assert_eq(0x, 0)
assert_eq(0b, 0)
assert_eq(0o, 0)

assert_eq(0b1101, 13)
assert_eq(01234,  668)
assert_eq(0o1234, 668)
assert_eq(0x1234, 4660)

say "** Test passed!";
