Skip to content

Commit

Permalink
整理: テストユーティリティのテストを追加 (#1355)
Browse files Browse the repository at this point in the history
* refactor: テストユーティリティのテストを追加

* fix: lint
  • Loading branch information
tarepan authored Jun 2, 2024
1 parent cac896b commit de4c24a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/test_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""テストユーティリティのテスト"""

from test.utility import round_floats


def test_round_floats_raw_float() -> None:
"""`round_floats()` は値を丸める。"""
# Inputs
target = 111.111
# Tests
assert round_floats(target, -2) == 100
assert round_floats(target, -1) == 110
assert round_floats(target, 0) == 111
assert round_floats(target, +1) == 111.1
assert round_floats(target, +2) == 111.11


def test_round_floats_list() -> None:
"""`round_floats()` はリスト内の値を丸める。"""
# Inputs
target = [1.111, 8.888]
# Tests
assert round_floats(target, 2) == [1.11, 8.89]


def test_round_floats_dict() -> None:
"""`round_floats()` は辞書内の値を丸める。"""
# Inputs
target = {"hello": 1.111}
# Tests
assert round_floats(target, 2) == {"hello": 1.11}


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

0 comments on commit de4c24a

Please sign in to comment.