diff yetilab/vector/test/test_vector.yeti @ 222:77c6a81c577f matrix_opaque_immutable

Move block directory -> vector
author Chris Cannam
date Sat, 11 May 2013 15:58:36 +0100
parents yetilab/block/test/test_vector.yeti@8e79cf8a4399
children de770971a628
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yetilab/vector/test/test_vector.yeti	Sat May 11 15:58:36 2013 +0100
@@ -0,0 +1,130 @@
+
+module yetilab.vector.test.test_vector;
+
+vec = load yetilab.vector.vector;
+
+{ compare } = load yetilab.test.test;
+
+[
+
+"zeros-empty": \(
+    v = vec.zeros 0;
+    compare (vec.length v) 0;
+),
+
+"zeros": \(
+    v = vec.zeros 3;
+    a = vec.array v;
+    compare (vec.length v) 3 and
+        compare a[0] 0 and
+        compare a[1] 0 and
+        compare a[2] 0;
+),
+
+"consts-empty": \(
+    v = vec.consts 4 0;
+    compare (vec.length v) 0;
+),
+
+"consts": \(
+    v = vec.consts 4 3;
+    a = vec.array v;
+    compare (vec.length v) 3 and
+        compare a[0] 4 and
+        compare a[1] 4 and
+        compare a[2] 4;
+),
+
+"ones-empty": \(
+    v = vec.ones 0;
+    compare (vec.length v) 0;
+),
+
+"ones": \(
+    v = vec.ones 3;
+    a = vec.array v;
+    compare (vec.length v) 3 and
+        compare a[0] 1 and
+        compare a[1] 1 and
+        compare a[2] 1;
+),
+
+"from-list-empty": \(
+    v = vec.fromList [];
+    compare (vec.length v) 0;
+),
+
+"from-list": \(
+    v = vec.fromList [1,2,3,4];
+    a = vec.array v;
+    compare (vec.length v) 4 and
+        compare a[0] 1 and
+        compare a[1] 2 and
+        compare a[2] 3 and
+        compare a[3] 4;
+),
+
+"equal-empty": \(
+    vec.equal (vec.fromList []) (vec.fromList [])
+),
+
+"equal": \(
+    v = vec.fromList [1,1,1,1];
+    w = vec.ones 4;
+    w' = vec.zeros 4;
+    w'' = vec.ones 3;
+    vec.equal v w and not vec.equal v w' and not vec.equal v w'';
+),
+/*
+"copyOf-empty": \(
+    vec.equal (vec.fromList []) (vec.copyOf (vec.fromList []))
+),
+
+"copyOf": \(
+    v = vec.fromList [1,2,3,4];
+    w = vec.copyOf v;
+    vec.equal v w and (
+        v[0] := 0; // check result is not aliasing inputs
+        not vec.equal v w
+    );
+),
+*/
+"rangeOf": \(
+    v = vec.fromList [1,2,3,4];
+    vec.equal (vec.rangeOf 0 4 v) v and (
+        vec.equal (vec.rangeOf 2 2 v) (vec.fromList [3,4])
+    )
+),
+
+"resizedTo": \(
+    vec.equal (vec.resizedTo 4 (vec.fromList [])) (vec.zeros 4) and
+        vec.equal (vec.resizedTo 2 (vec.fromList [1,2])) (vec.fromList [1,2]) and
+        vec.equal (vec.resizedTo 3 (vec.fromList [1,2])) (vec.fromList [1,2,0]) and
+        vec.equal (vec.resizedTo 2 (vec.fromList [1,2,3])) (vec.fromList [1,2]);
+),
+
+"concat2": \(
+    v = vec.fromList [1,2,3];
+    w = vec.fromList [4,5,6];
+    x = vec.concat [v, w];
+    x' = vec.fromList [1,2,3,4,5,6];
+    vec.equal x x' and
+/*       (v[0] := 0; // check result is not aliasing inputs
+        w[0] := 0;
+        vec.equal x x') and */
+        vec.equal x' (vec.concat [x', vec.fromList []]) and
+        vec.equal x' (vec.concat [vec.fromList [], x'])
+),
+
+"concatn": \(
+    v = vec.fromList [1,2,3];
+    w = vec.fromList [4,5,6];
+    vec.equal (vec.concat []) (vec.zeros 0) and
+        vec.equal (vec.concat [v]) v and
+        vec.equal (vec.concat [v,w,v]) (vec.fromList [1,2,3,4,5,6,1,2,3])
+),
+
+] is hash<string, () -> boolean>;
+
+
+