aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/tests')
-rw-r--r--sources/shiboken6/tests/libsample/stdcomplex.cpp5
-rw-r--r--sources/shiboken6/tests/libsample/stdcomplex.h3
-rw-r--r--sources/shiboken6/tests/samplebinding/stdcomplex_test.py5
3 files changed, 13 insertions, 0 deletions
diff --git a/sources/shiboken6/tests/libsample/stdcomplex.cpp b/sources/shiboken6/tests/libsample/stdcomplex.cpp
index c9937b9da..847174387 100644
--- a/sources/shiboken6/tests/libsample/stdcomplex.cpp
+++ b/sources/shiboken6/tests/libsample/stdcomplex.cpp
@@ -11,6 +11,11 @@ StdComplex::StdComplex(double re, double img) noexcept : m_impl(re, img)
{
}
+StdComplex::operator int() const
+{
+ return std::lround(abs_value());
+}
+
StdComplex::StdComplex(const Impl &impl) noexcept : m_impl(impl)
{
}
diff --git a/sources/shiboken6/tests/libsample/stdcomplex.h b/sources/shiboken6/tests/libsample/stdcomplex.h
index 130ca6545..b39b80612 100644
--- a/sources/shiboken6/tests/libsample/stdcomplex.h
+++ b/sources/shiboken6/tests/libsample/stdcomplex.h
@@ -27,6 +27,9 @@ public:
StdComplex pow(const StdComplex &exp) const;
+ operator double() const { return abs_value(); }
+ operator int() const;
+
friend inline bool operator==(const StdComplex &c1, const StdComplex &c2) noexcept
{ return c1.m_impl == c2.m_impl; }
friend inline bool operator!=(const StdComplex &c1, const StdComplex &c2) noexcept
diff --git a/sources/shiboken6/tests/samplebinding/stdcomplex_test.py b/sources/shiboken6/tests/samplebinding/stdcomplex_test.py
index 539463508..0caa9764d 100644
--- a/sources/shiboken6/tests/samplebinding/stdcomplex_test.py
+++ b/sources/shiboken6/tests/samplebinding/stdcomplex_test.py
@@ -25,6 +25,11 @@ class StdComplexTest(unittest.TestCase):
'''Test case for StdComplex class, exercising esoteric number
protocols (Py_nb_). For standard number protocols, see Point.'''
+ def testConversion(self):
+ pt = StdComplex(REAL, IMAG)
+ self.assertEqual(int(pt), int(round(pt.abs_value())))
+ self.assertEqual(float(pt), pt.abs_value())
+
def testAbs(self):
pt = StdComplex(REAL, IMAG)
self.assertEqual(abs(pt), pt.abs_value())