# ---------------------------------------------------------------------- # TESTS FOR: Rappture::optimizer # # This file contains a collection of tests for Tcl commands driving # the RapptureOptimizer package. # # ====================================================================== # AUTHOR: Michael McLennan, Purdue University # Copyright (c) 2004-2012 HUBzero Foundation, LLC # # See the file "license.terms" for information on usage and # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. # ====================================================================== # # Load the tcltest package... if {[lsearch [namespace children] ::tcltest] < 0} { package require tcltest 2 namespace import -force ::tcltest::* } test aaa-0.1 {RapptureOptimizer package can be loaded} { set status [catch {package require RapptureOptimizer} result] if {$status != 0} { # must not be installed yet -- use build version lappend auto_path ../src set status [catch {package require RapptureOptimizer} result] } list $status $result } {0 1.0} test aaa-1.1 {create an optimizer object} { list [catch {Rappture::optimizer} result] $result } {0 optimizer0} test aaa-1.2 {create an optimizer object with a given name} { list [catch {Rappture::optimizer foo} result] $result } {0 foo} test aaa-1.3 {can't clobber a name that already exists} { list [catch {Rappture::optimizer set} result] $result } {1 {command "set" already exists}} test aaa-1.4 {optimizer creation takes certain args} { list [catch {Rappture::optimizer -foo} result] $result } {1 {bad option "-foo": should be -tool, -using}} test aaa-1.5 {optimizer creation: -using requires a value} { list [catch {Rappture::optimizer -using} result] $result } {1 {missing value for option "-using"}} test aaa-1.6 {optimizer creation: -using requires particular values} { list [catch {Rappture::optimizer -using foo} result] $result } {1 {bad plugin name "foo": should be pgapack}} test aaa-1.7 {optimizer creation: extra args are processed} { list [catch {Rappture::optimizer -using pgapack -foo bar} result] $result } {1 {bad option "-foo": should be -tool, -using}} test aaa-1.8 {optimizer can be destroyed without dumping core} { rename foo "" rename optimizer0 "" } {} # ---------------------------------------------------------------------- test aaa-2.1 {create an optimizer and add parameters to it} { Rappture::optimizer ctxt ctxt add number input.temperature -min 0 -max 1 ctxt get } {input.temperature number -min 0.0 -max 1.0} test aaa-2.2 {add a parameter with a bad type} { list [catch {ctxt add foo input.wrong -bar test} result] $result } {1 {bad parameter type "foo": should be number, string}} test aaa-2.3 {add a number parameter with a missing option} { list [catch {ctxt add number input.wrong -min} result] $result } {1 {missing value for option "-min"}} test aaa-2.4 {add a number parameter with a bad value} { list [catch {ctxt add number input.wrong -min foo} result] $result } {1 {expected floating-point number but got "foo"}} test aaa-2.5 {add a number parameter with a bad option name} { list [catch {ctxt add number input.wrong -min 0 -foo x} result] $result } {1 {bad option "-foo": should be -min, -max}} test aaa-2.6 {add doesn't add parameter when there's an error} { ctxt get } {input.temperature number -min 0.0 -max 1.0} test aaa-2.7 {add a string parameter} { ctxt add string input.choice -values {a b c} ctxt get input.choice } {string -values {a b c}} test aaa-2.8 {add a string parameter with a missing option} { list [catch {ctxt add string input.wrong -values} result] $result } {1 {missing value for option "-values"}} test aaa-2.9 {add a string parameter with a bad option name} { list [catch {ctxt add string input.wrong -bad 0} result] $result } {1 {bad option "-bad": should be -values}} test aaa-2.10 {add doesn't add parameter when there's an error} { ctxt get } {{input.temperature number -min 0.0 -max 1.0} {input.choice string -values {a b c}}} test aaa-2.11 {add another number and return } { ctxt add number input.temporary -min -5 -max 5 lsort [ctxt get input.temp*] } {{input.temperature number -min 0.0 -max 1.0} {input.temporary number -min -5.0 -max 5.0}} test aaa-2.12 {query -min values for multiple parameters} { lsort [ctxt get input.temp* -min] } {{input.temperature 0.0} {input.temporary -5.0}} # cleanup ::tcltest::cleanupTests return