Skip to content

Commit

Permalink
整理: NumPy 向けスナップショットユーティリティを追加 (#1356)
Browse files Browse the repository at this point in the history
* refactor: `round_float()` ユーティリティに NumPy 対応を追加

* refactor: `hash_big_ndarray()` ユーティリティを追加

* refactor: TTS 出力スナップショットをハッシュ化

* fix: テスト名の重複を修正

* refactror: ユーティリティのテストを分割

* refactor: テスト用ユーティリティのテストを移動

* refactor: `summarize_big_ndarray()` を追加

* refactor: `round_floats()` 内の判定順序を変更

* fix: ndarray の float 判定を追加

* refactor: docstring を明確化

Co-authored-by: Hiroshiba <[email protected]>

* fix: `summarize_big_ndarray()` 出力型を変更

Co-authored-by: Hiroshiba <[email protected]>

* fix: `summarize_big_ndarray()` 出力型の変更を反映

* fix: lint

---------

Co-authored-by: Hiroshiba <[email protected]>
  • Loading branch information
tarepan and Hiroshiba authored Jun 16, 2024
1 parent bcb0c30 commit e3d49cc
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 12,808 deletions.
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

0 comments on commit e3d49cc

Please sign in to comment.