view yetilab/vector/test/test_vector.yeti @ 260:de770971a628

Rename and reorder args of at and slice functions in matrix and vector for consistency with std module equivalents
author Chris Cannam
date Wed, 22 May 2013 13:54:15 +0100
parents 77c6a81c577f
children c7efd12c27c5
line wrap: on
line source

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'';
),

"slice": \(
    v = vec.fromList [1,2,3,4];
    vec.equal (vec.slice v 0 4) v and (
        vec.equal (vec.slice v 2 4) (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
        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>;