-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3600 from ethereum/integer_squareroot
Handle `integer_squareroot` bound case
- Loading branch information
Showing
5 changed files
with
44 additions
and
12 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
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 |
---|---|---|
|
@@ -89,4 +89,4 @@ | |
# | ||
# Number | ||
# | ||
MAX_UINT_64 = 2**64 - 1 | ||
UINT64_MAX = 2**64 - 1 |
Empty file.
29 changes: 29 additions & 0 deletions
29
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,29 @@ | ||
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) | ||
|
||
try: | ||
spec.integer_squareroot(spec.uint64(2**64)) | ||
assert False | ||
except ValueError: | ||
pass |
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