source: trunk/optimizer/tests/aaa.test @ 898

Last change on this file since 898 was 898, checked in by mmc, 15 years ago

Optimization part is getting better. Fleshed out the plug-in for
PGApack, and integrated a first cut that includes the data handling.

File size: 4.0 KB
Line 
1# ----------------------------------------------------------------------
2#  TESTS FOR:  Rappture::optimizer
3#
4#  This file contains a collection of tests for Tcl commands driving
5#  the RapptureOptimizer package.
6#
7# ======================================================================
8#  AUTHOR:  Michael McLennan, Purdue University
9#  Copyright (c) 2008  Purdue Research Foundation
10#
11#  See the file "license.terms" for information on usage and
12#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13# ======================================================================
14#
15# Load the tcltest package...
16if {[lsearch [namespace children] ::tcltest] < 0} {
17    package require tcltest 2
18    namespace import -force ::tcltest::*
19}
20
21test aaa-0.1 {RapptureOptimizer package can be loaded} {
22    set status [catch {package require RapptureOptimizer} result]
23    if {$status != 0} {
24        # must not be installed yet -- use build version
25        lappend auto_path ../src
26        set status [catch {package require RapptureOptimizer} result]
27    }
28    list $status $result
29} {0 1.0}
30
31test aaa-1.1 {create an optimizer object} {
32  list [catch {Rappture::optimizer} result] $result
33} {0 optimizer0}
34
35test aaa-1.2 {create an optimizer object with a given name} {
36  list [catch {Rappture::optimizer foo} result] $result
37} {0 foo}
38
39test aaa-1.3 {can't clobber a name that already exists} {
40  list [catch {Rappture::optimizer set} result] $result
41} {1 {command "set" already exists}}
42
43test aaa-1.4 {optimizer creation takes certain args} {
44  list [catch {Rappture::optimizer -foo} result] $result
45} {1 {bad option "-foo": should be -tool, -using}}
46
47test aaa-1.5 {optimizer creation: -using requires a value} {
48  list [catch {Rappture::optimizer -using} result] $result
49} {1 {missing value for option "-using"}}
50
51test aaa-1.6 {optimizer creation: -using requires particular values} {
52  list [catch {Rappture::optimizer -using foo} result] $result
53} {1 {bad plugin name "foo": should be pgapack}}
54
55test aaa-1.7 {optimizer creation: extra args are processed} {
56  list [catch {Rappture::optimizer -using pgapack -foo bar} result] $result
57} {1 {bad option "-foo": should be -tool, -using}}
58
59test aaa-1.8 {optimizer can be destroyed without dumping core} {
60  rename foo ""
61  rename optimizer0 ""
62} {}
63
64# ----------------------------------------------------------------------
65test aaa-2.1 {create an optimizer and add parameters to it} {
66  Rappture::optimizer ctxt
67  ctxt add number input.temperature -min 0 -max 1
68  ctxt get
69} {input.temperature -min 0.0 -max 1.0}
70
71test aaa-2.2 {add a parameter with a bad type} {
72  list [catch {ctxt add foo input.wrong -bar test} result] $result
73} {1 {bad parameter type "foo": should be number, string}}
74
75test aaa-2.3 {add a number parameter with a missing option} {
76  list [catch {ctxt add number input.wrong -min} result] $result
77} {1 {missing value for option "-min"}}
78
79test aaa-2.4 {add a number parameter with a bad value} {
80  list [catch {ctxt add number input.wrong -min foo} result] $result
81} {1 {expected floating-point number but got "foo"}}
82
83test aaa-2.5 {add a number parameter with a bad option name} {
84  list [catch {ctxt add number input.wrong -min 0 -foo x} result] $result
85} {1 {bad option "-foo": should be -min, -max}}
86
87test aaa-2.6 {add doesn't add parameter when there's an error} {
88  ctxt get
89} {input.temperature -min 0.0 -max 1.0}
90
91test aaa-2.7 {add a string parameter} {
92  ctxt add string input.choice -values {a b c}
93  ctxt get input.choice
94} {-values {a b c}}
95
96test aaa-2.8 {add a string parameter with a missing option} {
97  list [catch {ctxt add string input.wrong -values} result] $result
98} {1 {missing value for option "-values"}}
99
100test aaa-2.9 {add a string parameter with a bad option name} {
101  list [catch {ctxt add string input.wrong -bad 0} result] $result
102} {1 {bad option "-bad": should be -values}}
103
104test aaa-2.10 {add doesn't add parameter when there's an error} {
105  ctxt get
106} {{input.temperature -min 0.0 -max 1.0} {input.choice -values {a b c}}}
107
108# cleanup
109::tcltest::cleanupTests
110return
Note: See TracBrowser for help on using the repository browser.