1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Author: cirakg & claude ai
// Summary: Small helpers shared by the Monkey C unit tests (reading vector rows, reporting mismatches).
import Toybox.Lang;
import Toybox.Test;
(:test)
module TestSupport {
// One row of a TestVectors table.
function row(table as Array, index as Number) as Array {
return table[index] as Array;
}
function str(r as Array, column as Number) as String {
return r[column] as String;
}
function bytes(r as Array, column as Number) as ByteArray {
return Bytes.fromHex(r[column] as String);
}
function num(r as Array, column as Number) as Number {
return r[column] as Number;
}
// Numbers above 2^31 are stored as Long literals in the tables.
function long(r as Array, column as Number) as Long {
return (r[column] as Number or Long).toLong();
}
function alg(r as Array, column as Number) as Hashes.Algorithm {
return r[column] as Hashes.Algorithm;
}
// Compare bytes; log both sides on mismatch. Returns true when equal.
function sameBytes(logger as Test.Logger, what as String, actual as ByteArray, expected as ByteArray) as Boolean {
if (Bytes.equal(actual, expected)) {
return true;
}
logger.error(what + ": got " + Bytes.toHex(actual) + ", expected " + Bytes.toHex(expected));
return false;
}
// Compare strings; log both sides on mismatch.
function sameString(logger as Test.Logger, what as String, actual as String, expected as String) as Boolean {
if (actual.equals(expected)) {
return true;
}
logger.error(what + ": got '" + actual + "', expected '" + expected + "'");
return false;
}
}
|