File: math.test

package info (click to toggle)
tclx8.4 8.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,800 kB
  • sloc: ansic: 14,863; tcl: 2,090; sh: 265; makefile: 159
file content (149 lines) | stat: -rw-r--r-- 3,311 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#
# 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