root / pobysoC-4.0 / src / test-pobyso-evaluate-constant.sh @ 145
Historique | Voir | Annoter | Télécharger (1,45 ko)
1 | 145 | storres | #! /bin/sh |
---|---|---|---|
2 | 145 | storres | # |
3 | 145 | storres | # |
4 | 145 | storres | TEST_BIN=./test-pobyso-evaluate-constant |
5 | 145 | storres | POBYSO_UNFAITHFUL=129 |
6 | 145 | storres | POBYSO_NAN=130 |
7 | 145 | storres | |
8 | 145 | storres | echo |
9 | 145 | storres | ## Functions |
10 | 145 | storres | ok_if_fail() { |
11 | 145 | storres | echo "$@" |
12 | 145 | storres | eval "$TEST_BIN $ARGUMENTS" |
13 | 145 | storres | if [ $? -eq 0 ] ; then |
14 | 145 | storres | echo "Succeeded (but should not have) for $ARGUMENTS" |
15 | 145 | storres | exit 1 |
16 | 145 | storres | fi |
17 | 145 | storres | echo "Correctly failing$WHY." |
18 | 145 | storres | echo |
19 | 145 | storres | } # End ok_if_fail |
20 | 145 | storres | # |
21 | 145 | storres | ## |
22 | 145 | storres | ok_if_ok() { |
23 | 145 | storres | echo "$@" |
24 | 145 | storres | eval "$TEST_BIN $ARGUMENTS" |
25 | 145 | storres | OUTCOME=$? |
26 | 145 | storres | if [ $OUTCOME -ne 0 ] ; then |
27 | 145 | storres | if [ $OUTCOME -eq $POBYSO_UNFAITHFUL ] ; then |
28 | 145 | storres | echo "Result is unfaithfull for $ARGUMENTS" |
29 | 145 | storres | echo |
30 | 145 | storres | return 0 |
31 | 145 | storres | fi |
32 | 145 | storres | if [ $OUTCOME -eq $POBYSO_NAN ] ; then |
33 | 145 | storres | echo "Result is NaN for $ARGUMENTS" |
34 | 145 | storres | echo |
35 | 145 | storres | return 0 |
36 | 145 | storres | fi |
37 | 145 | storres | echo "Failed for $ARGUMENTS" |
38 | 145 | storres | echo |
39 | 145 | storres | exit 1 |
40 | 145 | storres | fi |
41 | 145 | storres | echo |
42 | 145 | storres | } # End ok_if_ok |
43 | 145 | storres | ## |
44 | 145 | storres | ARGUMENTS="NULL" |
45 | 145 | storres | WHY=" (NULL argument)" |
46 | 145 | storres | ok_if_fail "Testing: $ARGUMENTS" |
47 | 145 | storres | |
48 | 145 | storres | ## |
49 | 145 | storres | ARGUMENTS="\"1/x+\" \"3\"" |
50 | 145 | storres | WHY=" (because \"1/x+\" is not a valid expression)" |
51 | 145 | storres | ok_if_fail "Testing: $ARGUMENTS" |
52 | 145 | storres | |
53 | 145 | storres | ## |
54 | 145 | storres | ARGUMENTS="\"1/x\" \"3+\"" |
55 | 145 | storres | WHY=" (because \"3+\" is not a constant)" |
56 | 145 | storres | ok_if_fail "Testing: $ARGUMENTS" |
57 | 145 | storres | |
58 | 145 | storres | ## |
59 | 145 | storres | ARGUMENTS="\"1/x\" \"+infty\"" |
60 | 145 | storres | ok_if_ok "Testing: $ARGUMENTS" |
61 | 145 | storres | |
62 | 145 | storres | ## |
63 | 145 | storres | ARGUMENTS="\"1/x\" \"+infty\"" |
64 | 145 | storres | ok_if_ok "Testing: $ARGUMENTS" |
65 | 145 | storres | |
66 | 145 | storres | ARGUMENTS="\"1/x\" \"0\"" |
67 | 145 | storres | WHY=" (because the result is Nan)" |
68 | 145 | storres | ok_if_ok "Testing: $ARGUMENTS" |
69 | 145 | storres | |
70 | 145 | storres | ARGUMENTS="\"2*x\" \"4\"" |
71 | 145 | storres | WHY=" (because the result is Nan)" |
72 | 145 | storres | ok_if_ok "Testing: $ARGUMENTS" |
73 | 145 | storres | |
74 | 145 | storres | ARGUMENTS="\"sin(x)\" \"pi/2\"" |
75 | 145 | storres | WHY=" (because the result is Nan)" |
76 | 145 | storres | ok_if_ok "Testing: $ARGUMENTS" |
77 | 145 | storres | |
78 | 145 | storres | ## |
79 | 145 | storres | echo "Tests terminated without error." |
80 | 145 | storres | echo |