#
# math.test
#
# Tests for the random, min, and commands.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies.  Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose.  It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: math.test,v 1.2 2002/04/02 02:29:43 hobbs Exp $
#------------------------------------------------------------------------------
#

if {[cequal [info procs Test] {}]} {
    source [file join [file dirname [info script]] testlib.tcl]
}

random seed 100

for {set i 0} {$i < 100} {set i [expr $i+1]} {
    Test math-1.1.$i {random tests} {
        set a [random 10]
        expr "(($a >= 0) || ($a <= 9))"
    } 0 1
}

Test math-1.2 {random tests} {
    random
} 1 {wrong # args: random limit | seed ?seedval?}

Test math-1.3 {random tests} {
    # Max range varies on some machines, so don't validate that part of
    # the message.
    list [catch {random 0} msg] [lrange $msg 0 6]
} 0 {1 {range must be > 0 and <=}}

Test math-1.4 {random tests} {
    random seed Foo
} 1 {expected integer but got "Foo"}

Test math-2.1 {max tests} {
    max 1 2 4 3
} 0 4

Test math-2.2 {max tests} {
    max -68 65537.4 2 5
} 0 65537.4

Test math-2.3 {max tests} {
    max -68.7 2100000000 2 5
} 0 2100000000

Test math-2.4 {max tests} {
    max -68.7 -2
} 0 -2

Test math-2.4.1 {max tests} {
    max -68.7
} 0 -68.7

Test math-2.4.2 {max tests} {
    max -68.7 0x200 010
} 0 0x200

Test math-2.4.3 {max tests} {
    max 668e7 0x200 010
} 0 668e7

Test math-2.5 {max tests} {
    max
} 1 {wrong # args: max num1 ?..numN?}

Test math-2.6 {max tests} {
    max 1 2 3 foo
} 1 {expected floating-point number but got "foo"}

Test math-3.1 {min tests} {
    min 1 2 4 3
} 0 1

Test math-3.2 {min tests} {
    min -68.8 64000 2 5
} 0 -68.8

Test math-3.3 {min tests} {
    min -2000000000 2000000000 2 5
} 0 -2000000000

Test math-3.3 {min tests} {
    min 5
} 0 5

Test math-3.3.1 {min tests} {
    min 5 0x200 010
} 0 5

Test math-3.3.2 {min tests} {
    min 5e10 0x200 010
} 0 010

Test math-3.4 {min tests} {
    min
} 1 {wrong # args: min num1 ?..numN?}

Test math-3.5 {min tests} {
    min 1 2 3 foo
} 1 {expected floating-point number but got "foo"}


Test math-4.1 {max function tests} {
    expr max(1, 4)
} 0 4

Test math-4.2 {max function tests} {
    format %.1f [expr max(-68, 65537.4)]
} 0 65537.4

Test math-4.3 {max function tests} {
    format %.1f [expr max(-68.7, 210000)]
} 0 210000.0

Test math-4.4 {max function tests} {
    format %.1f [expr max(-68.7, -2)]
} 0 -2.0

Test math-5.1 {min function tests} {
    expr min(1, 4)
} 0 1

Test math-5.2 {min function tests} {
    format %.1f [expr min(-68, 65537.4)]
} 0 -68.0

Test math-5.3 {min function tests} {
    format %.1f [expr min(-68.7, 2100000000)]
} 0 -68.7

Test math-5.4 {min function tests} {
    format %.1f [expr min(-68.7, -2)]
} 0 -68.7

# cleanup
::tcltest::cleanupTests
return
