home *** CD-ROM | disk | FTP | other *** search
- #
- # bsearch.test
- #
- # Tests for the bsearch command.
- #---------------------------------------------------------------------------
- # Copyright 1992 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: bsearch.test,v 2.0 1992/10/16 04:49:24 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] != "test"} then {source testlib.tcl}
-
- # Create a test file
-
- catch {unlink {BSEARCH.TMP}}
-
- set testFH [open BSEARCH.TMP w]
- for {set cnt 0} {$cnt < 100} {incr cnt} {
- puts $testFH [GenRec $cnt]
- }
- close $testFH
-
- # Test bsearch
-
- proc BsearchTestCmp {key line} {
- set linekey [lindex $line 2]
- return [string compare $key $linekey]
- }
-
- set testFH [open BSEARCH.TMP r]
- set toggle 0
- for {set cnt 0} {$cnt < 100} {incr cnt} {
- set key1 [format "Key:%04d" $cnt]
- set key2 [format "KeyX:%04d" $cnt]
- if {($cnt % 6) == 0} {
- set expect [GenRec $cnt]
- if {$toggle} {
- Test bsearch-1.1 {bsearch tests} {
- bsearch $testFH $key1
- } 0 $expect
- Test bsearch-1.2 {bsearch tests} {
- bsearch $testFH $key2 {} BsearchTestCmp
- } 0 $expect
- } else {
- set rec {}
- Test bsearch-1.3 {bsearch tests} {
- list [bsearch $testFH $key1 rec] $rec
- } 0 [list 1 $expect]
- set rec {}
- Test bsearch-1.4 {bsearch tests} {
- list [bsearch $testFH $key2 rec BsearchTestCmp] $rec
- } 0 [list 1 $expect]
- }
- set toggle [expr !$toggle]
- }
- }
- close $testFH
-
- catch {unlink {BSEARCH.TMP}}
-
-