| 1 |
/* |
| 2 |
* @progname st_table.li |
| 3 |
* @version 1.0 (2005-02-01) |
| 4 |
* @author Perry Rapp |
| 5 |
* @category self-test |
| 6 |
* @output none |
| 7 |
* @description validate table functions |
| 8 |
*/ |
| 9 |
|
| 10 |
char_encoding("ASCII") |
| 11 |
|
| 12 |
require("lifelines-reports.version:1.3") |
| 13 |
option("explicitvars") /* Disallow use of undefined variables */ |
| 14 |
include("st_aux") |
| 15 |
|
| 16 |
/* entry point in case not invoked via st_all.ll */ |
| 17 |
proc main() |
| 18 |
{ |
| 19 |
call testTables() |
| 20 |
} |
| 21 |
|
| 22 |
/* |
| 23 |
test some table functions |
| 24 |
*/ |
| 25 |
proc testTables() |
| 26 |
{ |
| 27 |
call initSubsection() |
| 28 |
|
| 29 |
table(tbl) |
| 30 |
/* empty table tests */ |
| 31 |
if (not(empty(tbl))) { |
| 32 |
call reportfail("empty FAILED") |
| 33 |
} |
| 34 |
else { incr(testok) } |
| 35 |
if (ne(length(tbl), 0)) { |
| 36 |
call reportfail("length(table)==0 FAILED") |
| 37 |
} |
| 38 |
else { incr(testok) } |
| 39 |
/* single element table tests */ |
| 40 |
insert(tbl, "alpha", 1) |
| 41 |
if (empty(tbl)) { |
| 42 |
call reportfail("not empty FAILED") |
| 43 |
} |
| 44 |
else { incr(testok) } |
| 45 |
set(el, lookup(tbl, "alpha")) |
| 46 |
if (ne(el, 1)) { |
| 47 |
call reportfail("lookup(alpha) FAILED") |
| 48 |
} |
| 49 |
else { incr(testok) } |
| 50 |
if (ne(length(tbl), 1)) { |
| 51 |
call reportfail("length(table)==1 FAILED") |
| 52 |
} |
| 53 |
else { incr(testok) } |
| 54 |
insert(tbl, "alpha", 2) |
| 55 |
set(el, lookup(tbl, "alpha")) |
| 56 |
if (ne(el, 2)) { |
| 57 |
call reportfail("lookup(alpha) FAILED") |
| 58 |
} |
| 59 |
else { incr(testok) } |
| 60 |
if (ne(length(tbl), 1)) { |
| 61 |
call reportfail("length(table)==1 FAILED") |
| 62 |
} |
| 63 |
else { incr(testok) } |
| 64 |
/* two element table tests */ |
| 65 |
insert(tbl, "bravo", 2) |
| 66 |
if (ne(length(tbl), 2)) { |
| 67 |
call reportfail("length(table)==2 FAILED") |
| 68 |
} |
| 69 |
else { incr(testok) } |
| 70 |
|
| 71 |
call testFreeTable(tbl) |
| 72 |
|
| 73 |
call reportSubsection("table tests") |
| 74 |
} |
| 75 |
|
| 76 |
proc testFreeTable(tbl) |
| 77 |
{ |
| 78 |
free(tbl) |
| 79 |
if (ne(tbl, 0)) { |
| 80 |
call reportfail("free table FAILED") |
| 81 |
} |
| 82 |
else { incr(testok) } |
| 83 |
} |