#
|
#
|
# Old test suite for [incr Tcl] v1.5
|
# Old test suite for [incr Tcl] v1.5
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# AUTHOR: Michael J. McLennan
|
# AUTHOR: Michael J. McLennan
|
# Bell Labs Innovations for Lucent Technologies
|
# Bell Labs Innovations for Lucent Technologies
|
# mmclennan@lucent.com
|
# mmclennan@lucent.com
|
# http://www.tcltk.com/itcl
|
# http://www.tcltk.com/itcl
|
#
|
#
|
# RCS: $Id: testlib.tcl,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
|
# RCS: $Id: testlib.tcl,v 1.1.1.1 2002-01-16 10:24:47 markom Exp $
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
# Copyright (c) 1993-1998 Lucent Technologies, Inc.
|
# ======================================================================
|
# ======================================================================
|
# See the file "license.terms" for information on usage and
|
# See the file "license.terms" for information on usage and
|
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
# redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# USAGE: test <test-desc> <test-cmd> <check>
|
# USAGE: test <test-desc> <test-cmd> <check>
|
#
|
#
|
# Executes the given test, the evaluates the <check> condition to
|
# Executes the given test, the evaluates the <check> condition to
|
# see if the test passed. The result from the <test-cmd> is kept
|
# see if the test passed. The result from the <test-cmd> is kept
|
# in the variable $result. If this condition evaluates non-zero,
|
# in the variable $result. If this condition evaluates non-zero,
|
# the test has passed. Otherwise, the test has failed. A variety
|
# the test has passed. Otherwise, the test has failed. A variety
|
# if checking routines (test_cmp_*) are provided below to make
|
# if checking routines (test_cmp_*) are provided below to make
|
# the check condition easier to write.
|
# the check condition easier to write.
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
proc test {desc cmd check} {
|
proc test {desc cmd check} {
|
set result [uplevel $cmd]
|
set result [uplevel $cmd]
|
|
|
if {![expr $check]} {
|
if {![expr $check]} {
|
puts stdout "-------------------------------------------------------"
|
puts stdout "-------------------------------------------------------"
|
puts stdout ">>>> FAILED TEST <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
|
puts stdout ">>>> FAILED TEST <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
|
puts stdout "-------------------------------------------------------"
|
puts stdout "-------------------------------------------------------"
|
set lines [split $desc "\n"]
|
set lines [split $desc "\n"]
|
foreach i $lines {
|
foreach i $lines {
|
puts stdout $i
|
puts stdout $i
|
}
|
}
|
puts stdout "======================================================="
|
puts stdout "======================================================="
|
set lines [split $cmd "\n"]
|
set lines [split $cmd "\n"]
|
set label TEST
|
set label TEST
|
foreach i $lines {
|
foreach i $lines {
|
puts stdout " $label | $i"
|
puts stdout " $label | $i"
|
set label " "
|
set label " "
|
}
|
}
|
puts stdout "-------------------------------------------------------"
|
puts stdout "-------------------------------------------------------"
|
set lines [split $check "\n"]
|
set lines [split $check "\n"]
|
set label CHECK
|
set label CHECK
|
foreach i $lines {
|
foreach i $lines {
|
if {$i != ""} {
|
if {$i != ""} {
|
puts stdout " $label | $i"
|
puts stdout " $label | $i"
|
set label " "
|
set label " "
|
}
|
}
|
}
|
}
|
puts stdout "-------------------------------------------------------"
|
puts stdout "-------------------------------------------------------"
|
set lines [split $result "\n"]
|
set lines [split $result "\n"]
|
set label RESULT
|
set label RESULT
|
foreach i $lines {
|
foreach i $lines {
|
if {$i != ""} {
|
if {$i != ""} {
|
puts stdout " $label | \$result => $i"
|
puts stdout " $label | \$result => $i"
|
set label " "
|
set label " "
|
}
|
}
|
}
|
}
|
puts stdout "======================================================="
|
puts stdout "======================================================="
|
error "tests aborted"
|
error "tests aborted"
|
}
|
}
|
}
|
}
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# USAGE: test_cmp_nums <num1> <num2>
|
# USAGE: test_cmp_nums <num1> <num2>
|
#
|
#
|
# Compares two numbers to see if they are "equal." Numbers are
|
# Compares two numbers to see if they are "equal." Numbers are
|
# "equal" if they have an absolute value greater than 1.0e-6 and they
|
# "equal" if they have an absolute value greater than 1.0e-6 and they
|
# have at least 5 significant figures. Returns 1/0 for true/false.
|
# have at least 5 significant figures. Returns 1/0 for true/false.
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
proc test_cmp_nums {num1 num2} {
|
proc test_cmp_nums {num1 num2} {
|
global TEST_ABS_TOL TEST_REL_TOL
|
global TEST_ABS_TOL TEST_REL_TOL
|
|
|
if {[expr abs($num1)] > $TEST_ABS_TOL &&
|
if {[expr abs($num1)] > $TEST_ABS_TOL &&
|
[expr abs($num2)] > $TEST_ABS_TOL} {
|
[expr abs($num2)] > $TEST_ABS_TOL} {
|
set avg [expr 0.5*($num1+$num2)]
|
set avg [expr 0.5*($num1+$num2)]
|
set diff [expr abs(($num1-$num2)/$avg)]
|
set diff [expr abs(($num1-$num2)/$avg)]
|
|
|
if {$diff > $TEST_REL_TOL} {
|
if {$diff > $TEST_REL_TOL} {
|
return 0
|
return 0
|
}
|
}
|
}
|
}
|
return 1
|
return 1
|
}
|
}
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# USAGE: test_cmp_vectors <list1> <list2>
|
# USAGE: test_cmp_vectors <list1> <list2>
|
#
|
#
|
# Compares two lists of numbers to see if they are "equal." Vectors
|
# Compares two lists of numbers to see if they are "equal." Vectors
|
# are "equal" if elements are "equal" in the numeric sense.
|
# are "equal" if elements are "equal" in the numeric sense.
|
# Returns 1/0 for true/false.
|
# Returns 1/0 for true/false.
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
proc test_cmp_vectors {list1 list2} {
|
proc test_cmp_vectors {list1 list2} {
|
if {[llength $list1] != [llength $list2]} {
|
if {[llength $list1] != [llength $list2]} {
|
return 0
|
return 0
|
}
|
}
|
for {set i 0} {$i < [llength $list1]} {incr i} {
|
for {set i 0} {$i < [llength $list1]} {incr i} {
|
set n1 [lindex $list1 $i]
|
set n1 [lindex $list1 $i]
|
set n2 [lindex $list2 $i]
|
set n2 [lindex $list2 $i]
|
|
|
if {![test_cmp_nums $n1 $n2]} {
|
if {![test_cmp_nums $n1 $n2]} {
|
return 0
|
return 0
|
}
|
}
|
}
|
}
|
return 1
|
return 1
|
}
|
}
|
|
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
# USAGE: test_cmp_lists <list1> <list2>
|
# USAGE: test_cmp_lists <list1> <list2>
|
#
|
#
|
# Compares two lists to see if they are "equal." Lists are "equal"
|
# Compares two lists to see if they are "equal." Lists are "equal"
|
# if they contain exactly the same elements, but perhaps in a
|
# if they contain exactly the same elements, but perhaps in a
|
# different order. Returns 1/0 for true/false.
|
# different order. Returns 1/0 for true/false.
|
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
proc test_cmp_lists {list1 list2} {
|
proc test_cmp_lists {list1 list2} {
|
if {[llength $list1] != [llength $list2]} {
|
if {[llength $list1] != [llength $list2]} {
|
return 0
|
return 0
|
}
|
}
|
foreach elem $list1 {
|
foreach elem $list1 {
|
set i [lsearch $list2 $elem]
|
set i [lsearch $list2 $elem]
|
if {$i >= 0} {
|
if {$i >= 0} {
|
set list2 [lreplace $list2 $i $i]
|
set list2 [lreplace $list2 $i $i]
|
} else {
|
} else {
|
return 0
|
return 0
|
}
|
}
|
}
|
}
|
return 1
|
return 1
|
}
|
}
|
|
|