Skip to content

Commit

Permalink
test(test_core): use plain random instead of numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
Rizhiy committed Jul 28, 2024
1 parent 337727b commit ec4049f
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import random
import resource

import numpy as np

from class_cache import Cache, CacheWithDefault

TEST_DICT = {1: "foo", "foo": "bar", (2, 3): [4, 5]}
Expand Down Expand Up @@ -128,20 +127,19 @@ def get_max_memory_used() -> int:
return resource.getrusage(resource.RUSAGE_SELF).ru_maxrss


def get_random_array(rng: np.random.Generator) -> np.ndarray:
return rng.uniform(size=1024)
def get_random_array() -> list[int]:
return [random.randint(0, 1024) for _ in range(1024)] # noqa: S311


def test_max_memory_usage():
cache = get_new_cache(max_items=16)
rng = np.random.default_rng()
# Get an array to account for generation in memory calculation
_ = get_random_array(rng)
_ = get_random_array()
starting_max_memory = get_max_memory_used()
for idx in range(1024):
cache[idx] = get_random_array(rng)
cache[idx] = get_random_array()
end_max_memory_usage = get_max_memory_used()
assert end_max_memory_usage - starting_max_memory < 1_000
assert end_max_memory_usage - starting_max_memory < 3_000


# TODO: Add parallel test for cache as well (threading)

0 comments on commit ec4049f

Please sign in to comment.