1 from __future__
import annotations
5 from pybind11_tests
import ConstructorStats
6 from pybind11_tests
import operators
as m
15 assert str(v1) ==
"[1.000000, 2.000000]"
16 assert str(v2) ==
"[3.000000, -1.000000]"
18 assert str(-v2) ==
"[-3.000000, 1.000000]"
20 assert str(v1 + v2) ==
"[4.000000, 1.000000]"
21 assert str(v1 - v2) ==
"[-2.000000, 3.000000]"
22 assert str(v1 - 8) ==
"[-7.000000, -6.000000]"
23 assert str(v1 + 8) ==
"[9.000000, 10.000000]"
24 assert str(v1 * 8) ==
"[8.000000, 16.000000]"
25 assert str(v1 / 8) ==
"[0.125000, 0.250000]"
26 assert str(8 - v1) ==
"[7.000000, 6.000000]"
27 assert str(8 + v1) ==
"[9.000000, 10.000000]"
28 assert str(8 * v1) ==
"[8.000000, 16.000000]"
29 assert str(8 / v1) ==
"[8.000000, 4.000000]"
30 assert str(v1 * v2) ==
"[3.000000, -2.000000]"
31 assert str(v2 / v1) ==
"[3.000000, -0.500000]"
40 assert str(v1) ==
"[7.000000, 0.000000]"
42 assert str(v1) ==
"[4.000000, 1.000000]"
44 assert str(v1) ==
"[8.000000, 2.000000]"
46 assert str(v1) ==
"[0.500000, 0.125000]"
48 assert str(v1) ==
"[1.500000, -0.125000]"
50 assert str(v2) ==
"[2.000000, 8.000000]"
53 assert cstats.alive() == 3
55 assert cstats.alive() == 2
57 assert cstats.alive() == 1
59 assert cstats.alive() == 0
60 assert cstats.values() == [
61 "[1.000000, 2.000000]",
62 "[3.000000, -1.000000]",
63 "[1.000000, 2.000000]",
64 "[-3.000000, 1.000000]",
65 "[4.000000, 1.000000]",
66 "[-2.000000, 3.000000]",
67 "[-7.000000, -6.000000]",
68 "[9.000000, 10.000000]",
69 "[8.000000, 16.000000]",
70 "[0.125000, 0.250000]",
71 "[7.000000, 6.000000]",
72 "[9.000000, 10.000000]",
73 "[8.000000, 16.000000]",
74 "[8.000000, 4.000000]",
75 "[3.000000, -2.000000]",
76 "[3.000000, -0.500000]",
77 "[6.000000, -2.000000]",
79 assert cstats.default_constructions == 0
80 assert cstats.copy_constructions == 0
81 assert cstats.move_constructions >= 10
82 assert cstats.copy_assignments == 0
83 assert cstats.move_assignments == 0
87 """#393: need to return NotSupported to ensure correct arithmetic operator behavior"""
89 c1, c2 = m.C1(), m.C2()
97 """#328: first member in a class can't be used in operators"""
104 assert m.get_NestA(a) == 13
106 assert m.get_NestA(b.a) == 103
108 assert m.get_NestA(c.b.a) == 1003
110 assert m.get_NestB(b) == 3
112 assert m.get_NestB(c.b) == 1
114 assert m.get_NestC(c) == 35
117 assert abase.value == -2
118 a.as_base().value += 44
119 assert abase.value == 42
120 assert c.b.a.as_base().value == -2
121 c.b.a.as_base().value += 44
122 assert c.b.a.as_base().value == 42
129 assert abase.value == 42
135 assert m.Comparable(15)
is not m.Comparable(15)
136 assert m.Comparable(15) == m.Comparable(15)
138 with pytest.raises(TypeError)
as excinfo:
139 hash(m.Comparable(15))
140 assert str(excinfo.value).startswith(
"unhashable type:")
142 for hashable
in (m.Hashable, m.Hashable2):
143 assert hashable(15)
is not hashable(15)
144 assert hashable(15) == hashable(15)
146 assert hash(hashable(15)) == 15
147 assert hash(hashable(15)) ==
hash(hashable(15))
151 with pytest.raises(TypeError)
as excinfo:
152 m.get_unhashable_HashMe_set()
153 assert str(excinfo.value.__cause__).startswith(
"unhashable type:")