-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds complex math expressions support (#3)
* Creates `_MathExpression` class * Adds `WPS204` to flake8's ignore list * Modifies `_Callable` class to use `_MathExpression` class in the math operations * Fixes type safety tests * Adds tests for `_MathExpression` class * Adds `complex` to `_Number` type alias * Renames file from `test_complex_expression.py` to `test_complex_math_expression.py` * Changes the returns typing hints of math dunder functions from `_Callable` class. Using the return type as `Callable[[_Number], _Number]` we got some mypy errors while composing complex math expressions! * Adds math operations tests for `_Callable` class
- Loading branch information
1 parent
932c513
commit 61582df
Showing
18 changed files
with
337 additions
and
55 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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _ | ||
|
||
|
||
def test_complex_expression(): | ||
"""Ensures that add works correctly.""" | ||
assert ((10 ** 5) / (_ % 3) * 9)(5) == 450000.0 |
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,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _ | ||
|
||
|
||
def test_floordiv(): | ||
"""Ensures that add works correctly.""" | ||
assert (_ // 5)(33) == 6 | ||
|
||
|
||
def test_rfloordiv(): | ||
"""Ensures that add works correctly.""" | ||
assert (_ // 5)(33) == (33 // _)(5) |
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,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _ | ||
|
||
|
||
def test_mod(): | ||
"""Ensures that add works correctly.""" | ||
assert (_ % 35)(140) == 0 | ||
|
||
|
||
def test_rmod(): | ||
"""Ensures that add works correctly.""" | ||
assert (149 % _)(36) == (_ % 36)(149) |
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,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _ | ||
|
||
|
||
def test_mul(): | ||
"""Ensures that add works correctly.""" | ||
assert (_ * 20)(10) == 200 | ||
|
||
|
||
def test_rmul(): | ||
"""Ensures that add works correctly.""" | ||
assert (99 * _)(4) == (_ * 99)(4) |
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,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _ | ||
|
||
|
||
def test_pow(): | ||
"""Ensures that add works correctly.""" | ||
assert (_ ** 3)(2) == 8 | ||
|
||
|
||
def test_rpow(): | ||
"""Ensures that add works correctly.""" | ||
assert (3 ** _)(4) == (_ ** 4)(3) |
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,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _ | ||
|
||
|
||
def test_sub(): | ||
"""Ensures that add works correctly.""" | ||
assert (_ - 10)(1) + 1 == -8 | ||
|
||
|
||
def test_rsub(): | ||
"""Ensures that add works correctly.""" | ||
assert (10 - _)(1) + (_ - 10)(1) == 0 |
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,13 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _ | ||
|
||
|
||
def test_truediv(): | ||
"""Ensures that add works correctly.""" | ||
assert (_ / 6)(39) == 6.5 | ||
|
||
|
||
def test_rtruediv(): | ||
"""Ensures that add works correctly.""" | ||
assert (42 / _)(8) == (_ / 8)(42) |
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,16 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _MathExpression | ||
|
||
|
||
def test_add(): | ||
"""Ensures that add works correctly.""" | ||
add = _MathExpression() + 2 | ||
assert add(1) + 1 == 4 | ||
|
||
|
||
def test_radd(): | ||
"""Ensures that add works correctly.""" | ||
add = _MathExpression() + 2 | ||
radd = 2 + _MathExpression() | ||
assert add(1) == radd(1) |
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,9 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _MathExpression | ||
|
||
|
||
def test_complex_expression(): | ||
"""Ensures that add works correctly.""" | ||
complex_expression = _MathExpression() * 2 + 1 | ||
assert complex_expression(1) == 3 |
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,16 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _MathExpression | ||
|
||
|
||
def test_floordiv(): | ||
"""Ensures that add works correctly.""" | ||
floordiv = _MathExpression() // 2 | ||
assert floordiv(5) == 2 | ||
|
||
|
||
def test_rfloordiv(): | ||
"""Ensures that add works correctly.""" | ||
floordiv = _MathExpression() // 2 | ||
rfloordiv = 5 // _MathExpression() | ||
assert floordiv(5) == rfloordiv(2) |
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,16 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from lambdas import _MathExpression | ||
|
||
|
||
def test_mod(): | ||
"""Ensures that add works correctly.""" | ||
mod = _MathExpression() % 3 | ||
assert mod(25) == 1 | ||
|
||
|
||
def test_rmod(): | ||
"""Ensures that add works correctly.""" | ||
mod = _MathExpression() % 3 | ||
rmod = 25 % _MathExpression() | ||
assert mod(25) == rmod(3) |
Oops, something went wrong.