-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Gobot1234 <[email protected]>
- Loading branch information
1 parent
27cf6f0
commit 8976936
Showing
5 changed files
with
177 additions
and
22 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 |
---|---|---|
|
@@ -9,6 +9,7 @@ venv | |
.mypy_cache | ||
.pytest_cache | ||
.ruff_cache | ||
.hypothesis | ||
|
||
.DS_Store | ||
Thumbs.db | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1,16 +1,82 @@ | ||
# pyright: reportUnusedExpression = false | ||
from decimal import Decimal | ||
from fractions import Fraction | ||
|
||
import pytest | ||
from hypothesis import given, strategies as st | ||
|
||
from steam.ext import tf2 | ||
|
||
client = tf2.Client() | ||
|
||
|
||
def test_metal_initializations(): | ||
assert tf2.Metal("0.77") == tf2.Metal(0.77) | ||
assert tf2.Metal(Fraction(7, 9)) == tf2.Metal(0.77) | ||
assert tf2.Metal(Decimal(0.77)) == tf2.Metal(0.77) | ||
assert tf2.Metal(Fraction(18, 9)) == tf2.Metal(2) | ||
assert tf2.Metal(1.99) == tf2.Metal(2) | ||
|
||
|
||
def test_metal_addition(): | ||
assert tf2.Metal(1.11) + tf2.Metal(1) == tf2.Metal(2.11) | ||
assert tf2.Metal(1.88) + tf2.Metal(1.11) == tf2.Metal(3) | ||
assert tf2.Metal(1.11) + tf2.Metal(1.11) == tf2.Metal(2.22) | ||
assert tf2.Metal(1.88) + tf2.Metal(1.88) == tf2.Metal(3.77) | ||
assert tf2.Metal(1.00) + tf2.Metal(0) == tf2.Metal(1) | ||
# TODO test inf prec | ||
|
||
|
||
def test_metal_subtraction(): | ||
assert tf2.Metal(1.11) - tf2.Metal(1) == tf2.Metal(0.11) | ||
assert tf2.Metal(1.11) - tf2.Metal(0) == tf2.Metal(1.11) | ||
|
||
assert tf2.Metal(1) - tf2.Metal(1.11) == tf2.Metal(-0.11) | ||
|
||
|
||
def test_metal_multiplication(): | ||
assert tf2.Metal(3) * 3 == tf2.Metal(9) | ||
assert tf2.Metal(0) * 3 == tf2.Metal(0) | ||
|
||
assert tf2.Metal(3) * -1 == tf2.Metal(-3) | ||
|
||
|
||
def test_metal_division(): | ||
assert tf2.Metal(2) / 2 == tf2.Metal(1) | ||
assert tf2.Metal(2) / -2 == tf2.Metal(-1) | ||
|
||
with pytest.raises(ValueError): | ||
tf2.Metal(5) / 2 | ||
with pytest.raises(ValueError): | ||
tf2.Metal(5) / -2 | ||
with pytest.raises(ValueError): | ||
-tf2.Metal(5) / 2 | ||
|
||
with pytest.raises(ZeroDivisionError): | ||
tf2.Metal(2) / 0 | ||
|
||
|
||
def test_metal_invalid_values(): | ||
with pytest.raises(ValueError): | ||
tf2.Metal(1.12) | ||
with pytest.raises(ValueError): | ||
tf2.Metal(1.115) | ||
with pytest.raises(ValueError): | ||
tf2.Metal(Fraction(1, 10)) | ||
|
||
|
||
def test_str(): | ||
assert str(tf2.Metal(1.22)) == "1.22" | ||
assert str(tf2.Metal(1.33)) == "1.33" | ||
assert str(tf2.Metal(1000)) == "1000.00" | ||
|
||
|
||
# some property tests | ||
@given(st.integers(), st.integers()) | ||
def test_ints_are_commutative(x: int, y: int): | ||
assert x + y == y + x | ||
|
||
|
||
@given(x=st.integers(), y=st.integers()) | ||
def test_ints_cancel(x: int, y: int): | ||
assert (tf2.Metal(x) + tf2.Metal(y)) - tf2.Metal(y) == tf2.Metal(x) |