Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > cd38b09e3cb8d6c675b02d30393e68af > files > 37

kaya-doc-0.5.2-8.fc14.noarch.rpm

#!/usr/bin/env kayac

import Testing;
import System;

// Some basic conversion tests
Void intConv {
    x = randomInt;
    assert(Int(String(x)) == x, String(x));
}

Void floatConv {
    x = randomFloat;
    // Some error allowance needed!
    y = Float(String(x));
    assert((y-x)<0.0000001 || (x-y)<0.0000001, String(x));
}

// Properties of prelude functions

Void rev {
    xs = randomIntArray();
    ys = copy(xs);
    reverse(ys);
    if (size(xs)>0) {
	assert(xs[0] == ys[size(ys)-1]);
    }
    reverse(ys);
    assert(xs == ys);
}

Void testRep {
    foo = randomString();
    assert(length(rep(foo,5))==length(foo)*5);
}

Void testSort {
    xs = [1..(1000+rand()%2000)];
    ys = copy(xs);
    shuffle(xs);
    sort(xs);
    assert(xs == ys);
}

Void main()
{
    Testing::init();
    add(@intConv, 1000, "Int/String");
    add(@floatConv, 1000, "Float/String");
    add(@rev, 1000, "reverse");
    add(@testRep, 100, "rep");
    add(@testSort, 100, "sort");

    if (!Testing::run()) {
	exit(1);
    }
}