-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: テストユーティリティのテストを追加 * fix: lint
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |