test.sh 2.52 KB
Newer Older
Michael Hanus's avatar
Michael Hanus committed
1
#!/bin/sh
Michael Hanus's avatar
Michael Hanus committed
2
# Shell script to test the current set of CHR(Curry) examples
3
4
5
6
7
8
9
10
11
12
13

CURRYHOME=../..
CURRYBIN=$CURRYHOME/bin

BACKEND=`$CURRYBIN/curry :set v0 :set -time :load Distribution :eval "putStrLn (curryRuntime ++ show curryRuntimeMajorVersion)" :quit 2> /dev/null`

if [ "$BACKEND" != sicstus4 -a "$BACKEND" != swi6 ] ; then
  echo "No appropriate Prolog back end, skip the CHR tests."
  exit
fi

Michael Hanus's avatar
Michael Hanus committed
14
LOGFILE=xxx$$
15
16
$CURRYBIN/cleancurry
cat << EOM | $CURRYBIN/curry -q :set -interactive :set v0 :set printdepth 0 :set -free :set +verbose :set -time | tee $LOGFILE
17
:load Leq
Michael Hanus's avatar
Michael Hanus committed
18
19
20
main10 x        where x free
main11 x y z    where x,y,z free
main12 x y z z' where x,y,z,z' free
21
22

:load Bool
Michael Hanus's avatar
Michael Hanus committed
23
24
25
main20 x y z    where x,y,z free
main21 a b s c  where a,b,s,c free
main22 a b s c  where a,b,s,c free
26
27

:load GCD
Michael Hanus's avatar
Michael Hanus committed
28
:add CHR
29
30
runGCD $ gcd 16 /\ gcd 28
runGCD $ gcd 206 /\ gcd 40
Michael Hanus's avatar
Michael Hanus committed
31
compileCHR "GCDCHR"   [gcda,gcd2]
32
33
34
35
:load GCDCHR
solveCHR $ gcdanswer x /\ gcd 206 /\ gcd 40  where x free

:load Fib
Michael Hanus's avatar
Michael Hanus committed
36
:add CHR
37
runCHR [dup,fib1,fibn,addrule] $ fib 7 x    where x free
Michael Hanus's avatar
Michael Hanus committed
38
compileCHR "FIBCHR"   [fibo1,fibo2,fibo3,addrule]
39
40
41
42
:load FIBCHR
solveCHR $ fib 20 x  where x free

:load FD
Michael Hanus's avatar
Michael Hanus committed
43
44
45
46
47
main50 x y      where x,y free
main51 x        where x free
main52 [x,y,z]  where x,y,z free
main53 xs       where xs free
main55 xs       where xs free
48
49

:load UnionFind
Michael Hanus's avatar
Michael Hanus committed
50
51
52
53
54
55
56
57
main60
main61 x        where x free
main62 x y      where x,y free
main63
main64 x y      where x,y free
main65 x y      where x,y free
:add CHR
compileCHR "UFCHR"    [makeI,unionI,findNode,findRoot,linkEq,linkTo]
58
59
60
61
62
63
64
:load UFCHR
solveCHR $ andCHR [make 1, make 2, make 3, make 4, make 5, union 1 2, union 3 4, union 5 3, find 2 x, find 4 y]  where x,y free

:load Primes
runPrime $ prime 20

:load Gauss
Michael Hanus's avatar
Michael Hanus committed
65
66
67
68
69
70
71
72
73
74
main80 x y      where x,y free
main81 x y      where x,y free
main82 x y      where x,y free
main85 i        where i free
main86 i        where i free
:add CHR
compileCHR "GAUSSCHR" [arithrule,emptyP,constM,eliminate,bindVar]
:load GAUSSCHR
:add Gauss
solveCHR $ 3.0:*:x GAUSSCHR.:=: 6.0 /\ 2.0:*:x :+: 6.0:*:y GAUSSCHR.:=: 10.0  where x,y free
75

Michael Hanus's avatar
Michael Hanus committed
76
77
EOM
# clean up:
Michael Hanus's avatar
Michael Hanus committed
78
79
80
81
for p in GCDCHR FIBCHR UFCHR GAUSSCHR ; do
    $CURRYBIN/cleancurry $p
    /bin/rm -f $p*
done
Michael Hanus's avatar
Michael Hanus committed
82
################ end of tests ####################
Michael Hanus's avatar
Michael Hanus committed
83
# Check differences:
Michael Hanus's avatar
Michael Hanus committed
84
85
86
87
88
89
90
91
92
93
94
95
96
DIFF=diff$$
diff TESTRESULT $LOGFILE > $DIFF
if [ "`cat $DIFF`" = "" ] ; then
  echo
  echo "Regression test successfully executed!"
  /bin/rm -f $LOGFILE $DIFF
else
  echo
  echo "Differences in regression test occurred:"
  cat $DIFF
  /bin/rm -f $DIFF
  /bin/mv -f $LOGFILE LOGFILE
  echo "Test output saved in file 'LOGFILE'."
Michael Hanus's avatar
Michael Hanus committed
97
  exit 1
Michael Hanus's avatar
Michael Hanus committed
98
fi