From: Chris Duncan Date: Thu, 3 Sep 2026 05:44:01 +0000 (-0700) Subject: Fix unit test ranges. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=d4c68e7505fbb6f25d3e68fa2d7ac0e504753266;p=nano25519.git Fix unit test ranges. --- diff --git a/src/assembly/tests.ts b/src/assembly/tests.ts index 2e56d66..cefee97 100644 --- a/src/assembly/tests.ts +++ b/src/assembly/tests.ts @@ -17,7 +17,7 @@ const zeros = new StaticArray(32).fill(0) const ones = new StaticArray(32).fill(255) const random = new StaticArray(32) for (let i = 0; i < 32; i++) { - random[i] = u8(Math.random() * 255) + random[i] = u8(Math.random() * 256) } const vectors = ['zeros', 'ones', 'random',] @@ -25,16 +25,16 @@ const expecteds = [zeros, ones, random,] const actual = new StaticArray(32) -for (let i = 0; i < vectors.length; i++) { - const vector = vectors[i] - const expected = expecteds[i] +for (let v = 0; v < vectors.length; v++) { + const vector = vectors[v] + const expected = expecteds[v] memory.copy(changetype(actual), changetype(expected), 32) + if (!equalbytes(actual, expected, 32)) { + throw new Error(`equalbytes build error: ${vector} failed instead of passing (expected [${expected}], actual [${actual}])`) + } for (let i = 0; i < 32; i++) { - if (!equalbytes(actual, expected, 32)) { - throw new Error(`equalbytes build error: ${vector} failed instead of passing (expected [${expected}], actual [${actual}])`) - } - for (let j: u8 = 1; j < 255; j++) { - actual[i] ^= j + for (let j = 1; j < 256; j++) { + actual[i] ^= u8(j) if (equalbytes(actual, expected, 32)) { throw new Error(`equalbytes build error: ${vector} passed instead of failing (expected [${expected}], actual [${actual}])`) }