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 all 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
29 changes: 29 additions & 0 deletions test/unit/test_utility/test_utility_hash_big_ndarray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""テストユーティリティ `summarize_big_ndarray()` のテスト"""

from test.utility import summarize_big_ndarray

import numpy as np


def test_summarize_big_ndarray_raw_small_array() -> None:
"""`summarize_big_ndarray()` は小さい NumPy 配列を要約しない。"""
# Inputs
target = np.array([111.111])
# Tests
assert summarize_big_ndarray(target) == np.array([111.111])


def test_summarize_big_ndarray_raw_big_array() -> None:
"""`summarize_big_ndarray()` は大きい NumPy 配列を要約する。"""
# Inputs
target = np.ones([10, 10, 10])
# Expects
true_hash_header = "MD5:"
true_shape = target.shape
# Outputs
summary = summarize_big_ndarray(target)
hash_header = summary["hash"][:4]
shape = tuple(summary["shape"])
# Tests
assert true_hash_header == hash_header
assert true_shape == shape
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""テストユーティリティのテスト"""
"""テストユーティリティ `round_floats()` のテスト"""

from test.utility import round_floats

import numpy as np


def test_round_floats_raw_float() -> None:
"""`round_floats()` は値を丸める。"""
Expand Down Expand Up @@ -31,12 +33,20 @@ 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
Expand Down
Loading