diff --git a/test/test-custom.4th b/test/test-custom.4th new file mode 100644 index 0000000..0ec04b1 --- /dev/null +++ b/test/test-custom.4th @@ -0,0 +1,35 @@ +\ Copyright 2019 nomennescio + +s" custom messages" describe#{ + + :noname ." Just passed" cr ; ^passed ! + :noname ." Just failed" cr ; ^different ! + + s" short strings" it#{ + <{ s" Hello World!" s# -> s" Hello World!" s# }> + <{ s" Hello Worlds!" s# -> s" Hello Worlds!" s# }> + }# + s" failing compares" it#{ + <{ s" Hello World!" s# -> s" Hello Worlds!" s# }> + <{ s" Hello Worlds!" s# -> s" Hello Worlds! " s# }> + }# + + 2variable actual$ + 2variable expected$ + + :noname ." Got '" actual$ 2@ type ." ' as expected" cr ; ^passed ! + :noname ." Expected '" expected$ 2@ type ." ', got '" actual$ 2@ type ." '" cr ; ^different ! + + : &actual 2dup actual$ 2! ; + : &expected 2dup expected$ 2! ; + + s" short strings" it#{ + <{ s" Hello World!" &actual s# -> s" Hello World!" &expected s# }> + <{ s" Hello Worlds!" &actual s# -> s" Hello Worlds!" &expected s# }> + }# + s" failing compares" it#{ + <{ s" Hello World!" &actual s# -> s" Hello Worlds!" &expected s# }> + <{ s" Hello Worlds!" &actual s# -> s" Hello Worlds! " &expected s# }> + }# + +}# diff --git a/test/test-custom.expected b/test/test-custom.expected new file mode 100644 index 0000000..c966c57 --- /dev/null +++ b/test/test-custom.expected @@ -0,0 +1,36 @@ + +custom messages + +short strings + +Just passed + +Just passed + +0.139 ms + +failing compares + +Just failed + +Just failed + +0.162 ms + +short strings + +Got 'Hello World!' as expected + +Got 'Hello Worlds!' as expected + +0.149 ms + +failing compares + +Expected 'Hello Worlds!', got 'Hello World!' + +Expected 'Hello Worlds! ', got 'Hello Worlds!' + +0.150 ms + +1.365 ms diff --git a/test/test-hash.4th b/test/test-hash.4th new file mode 100644 index 0000000..f3d0f13 --- /dev/null +++ b/test/test-hash.4th @@ -0,0 +1,11 @@ +\ Copyright 2019 nomennescio +s" string hash" describe#{ + s" short strings" it#{ + <{ s" Hello World!" s# -> s" Hello World!" s# }> + <{ s" Hello Worlds!" s# -> s" Hello Worlds!" s# }> + }# + s" failing compares" it#{ + <{ s" Hello World!" s# -> s" Hello Worlds!" s# }> + <{ s" Hello Worlds!" s# -> s" Hello Worlds! " s# }> + }# +}# diff --git a/test/test-hash.expected b/test/test-hash.expected new file mode 100644 index 0000000..4f6fc88 --- /dev/null +++ b/test/test-hash.expected @@ -0,0 +1,20 @@ + +string hash + +short strings + +Test Passed + +Test Passed + +0.125 ms + +failing compares + +Expected 1266463317 , got 610024131 + +Expected 1589968543 , got 1266463317 + +0.124 ms + +0.292 ms diff --git a/ttester-codewars.4th b/ttester-codewars.4th index 77bcd04..8553ffb 100644 --- a/ttester-codewars.4th +++ b/ttester-codewars.4th @@ -15,26 +15,45 @@ create EXPECTED-RESULTS 32 cells allot variable RESULTS variable DIFFERENCES +variable ^passed +variable ^nresults +variable ^different + +: passed$ ." Test Passed" cr ; +: different$ ." Expected " + RESULTS @ 0 +do EXPECTED-RESULTS i cells + @ . loop + ." , got " + RESULTS @ 0 +do ACTUAL-RESULTS i cells + @ . loop + cr ; +: nresults$ ." Wrong number of results, expected " depth START-DEPTH @ - . + ." , got " ACTUAL-DEPTH @ START-DEPTH @ - . cr ; + +' passed$ ^passed ! +' nresults$ ^nresults ! +' different$ ^different ! + : <{ T{ ; : }> depth ACTUAL-DEPTH @ = if depth START-DEPTH @ > if - depth START-DEPTH @ - dup RESULTS ! 0 do + 0 DIFFERENCES ! + depth START-DEPTH @ - dup RESULTS ! 0 +do dup EXPECTED-RESULTS i cells + ! ACTUAL-RESULTS i cells + @ <> DIFFERENCES +! loop DIFFERENCES @ if - failed# ." Expected " - RESULTS @ 0 do EXPECTED-RESULTS i cells + @ . loop - ." , got " - RESULTS @ 0 do ACTUAL-RESULTS i cells + @ . loop - cr + failed# ^different @ execute else - passed# ." Test Passed" cr + passed# ^passed @ execute then then else - failed# ." Wrong number of results, expected " depth START-DEPTH @ - . ." , got " ACTUAL-DEPTH @ START-DEPTH @ - . cr + failed# ^nresults @ execute then EMPTY-STACK F} ; + +3037000493 constant #m \ prime number < sqrt (2^63-1) +53 constant #p \ prime number +: c# { hash pow c -- hash' pow' } c pow * hash + #m mod pow #p * #m mod ; \ polynomial rolling hash function, single char +: s# { c-addr u -- hash } 0 1 c-addr u 0 +do { s } s c@ c# s char+ loop 2drop ; \ string hash \ No newline at end of file