Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

整理: NumPy 向けスナップショットユーティリティを追加 #1356

Merged
merged 17 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions test/test_utility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""テストユーティリティのテスト"""

from test.utility import round_floats
from test.utility import hash_big_ndarray, round_floats

import numpy as np

# round_floats()


def test_round_floats_raw_float() -> None:
Expand Down Expand Up @@ -31,13 +35,45 @@ def test_round_floats_dict() -> None:
assert round_floats(target, 2) == {"hello": 1.11}


def test_round_floats_numpy() -> None:
"""`round_floats()` は NumPy 値を丸める。"""
# Inputs
target = np.array([111.111])
# Tests
assert round_floats(target, 2) == np.array([111.11])


def test_round_floats_nested() -> None:
"""`round_floats()` はネストしたオブジェクト内の値を丸める。"""
# Inputs
target = [1.111, {"hello": 1.111, "world": [1.111]}]
target = [1.111, {"hello": 1.111, "world": [1.111]}, np.array([1.111])]
# Expects
true_rounded = [1.11, {"hello": 1.11, "world": [1.11]}]
true_rounded = [1.11, {"hello": 1.11, "world": [1.11]}, np.array([1.11])]
# Outputs
rounded = round_floats(target, 2)
# Tests
assert true_rounded == rounded


# hash_big_ndarray()
tarepan marked this conversation as resolved.
Show resolved Hide resolved


def test_hash_big_ndarray_raw_small_array() -> None:
"""`hash_big_ndarray()` は小さい NumPy 配列をハッシュ化しない。"""
# Inputs
target = np.array([111.111])
# Tests
assert hash_big_ndarray(target) == np.array([111.111])


def test_hash_big_ndarray_raw_big_array() -> None:
"""`hash_big_ndarray()` は大きい NumPy 配列をハッシュ化する。"""
# Inputs
target = np.ones([10, 10, 10])
# Expects
true_hashed_header = "MD5:"
# Outputs
hashed = hash_big_ndarray(target)
hashed_header = hashed[:4]
# Tests
assert true_hashed_header == hashed_header
Loading