Skip to content

Commit

Permalink
Add random stubs and test for random
Browse files Browse the repository at this point in the history
  • Loading branch information
ktnlvr committed Jun 2, 2023
1 parent 74b47be commit 019fd44
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
22 changes: 22 additions & 0 deletions pystd/random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def seed(a: int, version: int = 2):
...


def getstate() -> object:
...


def setstate(state: object):
...


def randbytes(n: int) -> bytes:
...


def getrandbits(k) -> int:
...


def random() -> float:
...
3 changes: 0 additions & 3 deletions tests/test_always_pass.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
def test_always_pass():
assert True

def always_fails():
assert False
27 changes: 27 additions & 0 deletions tests/test_random.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pystd import random


def test_same_seed_same_random():
random.seed(4)
a = random.random()
assert type(a) is int
random.seed(4)
b = random.random()
assert type(b) is int
assert a == b


def test_state_setter():
state = random.random()
random.setstate(state)
assert random.getstate() == state


def test_randbits_len():
random.seed(10)

for i in range(10000):
bits = random.getrandbits(i)
assert type(bits) is int
assert bits >= 0
assert bits.bit_count() <= i

0 comments on commit 019fd44

Please sign in to comment.