1# 2# math.test 3# 4# Tests for the random, min, and commands. 5#--------------------------------------------------------------------------- 6# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans. 7# 8# Permission to use, copy, modify, and distribute this software and its 9# documentation for any purpose and without fee is hereby granted, provided 10# that the above copyright notice appear in all copies. Karl Lehenbauer and 11# Mark Diekhans make no representations about the suitability of this 12# software for any purpose. It is provided "as is" without express or 13# implied warranty. 14#------------------------------------------------------------------------------ 15# $Id: math.test,v 1.2 2002/04/02 02:29:43 hobbs Exp $ 16#------------------------------------------------------------------------------ 17# 18 19if {[cequal [info procs Test] {}]} { 20 source [file join [file dirname [info script]] testlib.tcl] 21} 22 23random seed 100 24 25for {set i 0} {$i < 100} {set i [expr $i+1]} { 26 Test math-1.1.$i {random tests} { 27 set a [random 10] 28 expr "(($a >= 0) || ($a <= 9))" 29 } 0 1 30} 31 32Test math-1.2 {random tests} { 33 random 34} 1 {wrong # args: random limit | seed ?seedval?} 35 36Test math-1.3 {random tests} { 37 # Max range varies on some machines, so don't validate that part of 38 # the message. 39 list [catch {random 0} msg] [lrange $msg 0 6] 40} 0 {1 {range must be > 0 and <=}} 41 42Test math-1.4 {random tests} { 43 random seed Foo 44} 1 {expected integer but got "Foo"} 45 46Test math-2.1 {max tests} { 47 max 1 2 4 3 48} 0 4 49 50Test math-2.2 {max tests} { 51 max -68 65537.4 2 5 52} 0 65537.4 53 54Test math-2.3 {max tests} { 55 max -68.7 2100000000 2 5 56} 0 2100000000 57 58Test math-2.4 {max tests} { 59 max -68.7 -2 60} 0 -2 61 62Test math-2.4.1 {max tests} { 63 max -68.7 64} 0 -68.7 65 66Test math-2.4.2 {max tests} { 67 max -68.7 0x200 010 68} 0 0x200 69 70Test math-2.4.3 {max tests} { 71 max 668e7 0x200 010 72} 0 668e7 73 74Test math-2.5 {max tests} { 75 max 76} 1 {wrong # args: max num1 ?..numN?} 77 78Test math-2.6 {max tests} { 79 max 1 2 3 foo 80} 1 {expected floating-point number but got "foo"} 81 82Test math-3.1 {min tests} { 83 min 1 2 4 3 84} 0 1 85 86Test math-3.2 {min tests} { 87 min -68.8 64000 2 5 88} 0 -68.8 89 90Test math-3.3 {min tests} { 91 min -2000000000 2000000000 2 5 92} 0 -2000000000 93 94Test math-3.3 {min tests} { 95 min 5 96} 0 5 97 98Test math-3.3.1 {min tests} { 99 min 5 0x200 010 100} 0 5 101 102Test math-3.3.2 {min tests} { 103 min 5e10 0x200 010 104} 0 010 105 106Test math-3.4 {min tests} { 107 min 108} 1 {wrong # args: min num1 ?..numN?} 109 110Test math-3.5 {min tests} { 111 min 1 2 3 foo 112} 1 {expected floating-point number but got "foo"} 113 114 115Test math-4.1 {max function tests} { 116 expr max(1, 4) 117} 0 4 118 119Test math-4.2 {max function tests} { 120 format %.1f [expr max(-68, 65537.4)] 121} 0 65537.4 122 123Test math-4.3 {max function tests} { 124 format %.1f [expr max(-68.7, 210000)] 125} 0 210000.0 126 127Test math-4.4 {max function tests} { 128 format %.1f [expr max(-68.7, -2)] 129} 0 -2.0 130 131Test math-5.1 {min function tests} { 132 expr min(1, 4) 133} 0 1 134 135Test math-5.2 {min function tests} { 136 format %.1f [expr min(-68, 65537.4)] 137} 0 -68.0 138 139Test math-5.3 {min function tests} { 140 format %.1f [expr min(-68.7, 2100000000)] 141} 0 -68.7 142 143Test math-5.4 {min function tests} { 144 format %.1f [expr min(-68.7, -2)] 145} 0 -68.7 146 147# cleanup 148::tcltest::cleanupTests 149return 150