@@ -15,26 +15,45 @@ create EXPECTED-RESULTS 32 cells allot
1515variable RESULTS
1616variable DIFFERENCES
1717
18+ variable ^passed
19+ variable ^nresults
20+ variable ^different
21+
22+ : passed$ ." Test Passed" cr ;
23+ : different$ ." Expected "
24+ RESULTS @ 0 +do EXPECTED-RESULTS i cells + @ . loop
25+ ." , got "
26+ RESULTS @ 0 +do ACTUAL-RESULTS i cells + @ . loop
27+ cr ;
28+ : nresults$ ." Wrong number of results, expected " depth START-DEPTH @ - .
29+ ." , got " ACTUAL-DEPTH @ START-DEPTH @ - . cr ;
30+
31+ ' passed$ ^passed !
32+ ' nresults$ ^nresults !
33+ ' different$ ^different !
34+
1835: <{ T{ ;
1936: }>
2037 depth ACTUAL-DEPTH @ = if
2138 depth START-DEPTH @ > if
22- depth START-DEPTH @ - dup RESULTS ! 0 do
39+ 0 DIFFERENCES !
40+ depth START-DEPTH @ - dup RESULTS ! 0 +do
2341 dup EXPECTED-RESULTS i cells + !
2442 ACTUAL-RESULTS i cells + @ <> DIFFERENCES +!
2543 loop
2644 DIFFERENCES @ if
27- failed# ." Expected "
28- RESULTS @ 0 do EXPECTED-RESULTS i cells + @ . loop
29- ." , got "
30- RESULTS @ 0 do ACTUAL-RESULTS i cells + @ . loop
31- cr
45+ failed# ^different @ execute
3246 else
33- passed# ." Test Passed" cr
47+ passed# ^passed @ execute
3448 then
3549 then
3650 else
37- failed# ." Wrong number of results, expected " depth START-DEPTH @ - . ." , got " ACTUAL-DEPTH @ START-DEPTH @ - . cr
51+ failed# ^nresults @ execute
3852 then
3953 EMPTY-STACK
4054 F} ;
55+
56+ 3037000493 constant #m \ prime number < sqrt (2^63-1)
57+ 53 constant #p \ prime number
58+ : c# { hash pow c -- hash' pow' } c pow * hash + #m mod pow #p * #m mod ; \ polynomial rolling hash function, single char
59+ : s# { c-addr u -- hash } 0 1 c-addr u 0 +do { s } s c@ c# s char+ loop 2drop ; \ string hash
0 commit comments