sh_cpl/unittests/unittests_query/enumerable_test_case.py

36 lines
1019 B
Python
Raw Permalink Normal View History

2022-09-13 12:07:04 +02:00
import unittest
2022-09-13 19:33:26 +02:00
from cpl_query.enumerable.enumerable import Enumerable
2022-09-13 12:07:04 +02:00
class EnumerableTestCase(unittest.TestCase):
def setUp(self) -> None:
self._list = Enumerable(int, list(range(1, 4)))
2022-09-13 12:07:04 +02:00
def test_append(self):
self.assertEqual(self._list.to_list(), [1, 2, 3])
2023-02-20 15:55:20 +01:00
self.assertRaises(Exception, lambda v: self._list.add(v), "3")
2022-09-13 12:07:04 +02:00
def test_default(self):
2022-09-13 19:33:26 +02:00
self.assertEqual(Enumerable.empty().to_list(), [])
self.assertEqual(Enumerable.range(0, 100).to_list(), list(range(0, 100)))
2022-09-13 12:07:04 +02:00
2022-12-05 14:12:20 +01:00
# def test_iter(self):
# n = 0
# elements = Enumerable.range(0, 100)
# while n < 100:
# self.assertEqual(elements.next(), n)
# n += 1
2022-09-13 12:07:04 +02:00
def test_for(self):
n = 0
2022-09-13 19:33:26 +02:00
for i in Enumerable.range(0, 100):
2022-09-13 12:07:04 +02:00
self.assertEqual(i, n)
n += 1
def test_get(self):
2022-09-13 19:33:26 +02:00
self.assertEqual(self._list.element_at(2), [1, 2, 3][2])
2022-09-13 12:07:04 +02:00
def test_count(self):
self.assertEqual(self._list.count(), 3)