blob: 2fd345925fe3aba4794ae543181ac03dedb871db (
plain)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# -*- tcl -*-
#---------------------------------------------------------------------
# TITLE:
# romannumeral
#
# AUTHOR:
# Kenneth Green, 28 Sep 2005
#
# DESCRIPTION:
# tcltest test cases for romannumeral.tcl
# Note:
# Assumes Tcl 8.3
# The tests assume tcltest 2.2
# -------------------------------------------------------------------------
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.3
testsNeedTcltest 2.2
support {
useLocal math.tcl math
}
testing {
useLocal romannumerals.tcl math::roman
}
#=====================================================================
# S u p p o r t F u n c t i o n s
#=====================================================================
#---------------------------------------------------------------------
# cleanup --
#
# cleanup before each test
#---------------------------------------------------------------------
proc cleanup {} {
global errorInfo
}
#=====================================================================
# I n i t i a l i s a t i o n
#=====================================================================
::tcltest::testConstraint tk [info exists tk_version]
#=====================================================================
# T e s t C a s e s
#=====================================================================
#-----------------------------------------------------------------------
# toroman
test ToRoman-1.1 {good input} -constraints {
} -setup {
cleanup
} -body {
list [catch { list \
[::math::roman::toroman 0] \
[::math::roman::toroman 1] \
[::math::roman::toroman 2] \
[::math::roman::toroman 3] \
[::math::roman::toroman 4] \
[::math::roman::toroman 5] \
[::math::roman::toroman 6] \
[::math::roman::toroman 7] \
[::math::roman::toroman 8] \
[::math::roman::toroman 9] \
[::math::roman::toroman 10] \
[::math::roman::toroman 13] \
[::math::roman::toroman 100] \
[::math::roman::toroman 250] \
[::math::roman::toroman 333] \
[::math::roman::toroman 1001] \
[::math::roman::toroman 1963] \
} errMsg] [set errMsg]
} -cleanup {
cleanup
} -result {0 {{} I II III IV V VI VII VIII IX X XIII C CCL CCCXXXIII MI MCMLXIII}}
#-----------------------------------------------------------------------
# tointeger
test ToInteger-2.1 {good input} -constraints {
} -setup {
cleanup
} -body {
list [catch { list \
[::math::roman::tointeger ""] \
[::math::roman::tointeger I] \
[::math::roman::tointeger ii] \
[::math::roman::tointeger IiI] \
[::math::roman::tointeger iv] \
[::math::roman::tointeger V] \
[::math::roman::tointeger vI] \
[::math::roman::tointeger vIi] \
[::math::roman::tointeger ViiI] \
[::math::roman::tointeger ix] \
[::math::roman::tointeger X] \
[::math::roman::tointeger XiII] \
[::math::roman::tointeger C] \
[::math::roman::tointeger CCD] \
[::math::roman::tointeger CCCXXXIII] \
[::math::roman::tointeger MI] \
[::math::roman::tointeger MCMXXXVI] \
} errMsg] [set errMsg]
} -cleanup {
cleanup
} -result {0 {0 1 2 3 4 5 6 7 8 9 10 13 100 500 333 1001 1936}}
#-----------------------------------------------------------------------
# combined
test Combined-3.1 {good input} -constraints {
} -setup {
cleanup
} -body {
list [catch {
for { set i 0 } { $i < 11666 } { incr i } {
set r [::math::roman::toroman $i]
set j [::math::roman::tointeger $r]
if { $i != $j } {
error "Mismatch i ($i) -> r ($r) -> j ($j)"
}
}
} errMsg] [set errMsg]
} -cleanup {
cleanup
} -result {0 {}}
#-----------------------------------------------------------------------
# sort
test Sort-4.1 {good input} -constraints {
} -setup {
cleanup
} -body {
list [catch {
set l {X III IV I V}
::math::roman::sort $l \
} errMsg] [set errMsg]
} -cleanup {
cleanup
} -result {0 {I III IV V X}}
#-----------------------------------------------------------------------
# expr
test Expr-5.1 {plus} -constraints {
} -setup {
cleanup
} -body {
list [catch {
set x 23
set xr [::math::roman::toroman $x]
set y 77
set yr [::math::roman::toroman $y]
set xr+yr [::math::roman::expr $xr + $yr]
expr [::math::roman::tointeger ${xr+yr}] == [expr $x + $y]
} errMsg] [set errMsg]
} -cleanup {
cleanup
} -result {0 1}
test Expr-5.2 {minus} -constraints {
} -setup {
cleanup
} -body {
list [catch {
set x 23
set xr [::math::roman::toroman $x]
set y 77
set yr [::math::roman::toroman $y]
set yr-xr [::math::roman::expr $yr - $xr]
expr [::math::roman::tointeger ${yr-xr}] == [expr $y - $x]
} errMsg] [set errMsg]
} -cleanup {
cleanup
} -result {0 1}
test Expr-5.3 {times} -constraints {
} -setup {
cleanup
} -body {
list [catch {
set x 23
set xr [::math::roman::toroman $x]
set y 77
set yr [::math::roman::toroman $y]
set xr*yr [::math::roman::expr $xr * $yr]
expr $x * $y
expr [::math::roman::tointeger ${xr*yr}] == [expr $x * $y]
} errMsg] [set errMsg]
} -cleanup {
cleanup
} -result {0 1}
test Expr-5.4 {divide} -constraints {
} -setup {
cleanup
} -body {
list [catch {
set x 23
set xr [::math::roman::toroman $x]
set y 77
set yr [::math::roman::toroman $y]
set yr/xr [::math::roman::expr $yr / $xr]
expr [::math::roman::tointeger ${yr/xr}] == [expr $y / $x]
} errMsg] [set errMsg]
} -cleanup {
cleanup
} -result {0 1}
#---------------------------------------------------------------------
# Clean up
cleanup
testsuiteCleanup
|