summaryrefslogtreecommitdiffstats
path: root/toolkit/components/uniffi-fixtures/arithmetic/tests/bindings/test_arithmetic.py
blob: e1b4f7127748e00aca6db4621b28da0d5468a527 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from arithmetic import InternalError, add, div, equal, sub

try:
    add(18446744073709551615, 1)
    assert not ("Should have thrown a IntegerOverflow exception!")
except ArithmeticError.IntegerOverflow:
    # It's okay!
    pass

assert add(2, 4) == 6
assert add(4, 8) == 12

try:
    sub(0, 1)
    assert not ("Should have thrown a IntegerOverflow exception!")
except ArithmeticError.IntegerOverflow:
    # It's okay!
    pass

assert sub(4, 2) == 2
assert sub(8, 4) == 4

assert div(8, 4) == 2

try:
    div(8, 0)
except InternalError:
    # It's okay!
    pass
else:
    assert not ("Should have panicked when dividing by zero")

assert equal(2, 2)
assert equal(4, 4)

assert not equal(2, 4)
assert not equal(4, 8)