-
Notifications
You must be signed in to change notification settings - Fork 933
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle
integer_squareroot
bound case
- Loading branch information
Showing
3 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
23 changes: 23 additions & 0 deletions
23
tests/core/pyspec/eth2spec/test/phase0/unittests/math/test_integer_squareroot.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import random | ||
from math import isqrt | ||
from eth2spec.test.context import ( | ||
spec_test, | ||
single_phase, | ||
with_all_phases, | ||
) | ||
|
||
|
||
@with_all_phases | ||
@spec_test | ||
@single_phase | ||
def test_integer_squareroot(spec): | ||
values = [0, 100, 2**64 - 2, 2**64 - 1] | ||
for n in values: | ||
uint64_n = spec.uint64(n) | ||
assert spec.integer_squareroot(uint64_n) == isqrt(n) | ||
|
||
rng = random.Random(5566) | ||
for _ in range(10): | ||
n = rng.randint(0, 2**64 - 1) | ||
uint64_n = spec.uint64(n) | ||
assert spec.integer_squareroot(uint64_n) == isqrt(n) |