Skip to content

Commit 040f50f

Browse files
Merge 1efdd58 into 9f21824
2 parents 9f21824 + 1efdd58 commit 040f50f

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

noir_stdlib/src/field/mod.nr

+16-4
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,31 @@ mod tests {
384384
#[test]
385385
// docs:start:to_be_radix_example
386386
fn test_to_be_radix() {
387-
let field = 2;
387+
// 259, in base 256, big endian, is [1, 3].
388+
// i.e. 3 * 256^0 + 1 * 256^1
389+
let field = 259;
390+
391+
// The radix (in this example, 256) must be a power of 2.
392+
// The length of the returned byte array can be specified to be
393+
// >= the amount of space needed.
388394
let bytes: [u8; 8] = field.to_be_radix(256);
389-
assert_eq(bytes, [0, 0, 0, 0, 0, 0, 0, 2]);
395+
assert_eq(bytes, [0, 0, 0, 0, 0, 0, 1, 3]);
390396
assert_eq(Field::from_be_bytes::<8>(bytes), field);
391397
}
392398
// docs:end:to_be_radix_example
393399

394400
#[test]
395401
// docs:start:to_le_radix_example
396402
fn test_to_le_radix() {
397-
let field = 2;
403+
// 259, in base 256, little endian, is [3, 1].
404+
// i.e. 3 * 256^0 + 1 * 256^1
405+
let field = 259;
406+
407+
// The radix (in this example, 256) must be a power of 2.
408+
// The length of the returned byte array can be specified to be
409+
// >= the amount of space needed.
398410
let bytes: [u8; 8] = field.to_le_radix(256);
399-
assert_eq(bytes, [2, 0, 0, 0, 0, 0, 0, 0]);
411+
assert_eq(bytes, [3, 1, 0, 0, 0, 0, 0, 0]);
400412
assert_eq(Field::from_le_bytes::<8>(bytes), field);
401413
}
402414
// docs:end:to_le_radix_example

0 commit comments

Comments
 (0)