#!/usr/bin/env maiascript

tries = 10

if (system.argc == 2) {
    tries = system.argv[1]
}

system.println("Testing loop statements " + tries + " times.")

system.println("while...")
test (tries; "81"; 0) {
    a = core.matrix(0, 10, 10)
    i = 0
    while (i < 10) {
        j = 0
        while (j < 10) {
            a[i , j] = core.toString(i * j)
            j = j + 1
        }
        i = i + 1
    }
    core.toString(a[9 ,9])
} catch (v) {
    system.print("TEST: Fail testing statements while.")
    system.print("      Expected result " + core.testResult.expected)
    system.print("      But got " + core.testResult.obtained)
}

system.println("do...")
test (tries; "81"; 0) {
    a = core.matrix(0, 10, 10)
    i = 0
    do {
        j = 0
        do {
            a[i , j] = core.toString(i * j)
            j = j + 1
        } while (j < 10)
        i = i + 1
    } while (i < 10)
    core.toString(a[9 ,9])
} catch (v) {
    system.print("TEST: Fail testing statements do.")
    system.print("      Expected result " + core.testResult.expected)
    system.print("      But got " + core.testResult.obtained)
}

system.println("for...")
test (tries; "81"; 0) {
    a = core.matrix(0, 10, 10)
    for (i = 0; i < 10; i = i + 1) {
        for (j = 0; j < 10; j = j + 1) {
            a[i , j] = core.toString(i * j)
        }
    }
    core.toString(a[9 ,9])
} catch (v) {
    system.print("TEST: Fail testing statements for.")
    system.print("      Expected result " + core.testResult.expected)
    system.print("      But got " + core.testResult.obtained)
}

system.println("foreach...")
test (tries; "y2"; 0) {
    a = {"x": 1, "y": 2}
    foreach (a; k; v) {
        z = k + core.toString(v)
    }
} catch (v) {
    system.print("TEST: Fail testing statements for.")
    system.print("      Expected result " + core.testResult.expected)
    system.print("      But got " + core.testResult.obtained)
}
