Skip to content

Commit 4688629

Browse files
committed
Renames lispy-tests.json to interpreter-tests.json and moves all into one json
1 parent 138714e commit 4688629

File tree

5 files changed

+43
-59
lines changed

5 files changed

+43
-59
lines changed

ports-js/interpreter-tests.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,9 @@ function valueToString(value) {
5959
// Load test cases
6060
let testTable = [];
6161
try {
62-
const testsPath1 = join(__dirname, '../ports/lispy-tests.json');
63-
const testsPath2 = join(__dirname, '../ports/lispy-tests2.json');
62+
const testsPath = join(__dirname, '../ports/interpreter-tests.json');
6463

65-
const tests1 = JSON.parse(readFileSync(testsPath1, 'utf8'));
66-
testTable = testTable.concat(tests1);
67-
68-
const tests2 = JSON.parse(readFileSync(testsPath2, 'utf8'));
69-
testTable = testTable.concat(tests2);
64+
testTable = JSON.parse(readFileSync(testsPath, 'utf8'));
7065
} catch (error) {
7166
console.error(`Error loading test files: ${error.message}`);
7267
process.exit(1);

ports-py/interpreter-tests.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
import numbers
44

55
testTable = []
6-
with open("ports/lispy-tests.json") as file:
7-
testTable.extend(json.load(file))
6+
with open("ports/interpreter-tests.json") as file:
7+
testTable = json.load(file)
88

9-
with open("ports/lispy-tests2.json") as file:
10-
testTable.extend(json.load(file))
11-
129
def matches(structure, target):
1310
if(isinstance(target, dict) and "type" in target):
1411
return isinstance(structure, Exception)

ports-rb/interpreter-tests.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,8 @@ def matches(result, target)
3131
# Load test cases
3232
test_table = []
3333
begin
34-
tests_path1 = File.join(dirname, "../ports/lispy-tests.json")
35-
tests_path2 = File.join(dirname, "../ports/lispy-tests2.json")
36-
37-
tests1 = JSON.parse(File.read(tests_path1))
38-
test_table.concat(tests1)
39-
40-
tests2 = JSON.parse(File.read(tests_path2))
41-
test_table.concat(tests2)
34+
tests_path = File.join(dirname, "../ports/interpreter-tests.json")
35+
test_table = JSON.parse(File.read(tests_path))
4236
rescue => error
4337
puts "Error loading test files: #{error.message}"
4438
exit(1)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
11
[
2+
{"input": "(quote (testing 1 (2.0) -3.14e159))", "expected": ["testing", 1, [2.0], -3.14e159]},
3+
{"input": "(+ 2 2)", "expected": 4},
4+
{"input": "(+ (* 2 100) (* 1 10))", "expected": 210},
5+
{"input": "(if (> 6 5) (+ 1 1) (+ 2 2))", "expected": 2},
6+
{"input": "(if (< 6 5) (+ 1 1) (+ 2 2))", "expected": 4},
7+
{"input": "(cond ((< 6 5) 1) ((< 5 6) 2) (else 3) )", "expected": 2},
8+
{"input": "(cond ((< 6 5) 1) (#f 2) (else 3) )", "expected": 3},
9+
{"input": "(cond ((< 6 5) 1) (#f 2))", "expected": null},
10+
{"input": "(define x 3)", "expected": null},
11+
{"input": "x", "expected": 3},
12+
{"input": "(+ x x)", "expected": 6},
13+
{"input": "((lambda (x) (+ x x)) 5)", "expected": 10},
14+
{"input": "(define twice (lambda (x) (* 2 x)))", "expected": null},
15+
{"input": "(twice 5)", "expected": 10},
16+
{"input": "(define compose (lambda (f g) (lambda (x) (f (g x)))))", "expected": null},
17+
{"input": "((compose list twice) 5)", "expected": [10]},
18+
{"input": "(define repeat (lambda (f) (compose f f)))", "expected": null},
19+
{"input": "((repeat twice) 5)", "expected": 20},
20+
{"input": "((repeat (repeat twice)) 5)", "expected": 80},
21+
{"input": "(define fact (lambda (n) (if (<= n 1) 1 (* n (fact (- n 1))))))", "expected": null},
22+
{"input": "(fact 3)", "expected": 6},
23+
{"input": "(fact 50)", "expected": 30414093201713378043612608166064768844377641568960512000000000000},
24+
{"input": "(define abs (lambda (n) ((if (> n 0) + -) 0 n)))", "expected": null},
25+
{"input": "(list (abs -3) (abs 0) (abs 3))", "expected": [3, 0, 3]},
26+
{"input": "(define combine (lambda (f)\n(lambda (x y)\n(if (null? x) (quote ())\n(f (list (car x) (car y))\n((combine f) (cdr x) (cdr y)))))))", "expected": null},
27+
{"input": "(define zip (combine cons))", "expected": null},
28+
{"input": "(zip (list 1 2 3 4) (list 5 6 7 8))", "expected" : [[1, 5], [2, 6], [3, 7], [4, 8]]},
29+
{"input": "(define riff-shuffle (lambda (deck) (begin\n(define take (lambda (n seq) (if (<= n 0) (quote ()) (cons (car seq) (take (- n 1) (cdr seq))))))\n(define drop (lambda (n seq) (if (<= n 0) seq (drop (- n 1) (cdr seq)))))\n(define mid (lambda (seq) (/ (length seq) 2)))\n((combine append) (take (mid deck) deck) (drop (mid deck) deck)))))", "expected" : null},
30+
{"input": "(riff-shuffle (list 1 2 3 4 5 6 7 8))", "expected" : [1, 5, 2, 6, 3, 7, 4, 8]},
31+
{"input": "((repeat riff-shuffle) (list 1 2 3 4 5 6 7 8))", "expected" : [1, 3, 5, 7, 2, 4, 6, 8]},
32+
{"input": "(riff-shuffle (riff-shuffle (riff-shuffle (list 1 2 3 4 5 6 7 8))))", "expected" : [1,2,3,4,5,6,7,8]},
33+
{"input": "(equal? \"a\" 'a)", "expected": false},
34+
{"input": "(equal? 'a \"a\")", "expected": false},
35+
{"input": "(equal? \"a\" \"a\")", "expected": true},
36+
{"input": "(equal? 'a 'a)", "expected": true},
37+
{"input": "(eq? 'a 'a)", "expected": true},
38+
{"input": "(eqv? 'a 'a)", "expected": true},
239
{"input": "()", "expected": {"type": "SyntaxError"}},
340
{"input": "(set! x)", "expected": {"type": "SyntaxError"}},
441
{"input": "(define 3 4)", "expected": {"type": "SyntaxError"}},

ports/lispy-tests.json

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)