Skip to content

Commit bf0daab

Browse files
committed
split math_basics.py to proper files
1 parent d62ea37 commit bf0daab

File tree

4 files changed

+64
-72
lines changed

4 files changed

+64
-72
lines changed

extra_tests/snippets/builtin_pow.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
assert pow(41, 7, 2) == 1
77
assert pow(7, 2, 49) == 0
88

9+
assert pow(0, 0) == 1
10+
assert pow(2, 2) == 4
11+
assert pow(1, 2.0) == 1.0
12+
assert pow(2.0, 1) == 2.0
13+
assert pow(0, 10**1000) == 0
14+
assert pow(1, 10**1000) == 1
15+
assert pow(-1, 10**1000+1) == -1
16+
assert pow(-1, 10**1000) == 1
17+
18+
assert pow(2, 4, 5) == 1
19+
assert_raises(TypeError, pow, 2, 4, 5.0)
20+
assert_raises(TypeError, pow, 2, 4.0, 5)
21+
assert_raises(TypeError, pow, 2.0, 4, 5)
22+
assert pow(2, -1, 5) == 3
23+
assert_raises(ValueError, pow, 2, 2, 0)
24+
925

1026
assert_almost_equal = assert_equal
1127

extra_tests/snippets/builtin_round.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
from testutils import assert_raises
22

3+
assert round(1.2) == 1
4+
assert round(1.8) == 2
5+
assert round(0.5) == 0
6+
assert round(1.5) == 2
7+
assert round(-0.5) == 0
8+
assert round(-1.5) == -2
9+
10+
# ValueError: cannot convert float NaN to integer
11+
assert_raises(ValueError, round, float('nan'))
12+
# OverflowError: cannot convert float infinity to integer
13+
assert_raises(OverflowError, round, float('inf'))
14+
# OverflowError: cannot convert float infinity to integer
15+
assert_raises(OverflowError, round, -float('inf'))
16+
317
assert round(0) == 0
418
assert isinstance(round(0), int)
519
assert round(0.0) == 0

extra_tests/snippets/math_basics.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

extra_tests/snippets/operator.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from testutils import assert_raises
2+
3+
assert -3 // 2 == -2
4+
assert -3 % 2 == 1
5+
6+
a = 4
7+
8+
assert a ** 3 == 64
9+
assert a * 3 == 12
10+
assert a / 2 == 2
11+
assert 2 == a / 2
12+
assert a % 3 == 1
13+
assert a - 3 == 1
14+
assert -a == -4
15+
assert +a == 4
16+
17+
# bitwise
18+
19+
assert 8 >> 3 == 1
20+
assert 8 << 3 == 64
21+
22+
# Left shift raises type error
23+
assert_raises(TypeError, lambda: 1 << 0.1)
24+
assert_raises(TypeError, lambda: 1 << "abc")
25+
26+
# Right shift raises type error
27+
assert_raises(TypeError, lambda: 1 >> 0.1)
28+
assert_raises(TypeError, lambda: 1 >> "abc")
29+
30+
# Left shift raises value error on negative
31+
assert_raises(ValueError, lambda: 1 << -1)
32+
33+
# Right shift raises value error on negative
34+
assert_raises(ValueError, lambda: 1 >> -1)

0 commit comments

Comments
 (0)