summaryrefslogtreecommitdiff
path: root/tests/arr
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2019-12-06 10:15:58 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2019-12-06 10:15:58 -0500
commit753923c9a3ae6b5e3d6754083c2f2a8742b62ebb (patch)
tree38b78b26570ddcb02996409243d2b00ec218cdfb /tests/arr
parent21f98fd513f193963f5932da84176c418168d061 (diff)
new test
Diffstat (limited to 'tests/arr')
-rw-r--r--tests/arr/.gitignore1
-rw-r--r--tests/arr/arr.toc51
-rw-r--r--tests/arr/expected200
-rwxr-xr-xtests/arr/test.sh3
4 files changed, 255 insertions, 0 deletions
diff --git a/tests/arr/.gitignore b/tests/arr/.gitignore
new file mode 100644
index 0000000..a0ae6ee
--- /dev/null
+++ b/tests/arr/.gitignore
@@ -0,0 +1 @@
+got \ No newline at end of file
diff --git a/tests/arr/arr.toc b/tests/arr/arr.toc
new file mode 100644
index 0000000..a999512
--- /dev/null
+++ b/tests/arr/arr.toc
@@ -0,0 +1,51 @@
+puti ::= fn(x: int) {
+ #C("printf(\"%ld\\n\", (long)x);
+");
+};
+putf ::= fn(x: float) {
+ #C("printf(\"%f\\n\", (double)x);
+");
+};
+
+// it would be nice if Arr.data.len == Arr.len (: but this will require some C code...
+Arr ::= fn (t :: Type) Type {
+ struct {
+ data : []t;
+ len, cap : int;
+ }
+};
+
+arr_add ::= fn(t :: Type, a : &Arr(t), x : t) {
+ if a.len >= a.cap {
+ a.cap = a.cap * 2 + 2;
+ new_data := new(t, a.cap);
+ each i := 0..a.len-1 {
+ new_data[i] = a.data[i];
+ }
+ a.data = new_data;
+ }
+ a.data[a.len] = x;
+ a.len += 1;
+};
+
+
+ArrInt ::= Arr(int);
+
+inc ::= fn(t :: Type, x : t) t {
+ x + 1
+};
+
+main ::= fn() {
+ arr : ArrInt;
+ farr : Arr(float);
+ each i := 1..100 {
+ arr_add(int, &arr, inc(int, i*i));
+ arr_add(float, &farr, inc(float, (i*i) as float));
+ }
+ each i := 0..arr.len - 1 {
+ puti(arr.data[i]);
+ }
+ each i := 0..farr.len - 1 {
+ putf(farr.data[i]);
+ }
+};
diff --git a/tests/arr/expected b/tests/arr/expected
new file mode 100644
index 0000000..c0a3e45
--- /dev/null
+++ b/tests/arr/expected
@@ -0,0 +1,200 @@
+2
+5
+10
+17
+26
+37
+50
+65
+82
+101
+122
+145
+170
+197
+226
+257
+290
+325
+362
+401
+442
+485
+530
+577
+626
+677
+730
+785
+842
+901
+962
+1025
+1090
+1157
+1226
+1297
+1370
+1445
+1522
+1601
+1682
+1765
+1850
+1937
+2026
+2117
+2210
+2305
+2402
+2501
+2602
+2705
+2810
+2917
+3026
+3137
+3250
+3365
+3482
+3601
+3722
+3845
+3970
+4097
+4226
+4357
+4490
+4625
+4762
+4901
+5042
+5185
+5330
+5477
+5626
+5777
+5930
+6085
+6242
+6401
+6562
+6725
+6890
+7057
+7226
+7397
+7570
+7745
+7922
+8101
+8282
+8465
+8650
+8837
+9026
+9217
+9410
+9605
+9802
+10001
+2.000000
+5.000000
+10.000000
+17.000000
+26.000000
+37.000000
+50.000000
+65.000000
+82.000000
+101.000000
+122.000000
+145.000000
+170.000000
+197.000000
+226.000000
+257.000000
+290.000000
+325.000000
+362.000000
+401.000000
+442.000000
+485.000000
+530.000000
+577.000000
+626.000000
+677.000000
+730.000000
+785.000000
+842.000000
+901.000000
+962.000000
+1025.000000
+1090.000000
+1157.000000
+1226.000000
+1297.000000
+1370.000000
+1445.000000
+1522.000000
+1601.000000
+1682.000000
+1765.000000
+1850.000000
+1937.000000
+2026.000000
+2117.000000
+2210.000000
+2305.000000
+2402.000000
+2501.000000
+2602.000000
+2705.000000
+2810.000000
+2917.000000
+3026.000000
+3137.000000
+3250.000000
+3365.000000
+3482.000000
+3601.000000
+3722.000000
+3845.000000
+3970.000000
+4097.000000
+4226.000000
+4357.000000
+4490.000000
+4625.000000
+4762.000000
+4901.000000
+5042.000000
+5185.000000
+5330.000000
+5477.000000
+5626.000000
+5777.000000
+5930.000000
+6085.000000
+6242.000000
+6401.000000
+6562.000000
+6725.000000
+6890.000000
+7057.000000
+7226.000000
+7397.000000
+7570.000000
+7745.000000
+7922.000000
+8101.000000
+8282.000000
+8465.000000
+8650.000000
+8837.000000
+9026.000000
+9217.000000
+9410.000000
+9605.000000
+9802.000000
+10001.000000
diff --git a/tests/arr/test.sh b/tests/arr/test.sh
new file mode 100755
index 0000000..4977e56
--- /dev/null
+++ b/tests/arr/test.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+./arr.bin > got || exit 1
+diff got expected > /dev/null || exit 1