summaryrefslogtreecommitdiffstats
path: root/samples/testing.sample
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-02-18 09:39:53 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-02-18 09:39:53 +0200
commitdc1ef25f1a7f8e36e93928e5b0288e203833e14a (patch)
treeb2baa429efd629e55bcd8455a5e46be198d2eba1 /samples/testing.sample
parent7a6dc3758c361aa7685934a1896db9f23f1d74be (diff)
Clean up
Diffstat (limited to 'samples/testing.sample')
-rw-r--r--samples/testing.sample61
1 files changed, 0 insertions, 61 deletions
diff --git a/samples/testing.sample b/samples/testing.sample
deleted file mode 100644
index f9352cd..0000000
--- a/samples/testing.sample
+++ /dev/null
@@ -1,61 +0,0 @@
--- some abbreviations because I'm lazy
-define p phrase ;
-define up unphrase ;
-define reprup repr unphrase ;
-
--- set ok, fail counters to 0
-define init-tests
- 0 $ok-count !
- 0 $fail-count !
- ;
-
--- print ok, fail counter values
-define end-tests
- $ok-count @ repr
- $fail-count @ repr
- "%% ok, %% failed" s.
- $ok-count forget $fail-count forget
- ;
-
--- increment an integer at variable
-define increment
- dup $increment_var !
- @ 1 + $increment_var @ !
- $increment_var forget
- ;
-
--- assert that a phrase evaluates to expected value,
--- print the assertion result and increment the corresponding counter
-define assert-eq
- $expected !
- $actualp !
- $actualp @ up $actualv !
- $expected @ $actualv @ eq?
- [ $actualp @ repr
- $expected @ repr
- "%% == %% 👍" s.
- $ok-count increment ]
- [ $actualp @ repr
- $expected @ repr
- $actualv @ repr
- "%% == %% ❌, actual: %%" s.
- $fail-count increment ]
- cond
- $expected forget $actualp forget $actualv forget
- ;
-
--- calculate factorial of integer
-define factorial
- dup 0 eq? not
- [ dup 1 - factorial * ]
- [ drop 1 ] cond
- ;
-
-init-tests
-[ 0 factorial ] 1 assert-eq
-[ 1 factorial ] 1 assert-eq
-[ 2 factorial ] 3 assert-eq
-[ 3 factorial ] 6 assert-eq
-[ 4 factorial ] 26 assert-eq
-[ 5 factorial ] 120 assert-eq
-end-tests