Skip to content
Snippets Groups Projects
Commit 777eed4f authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

tests for Proxy

parent 1b0cd9d0
No related branches found
No related tags found
No related merge requests found
......@@ -199,6 +199,12 @@ class Proxy(tp.Generic[T]):
def __repr__(self) -> str:
return repr(self.__obj)
def __oct__(self) -> str:
return oct(self.__obj)
def __hex__(self) -> str:
return hex(self.__obj)
def __abs__(self):
return abs(self.__obj)
......@@ -214,6 +220,39 @@ class Proxy(tp.Generic[T]):
def __xor__(self, other):
return self.__obj ^ other
def __radd__(self, other):
return other + self.__obj
def __rsub__(self, other):
return other - self.__obj
def __rmul__(self, other):
return other * self.__obj
def __rtruediv__(self, other):
return other / self.__obj
def __rfloordiv__(self, other):
return other // self.__obj
def __rlshift__(self, other):
return other << self.__obj
def __rrshift__(self, other):
return other >> self.__obj
def __rpow__(self, other):
return other ** self.__obj
def __ror__(self, other):
return other | self.__obj
def __rand__(self, other):
return other & self.__obj
def __rxor__(self, other):
return other ^ self.__obj
def __ior__(self, other) -> 'Proxy':
self.__obj |= other
return self
......
......@@ -18,9 +18,20 @@ class TestProxy(unittest.TestCase):
self.assertEqual(math.floor(a), 5)
self.assertEqual(round(a), 5)
self.assertEqual(math.trunc(a), 5)
self.assertEqual(- 0.25+a, 5.0)
self.assertEqual(2 * a, 10.5)
self.assertEqual(2 / a, 2/5.25)
self.assertEqual(2 // a, 0)
self.assertEqual(2 ** a, 2**5.25)
a = Proxy(2)
self.assertEqual(a & 2, 2)
self.assertEqual(a | 1, 3)
self.assertEqual(a << 1, 4)
self.assertEqual(a >> 1, 1)
self.assertNotEqual(a, 6)
self.assertEqual(2 & a, 2)
self.assertEqual(1 | a, 3)
self.assertEqual(1 << a, 4)
self.assertEqual(1 >> a, 0)
self.assertEqual(hex(a), '0x2')
self.assertEqual(oct(a), '0o2')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment