aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/maybe_ut.pyx
diff options
context:
space:
mode:
authorMikhail Borisov <borisov.mikhail@gmail.com>2022-02-10 16:45:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:39 +0300
commita6a92afe03e02795227d2641b49819b687f088f8 (patch)
treef6984a1d27d5a7ec88a6fdd6e20cd5b7693b6ece /util/generic/maybe_ut.pyx
parentc6dc8b8bd530985bc4cce0137e9a5de32f1087cb (diff)
downloadydb-a6a92afe03e02795227d2641b49819b687f088f8.tar.gz
Restoring authorship annotation for Mikhail Borisov <borisov.mikhail@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/generic/maybe_ut.pyx')
-rw-r--r--util/generic/maybe_ut.pyx370
1 files changed, 185 insertions, 185 deletions
diff --git a/util/generic/maybe_ut.pyx b/util/generic/maybe_ut.pyx
index 2de185c807..c983f11053 100644
--- a/util/generic/maybe_ut.pyx
+++ b/util/generic/maybe_ut.pyx
@@ -1,185 +1,185 @@
-from util.generic.maybe cimport TMaybe, Nothing
-
-import pytest
-import unittest
-
-
-def _check_from_py(TMaybe[int] x):
- return x.Defined()
-
-
-def _check_to_py_value():
- cdef TMaybe[int] tmp = TMaybe[int](42)
- return tmp
-
-
-def _check_to_py_nothing():
- cdef TMaybe[int] tmp = Nothing()
- return tmp
-
-
-class TestMaybe(unittest.TestCase):
-
- def test_ctor1(self):
- cdef TMaybe[int] tmp = TMaybe[int]()
- self.assertFalse(tmp.Defined())
-
- def test_ctor2(self):
- cdef TMaybe[int] tmp = TMaybe[int](42)
- self.assertTrue(tmp.Defined())
- self.assertEquals(tmp.GetRef(), 42)
-
- def test_ctor3(self):
- cdef TMaybe[int] tmp = Nothing()
- self.assertFalse(tmp.Defined())
-
- def test_operator_assign(self):
- cdef TMaybe[int] tmp
- tmp = 42
- self.assertTrue(tmp.Defined())
- self.assertEquals(tmp.GetRef(), 42)
-
- def test_compare(self):
- cdef TMaybe[int] tmp1 = 17
- cdef TMaybe[int] tmp2 = 42
- cdef TMaybe[int] nothing
-
- # ==
- self.assertTrue(tmp1 == 17)
- self.assertTrue(tmp1 == tmp1)
- self.assertTrue(nothing == nothing)
-
- self.assertFalse(tmp1 == 16)
- self.assertFalse(tmp1 == tmp2)
- self.assertFalse(tmp1 == nothing)
-
- # !=
- self.assertTrue(tmp1 != 16)
- self.assertTrue(tmp1 != tmp2)
- self.assertTrue(tmp1 != nothing)
-
- self.assertFalse(tmp1 != 17)
- self.assertFalse(tmp1 != tmp1)
- self.assertFalse(nothing != nothing)
-
- # <
- self.assertTrue(nothing < tmp1)
- self.assertTrue(nothing < tmp2)
- self.assertTrue(tmp1 < tmp2)
- self.assertTrue(nothing < 0)
- self.assertTrue(tmp1 < 18)
-
- self.assertFalse(nothing < nothing)
- self.assertFalse(tmp1 < tmp1)
- self.assertFalse(tmp2 < tmp1)
- self.assertFalse(tmp1 < 16)
-
- # <=
- self.assertTrue(nothing <= nothing)
- self.assertTrue(nothing <= tmp1)
- self.assertTrue(nothing <= tmp2)
- self.assertTrue(tmp1 <= tmp1)
- self.assertTrue(tmp1 <= tmp2)
- self.assertTrue(nothing <= 0)
- self.assertTrue(tmp1 <= 18)
-
- self.assertFalse(tmp2 <= tmp1)
- self.assertFalse(tmp1 <= 16)
-
- # >
- self.assertTrue(tmp1 > nothing)
- self.assertTrue(tmp2 > nothing)
- self.assertTrue(tmp2 > tmp1)
- self.assertTrue(tmp1 > 16)
-
- self.assertFalse(nothing > nothing)
- self.assertFalse(nothing > 0)
- self.assertFalse(tmp1 > tmp1)
- self.assertFalse(tmp1 > tmp2)
- self.assertFalse(tmp1 > 18)
-
- # >=
- self.assertTrue(nothing >= nothing)
- self.assertTrue(tmp1 >= nothing)
- self.assertTrue(tmp2 >= nothing)
- self.assertTrue(tmp2 >= tmp1)
- self.assertTrue(tmp1 >= tmp1)
- self.assertTrue(tmp1 >= 16)
-
- self.assertFalse(nothing >= 0)
- self.assertFalse(tmp1 >= tmp2)
- self.assertFalse(tmp1 >= 18)
-
- def test_construct_in_place(self):
- cdef TMaybe[int] tmp
- tmp.ConstructInPlace(42)
- self.assertTrue(tmp.Defined())
- self.assertEquals(tmp.GetRef(), 42)
-
- def test_clear(self):
- cdef TMaybe[int] tmp = 42
- tmp.Clear()
- self.assertFalse(tmp.Defined())
-
- def test_defined(self):
- cdef TMaybe[int] tmp
- self.assertFalse(tmp.Defined())
- self.assertTrue(tmp.Empty())
- tmp = 42
- self.assertTrue(tmp.Defined())
- self.assertFalse(tmp.Empty())
-
- def test_check_defined(self):
- cdef TMaybe[int] tmp
- with pytest.raises(RuntimeError):
- tmp.CheckDefined()
- tmp = 42
- tmp.CheckDefined()
-
- def test_get(self):
- cdef TMaybe[int] tmp = 42
- cdef int* p = tmp.Get()
- self.assertTrue(p != NULL)
- self.assertEquals(p[0], 42)
-
- def test_get_ref(self):
- cdef TMaybe[int] tmp = 42
- self.assertTrue(tmp.Defined())
- self.assertEquals(tmp.GetRef(), 42)
-
- def test_get_or_else(self):
- cdef TMaybe[int] tmp = 42
- self.assertEquals(tmp.GetOrElse(13), 42)
- tmp.Clear()
- self.assertEquals(tmp.GetOrElse(13), 13)
-
- def test_or_else(self):
- cdef TMaybe[int] tmp = 42
- cdef TMaybe[int] nothing
- self.assertFalse(nothing.OrElse(nothing).Defined())
- self.assertEquals(tmp.OrElse(nothing).GetRef(), 42)
- self.assertEquals(nothing.OrElse(tmp).GetRef(), 42)
- self.assertEquals(tmp.OrElse(tmp).GetRef(), 42)
-
- def test_cast(self):
- cdef TMaybe[int] tmp = 42
- cdef TMaybe[char] tmp2 = tmp.Cast[char]()
- self.assertEquals(tmp2.GetRef(), 42)
-
- def test_swap(self):
- cdef TMaybe[int] tmp1 = 42
- cdef TMaybe[int] tmp2
- tmp2.Swap(tmp1)
- self.assertFalse(tmp1.Defined())
- self.assertEquals(tmp2.GetRef(), 42)
-
- def test_from_py(self):
- self.assertTrue(_check_from_py(42))
- self.assertFalse(_check_from_py(None))
-
- with self.assertRaises(TypeError):
- _check_from_py("ttt")
-
- def test_to_py(self):
- self.assertEquals(_check_to_py_value(), 42)
- self.assertEquals(_check_to_py_nothing(), None)
+from util.generic.maybe cimport TMaybe, Nothing
+
+import pytest
+import unittest
+
+
+def _check_from_py(TMaybe[int] x):
+ return x.Defined()
+
+
+def _check_to_py_value():
+ cdef TMaybe[int] tmp = TMaybe[int](42)
+ return tmp
+
+
+def _check_to_py_nothing():
+ cdef TMaybe[int] tmp = Nothing()
+ return tmp
+
+
+class TestMaybe(unittest.TestCase):
+
+ def test_ctor1(self):
+ cdef TMaybe[int] tmp = TMaybe[int]()
+ self.assertFalse(tmp.Defined())
+
+ def test_ctor2(self):
+ cdef TMaybe[int] tmp = TMaybe[int](42)
+ self.assertTrue(tmp.Defined())
+ self.assertEquals(tmp.GetRef(), 42)
+
+ def test_ctor3(self):
+ cdef TMaybe[int] tmp = Nothing()
+ self.assertFalse(tmp.Defined())
+
+ def test_operator_assign(self):
+ cdef TMaybe[int] tmp
+ tmp = 42
+ self.assertTrue(tmp.Defined())
+ self.assertEquals(tmp.GetRef(), 42)
+
+ def test_compare(self):
+ cdef TMaybe[int] tmp1 = 17
+ cdef TMaybe[int] tmp2 = 42
+ cdef TMaybe[int] nothing
+
+ # ==
+ self.assertTrue(tmp1 == 17)
+ self.assertTrue(tmp1 == tmp1)
+ self.assertTrue(nothing == nothing)
+
+ self.assertFalse(tmp1 == 16)
+ self.assertFalse(tmp1 == tmp2)
+ self.assertFalse(tmp1 == nothing)
+
+ # !=
+ self.assertTrue(tmp1 != 16)
+ self.assertTrue(tmp1 != tmp2)
+ self.assertTrue(tmp1 != nothing)
+
+ self.assertFalse(tmp1 != 17)
+ self.assertFalse(tmp1 != tmp1)
+ self.assertFalse(nothing != nothing)
+
+ # <
+ self.assertTrue(nothing < tmp1)
+ self.assertTrue(nothing < tmp2)
+ self.assertTrue(tmp1 < tmp2)
+ self.assertTrue(nothing < 0)
+ self.assertTrue(tmp1 < 18)
+
+ self.assertFalse(nothing < nothing)
+ self.assertFalse(tmp1 < tmp1)
+ self.assertFalse(tmp2 < tmp1)
+ self.assertFalse(tmp1 < 16)
+
+ # <=
+ self.assertTrue(nothing <= nothing)
+ self.assertTrue(nothing <= tmp1)
+ self.assertTrue(nothing <= tmp2)
+ self.assertTrue(tmp1 <= tmp1)
+ self.assertTrue(tmp1 <= tmp2)
+ self.assertTrue(nothing <= 0)
+ self.assertTrue(tmp1 <= 18)
+
+ self.assertFalse(tmp2 <= tmp1)
+ self.assertFalse(tmp1 <= 16)
+
+ # >
+ self.assertTrue(tmp1 > nothing)
+ self.assertTrue(tmp2 > nothing)
+ self.assertTrue(tmp2 > tmp1)
+ self.assertTrue(tmp1 > 16)
+
+ self.assertFalse(nothing > nothing)
+ self.assertFalse(nothing > 0)
+ self.assertFalse(tmp1 > tmp1)
+ self.assertFalse(tmp1 > tmp2)
+ self.assertFalse(tmp1 > 18)
+
+ # >=
+ self.assertTrue(nothing >= nothing)
+ self.assertTrue(tmp1 >= nothing)
+ self.assertTrue(tmp2 >= nothing)
+ self.assertTrue(tmp2 >= tmp1)
+ self.assertTrue(tmp1 >= tmp1)
+ self.assertTrue(tmp1 >= 16)
+
+ self.assertFalse(nothing >= 0)
+ self.assertFalse(tmp1 >= tmp2)
+ self.assertFalse(tmp1 >= 18)
+
+ def test_construct_in_place(self):
+ cdef TMaybe[int] tmp
+ tmp.ConstructInPlace(42)
+ self.assertTrue(tmp.Defined())
+ self.assertEquals(tmp.GetRef(), 42)
+
+ def test_clear(self):
+ cdef TMaybe[int] tmp = 42
+ tmp.Clear()
+ self.assertFalse(tmp.Defined())
+
+ def test_defined(self):
+ cdef TMaybe[int] tmp
+ self.assertFalse(tmp.Defined())
+ self.assertTrue(tmp.Empty())
+ tmp = 42
+ self.assertTrue(tmp.Defined())
+ self.assertFalse(tmp.Empty())
+
+ def test_check_defined(self):
+ cdef TMaybe[int] tmp
+ with pytest.raises(RuntimeError):
+ tmp.CheckDefined()
+ tmp = 42
+ tmp.CheckDefined()
+
+ def test_get(self):
+ cdef TMaybe[int] tmp = 42
+ cdef int* p = tmp.Get()
+ self.assertTrue(p != NULL)
+ self.assertEquals(p[0], 42)
+
+ def test_get_ref(self):
+ cdef TMaybe[int] tmp = 42
+ self.assertTrue(tmp.Defined())
+ self.assertEquals(tmp.GetRef(), 42)
+
+ def test_get_or_else(self):
+ cdef TMaybe[int] tmp = 42
+ self.assertEquals(tmp.GetOrElse(13), 42)
+ tmp.Clear()
+ self.assertEquals(tmp.GetOrElse(13), 13)
+
+ def test_or_else(self):
+ cdef TMaybe[int] tmp = 42
+ cdef TMaybe[int] nothing
+ self.assertFalse(nothing.OrElse(nothing).Defined())
+ self.assertEquals(tmp.OrElse(nothing).GetRef(), 42)
+ self.assertEquals(nothing.OrElse(tmp).GetRef(), 42)
+ self.assertEquals(tmp.OrElse(tmp).GetRef(), 42)
+
+ def test_cast(self):
+ cdef TMaybe[int] tmp = 42
+ cdef TMaybe[char] tmp2 = tmp.Cast[char]()
+ self.assertEquals(tmp2.GetRef(), 42)
+
+ def test_swap(self):
+ cdef TMaybe[int] tmp1 = 42
+ cdef TMaybe[int] tmp2
+ tmp2.Swap(tmp1)
+ self.assertFalse(tmp1.Defined())
+ self.assertEquals(tmp2.GetRef(), 42)
+
+ def test_from_py(self):
+ self.assertTrue(_check_from_py(42))
+ self.assertFalse(_check_from_py(None))
+
+ with self.assertRaises(TypeError):
+ _check_from_py("ttt")
+
+ def test_to_py(self):
+ self.assertEquals(_check_to_py_value(), 42)
+ self.assertEquals(_check_to_py_nothing(), None)