#
# bsearch.test
#
# Tests for the bsearch command.
#---------------------------------------------------------------------------
# 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: bsearch.test,v 1.1.1.1 1999/06/28 20:35:24 damon Exp $
#------------------------------------------------------------------------------
#

if [cequal [info procs Test] {}] {source testlib.tcl}

# Create a test file

TestRemove 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.$cnt {bsearch tests} {
                bsearch $testFH $key1
            } 0 $expect
            Test bsearch-1.2.$cnt {bsearch tests} {
                bsearch $testFH $key2 {} BsearchTestCmp
            } 0 $expect
        } else {
            set rec {}
            Test bsearch-1.3.$cnt {bsearch tests} {
                 list [bsearch $testFH $key1 rec] $rec
            } 0 [list 1 $expect]
            set rec {}
            Test bsearch-1.4.$cnt {bsearch tests} {
                 list [bsearch $testFH $key2 rec BsearchTestCmp] $rec
            } 0 [list 1 $expect]
        }
        set toggle [expr !$toggle]
    }
}
close $testFH

TestRemove BSEARCH.TMP




