Skip to content

Commit 81739e4

Browse files
committed
Add code and license
1 parent 752060b commit 81739e4

File tree

7 files changed

+88
-0
lines changed

7 files changed

+88
-0
lines changed

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018-2019 nomennescio
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## ttester Codewars
2+
3+
`ttester.fs` extension to output test results for Codewars.
4+
5+
This project is work in progress.
6+
7+
Please contribute to improve Forth support on Codewars.
8+
9+
## Example
10+
11+
See [example](./example).
12+
13+
## Acknowledgements
14+
15+
Authored by [@nomennescio](https://github.com/nomennescio).

example/preloaded.4th

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\ preloaded.4th is loaded before solution.4th

example/run-tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
example_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P)
4+
5+
cd "$example_dir"
6+
gforth preloaded.4th solution.4th ../ttester-codewars.4th tests.4th -e bye

example/solution.4th

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
: solution ( u1|n1 u2|n2 -- u3|n3 ) + ; \ Addition

example/tests.4th

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
s" solution" describe#{
2+
s" returns sum" it#{
3+
<{ 1 1 solution -> 2 }>
4+
}#
5+
}#

ttester-codewars.4th

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
\ ttester extension for Codewars
2+
decimal
3+
s" test/ttester.fs" included
4+
5+
: #ms ( dmicroseconds -- len c-addr ) <# # # # [char] . hold #s #> ;
6+
7+
: describe#{ ( len c-addr -- ) cr ." <DESCRIBE::>" type cr utime ;
8+
: it#{ ( len c-addr -- ) cr ." <IT::>" type cr utime ;
9+
: }# ( -- ) utime cr ." <COMPLETEDIN::>" 2swap d- #ms type ." ms" cr ;
10+
11+
: failed# ( -- ) cr ." <FAILED::>" ;
12+
: passed# ( -- ) cr ." <PASSED::>" ;
13+
14+
create EXPECTED-RESULTS 32 cells allot
15+
variable RESULTS
16+
variable DIFFERENCES
17+
18+
: <{ T{ ;
19+
: }>
20+
depth ACTUAL-DEPTH @ = if
21+
depth START-DEPTH @ > if
22+
depth START-DEPTH @ - dup RESULTS ! 0 do
23+
dup EXPECTED-RESULTS i cells + !
24+
ACTUAL-RESULTS i cells + @ <> DIFFERENCES +!
25+
loop
26+
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
32+
else
33+
passed# ." Test Passed" cr
34+
then
35+
then
36+
else
37+
failed# ." Wrong number of results, expected " ACTUAL-DEPTH @ . ." , got " depth . cr
38+
then
39+
F} ;

0 commit comments

Comments
 (0)