| 1 |
# This test code was written by the `hypothesis.extra.ghostwriter` module |
| 2 |
# and is provided under the Creative Commons Zero public domain dedication. |
| 3 |
|
| 4 |
import operator |
| 5 |
from hypothesis import given, strategies as st |
| 6 |
|
| 7 |
# TODO: replace st.nothing() with an appropriate strategy |
| 8 |
|
| 9 |
mul_operands = st.nothing() |
| 10 |
|
| 11 |
|
| 12 |
@given(a=mul_operands, b=mul_operands, c=mul_operands) |
| 13 |
def test_associative_binary_operation_mul(a, b, c): |
| 14 |
left = operator.mul(a, operator.mul(b, c)) |
| 15 |
right = operator.mul(operator.mul(a, b), c) |
| 16 |
assert left == right, (left, right) |
| 17 |
|
| 18 |
|
| 19 |
@given(a=mul_operands, b=mul_operands) |
| 20 |
def test_commutative_binary_operation_mul(a, b): |
| 21 |
left = operator.mul(a, b) |
| 22 |
right = operator.mul(b, a) |
| 23 |
assert left == right, (left, right) |
| 24 |
|
| 25 |
|
| 26 |
@given(a=mul_operands) |
| 27 |
def test_identity_binary_operation_mul(a): |
| 28 |
identity = "identity element here" |
| 29 |
assert a == operator.mul(a, identity) |
| 30 |
assert a == operator.mul(identity, a) |
| 31 |
|
| 32 |
|
| 33 |
@given(a=mul_operands, b=mul_operands, c=mul_operands) |
| 34 |
def test_add_distributes_over_binary_operation_mul(a, b, c): |
| 35 |
left = operator.mul(a, operator.add(b, c)) |
| 36 |
ldist = operator.add(operator.mul(a, b), operator.mul(a, c)) |
| 37 |
assert ldist == left, (ldist, left) |
| 38 |
|
| 39 |
right = operator.mul(operator.add(a, b), c) |
| 40 |
rdist = operator.add(operator.mul(a, c), operator.mul(b, c)) |
| 41 |
assert rdist == right, (rdist, right) |