Пример #1
0
 def test_radd_dif(self):
     """ Test """
     a = [1, 7, 5, 4]
     b = CustomList([8, 5, 11])
     self.assertEqual(a, [1, 7, 5, 4])
     self.assertEqual(b, CustomList([8, 5, 11]))
     self.assertEqual(a - b, CustomList([-7, 2, -6, 4]))
Пример #2
0
 def test_add_sim(self):
     """ Test """
     a = CustomList([1, 7, 5, 4])
     b = CustomList([8, 5, 11])
     self.assertEqual(a, CustomList([1, 7, 5, 4]))
     self.assertEqual(b, CustomList([8, 5, 11]))
     self.assertEqual(a + b, CustomList([9, 12, 16, 4]))
Пример #3
0
 def test_add_dif(self):
     """ Test """
     a = CustomList([1, 7, 5, 4])
     b = [8, 5, 11]
     self.assertEqual(a, CustomList([1, 7, 5, 4]))
     self.assertEqual(b, [8, 5, 11])
     self.assertEqual(a - b, CustomList([-7, 2, -6, 4]))
Пример #4
0
 def test_sub_sim(self):
     """ Test """
     a = CustomList([1, 7, 5, 4])
     b = CustomList([8, 5, 11])
     self.assertEqual(a, CustomList([1, 7, 5, 4]))
     self.assertEqual(b, CustomList([8, 5, 11]))
     self.assertEqual(a - b, CustomList([-7, 2, -6, 4]))
Пример #5
0
 def test_add(self):
     self.assertEqual(self.custom_list + [0, -2, 4, 8],
                      CustomList([1, 0, 7, 8]))
     self.assertEqual(self.custom_list + [], self.custom_list)
     self.assertEqual(self.custom_list + [3, 5, 6], CustomList([4, 7, 9]))
     self.assertEqual(self.custom_list + CustomList([1, -1, 2, 6]),
                      CustomList([2, 1, 5, 6]))
Пример #6
0
def test2():
    a = CustomList(5, 1, 3)
    b = CustomList(1, 2, 7, 3)
    assert type(a) == CustomList
    assert type(b) == CustomList
    assert (a + b) == CustomList(6, 3, 10, 3)
    assert (a - b) == CustomList(4, -1, -4, -3)
    assert a == CustomList(5, 1, 3)
Пример #7
0
    def __str__(self):
        dict_attrs = CustomList()
        for item in self.items():
            dict_attrs.append(str(item))

        els = ', '.join(dict_attrs)
        return_str = f'{self.__class__.__name__}({els})'
        return return_str
Пример #8
0
    def items(self):
        dict_items = CustomList()
        for attr in dir(self):
            if attr.startswith(self._CUST_DICT_ATTR_PREFIX):
                key, val = getattr(self, attr)
                dict_items.append((key, val))

        return dict_items
Пример #9
0
 def test_add(self):
     Ob1 = CustomList([1, 2, 3])
     Ob2 = CustomList([2, 4, 5])
     Ob3 = Ob1 + Ob2
     Ob4 = Ob1 + [2]
     Ob5 = [1, 4] + Ob1
     self.assertEqual(Ob3, [3, 6, 8])
     self.assertEqual(Ob4, [3, 2, 3])
     self.assertEqual(Ob5, [2, 6, 3])
Пример #10
0
 def setUp(self):
     self.basic_custom_list = CustomList([1, 2, 3])
     self.basic_list = [1, 2, 3]
     self.basic_custom_list_2 = CustomList([3, 2, 1])
     self.basic_list_2 = [3, 2, 1]
     self.big_custom_list = CustomList([i for i in range(100)])
     self.big_list = [i for i in range(100)]
     self.small_custom_list = CustomList([1, 2])
     self.small_list = [1, 2]
Пример #11
0
    def test_gt(self):
        """ Test """
        a = CustomList([1, 7, 5, 4])
        b = CustomList([8, 5, 11])
        self.assertEqual(a > b, False)

        a = CustomList([1, 5, 66, 4])
        b = CustomList([8, 5, 11, -7])
        self.assertEqual(a > b, True)
Пример #12
0
 def test_sub(self):
     Ob1 = CustomList([1, 2, 3])
     Ob2 = CustomList([2, 4, 5])
     Ob3 = Ob1 - Ob2
     Ob4 = Ob1 - [2]
     Ob5 = [1, 4] - Ob1
     self.assertEqual(Ob3, [-1, -2, -2])
     self.assertEqual(Ob4, [-1, 2, 3])
     self.assertEqual(Ob5, [0, 2, -3])
 def setUp(self):
     self.l1 = [0, 1, 2, 3, 4]
     self.l2 = [0, 1, 2, 3, 3]
     self.l3 = [0, 1, 2, 3]
     self.l4 = [0, 1, 2, 3, 4, 5]
     self.cl1 = CustomList(self.l1)
     self.cl2 = CustomList(self.l2)
     self.cl3 = CustomList(self.l3)
     self.cl4 = CustomList(self.l4)
Пример #14
0
 def test_compare(self):
     Ob1 = CustomList([1, 2, 3])
     Ob2 = CustomList([2, 4, 5])
     Ob3 = CustomList([6])
     self.assertTrue(Ob1 < Ob2)
     self.assertFalse(Ob1 > Ob2)
     self.assertTrue(Ob1 != Ob2)
     self.assertTrue(Ob1 <= Ob2)
     self.assertFalse(Ob1 >= Ob2)
     self.assertTrue(Ob1 == Ob3)
Пример #15
0
    def test_second_lower(self):
        ans = CustomList([1, 3] + [i for i in range(2, 100)])
        res = self.big_custom_list + self.small_list
        self.assertListEqual(list(res), list(ans))

        ans = CustomList([1, 3] + [i for i in range(2, 100)])
        res = self.big_list + self.small_custom_list
        self.assertListEqual(list(res), list(ans))

        ans = CustomList([1, 3] + [i for i in range(2, 100)])
        res = self.big_custom_list + self.small_custom_list
        self.assertListEqual(list(res), list(ans))
Пример #16
0
    def test_first_lower(self):
        ans = CustomList([1, 1] + [i for i in range(-2, -100, -1)])
        res = self.small_list - self.big_custom_list
        self.assertListEqual(list(res), list(ans))

        ans = CustomList([1, 1] + [i for i in range(-2, -100, -1)])
        res = self.small_custom_list - self.big_list
        self.assertListEqual(list(res), list(ans))

        ans = CustomList([1, 1] + [i for i in range(-2, -100, -1)])
        res = self.small_custom_list - self.big_custom_list
        self.assertListEqual(list(res), list(ans))
Пример #17
0
class CarShop(object):
    _items = CustomList(Car)

    def add(self, name, price, placa):
        """
            Method add a new car on the CarShop.
        """
        self._items.append(Car(name=name, price=price, placa=placa))

    def __getattr__(self, name):
        """
            Method get information about specific car.
        """
        for car in self._items:
            if license_plate_pattern(car.placa) == license_plate_pattern(name):
                return car
        raise Exception('%s car not found.' % name.upper())

    def __len__(self):
        """
            Method get the quantity of the cars in CarShop.
        """
        return len(self._items)

    @property
    def total(self):
        """
            Method get the total cost of the cars in CarShop.
        """
        return sum(car.price for car in self._items)
Пример #18
0
class Test:
    drivers = [CustomList(), HashTable(5), BuiltinList()]

    @pytest.mark.parametrize("driver", drivers)
    def test_drivers(self, driver):
        driver = deepcopy(driver)

        to_add = [1, 2, 1, 6]

        for value in to_add:
            driver.add(value)
        assert len(driver) == len(to_add)
        assert sorted(list(driver)) == sorted(to_add)

        to_remove = [1, 2, 5]
        to_leave = [1, 6]

        for value in to_remove:
            driver.remove(value)
        assert len(driver) == len(to_leave)
        assert sorted(list(driver)) == sorted(to_leave)

        assert driver.find(6) == 6
        assert driver.find(5) is None

    @pytest.mark.parametrize("driver", drivers)
    def test_dict(self, driver):
        driver = deepcopy(driver)
        d = Dict(driver)

        for key, value in [(1, 6), (2, 7), (1, 5), (6, 8)]:
            d.set(key, value)
        assert sorted(d.items()) == sorted([(2, 7), (1, 5), (6, 8)])

        for key in [2]:
            d.remove(key)
        assert sorted(d.items()) == sorted([(1, 5), (6, 8)])

        for key, value in [(1, 5), (2, None), (6, 8)]:
            assert d.get(key) == value

    @pytest.mark.parametrize("driver", drivers)
    def test_set(self, driver):
        driver = deepcopy(driver)
        d = Set(driver)

        for key in [1, 2, 1, 6]:
            d.add(key)
        for key, response in [(1, True), (2, True), (5, False)]:
            assert d.isin(key) == response

        for key in [1, 2, 5]:
            d.remove(key)
        for key, response in [(1, True), (2, False), (6, True)]:
            assert d.isin(key) == response
Пример #19
0
def test3():
    a = CustomList(1, 2, 7)
    b = CustomList(1, 2, 7, 3)
    assert (a == b) is False
    a.append(3)
    assert (a == b) is True
    a.pop()
    assert (a <= b) is True
    assert (a < b) is True
    assert (a == b) is False
Пример #20
0
    def test_immutability(self):
        self.assertEqual(self.custom_list + [0, -2, 4, 8],
                         CustomList([1, 0, 7, 8]))
        self.assertEqual(self.custom_list, CustomList([1, 2, 3]))

        self.assertEqual([-3, 5] + self.custom_list, CustomList([-2, 7, 3]))
        self.assertEqual(self.custom_list, CustomList([1, 2, 3]))

        self.assertEqual(self.custom_list - [3, 2, 1], CustomList([-2, 0, 2]))
        self.assertEqual(self.custom_list, CustomList([1, 2, 3]))

        self.assertEqual([2, 8, 12, 3] - self.custom_list,
                         CustomList([1, 6, 9, 3]))
        self.assertEqual(self.custom_list, CustomList([1, 2, 3]))
Пример #21
0
 def test_neg(self):
     self.assertEqual(-self.custom_list, CustomList([-1, -2, -3]))
     self.assertEqual(-CustomList([]), CustomList([]))
Пример #22
0
 def setUp(self):
     self.custom_list = CustomList([1, 2, 3])
Пример #23
0
 def test_comp(self):
     self.assertEqual(CustomList([2, 8, 1]), CustomList([3, 6, 2]))
     self.assertNotEqual(CustomList([-1, 3, 5]), CustomList([2, 3]))
     self.assertGreater(CustomList([1, 4, 5]), CustomList([]))
     self.assertGreaterEqual(CustomList([]), CustomList([2, -2]))
     self.assertLess(CustomList([1, 2, 1]), CustomList([2, 3, 4]))
     self.assertLessEqual(CustomList([3]), CustomList([6, 7]))
Пример #24
0
 def test_sub(self):
     self.assertEqual(self.custom_list - [3, 2, 1], CustomList([-2, 0, 2]))
     self.assertEqual(self.custom_list - [], self.custom_list)
     self.assertEqual(self.custom_list - [-1, -2], CustomList([2, 4, 3]))
     self.assertEqual(self.custom_list - CustomList([3, 1, 9, 3]),
                      CustomList([-2, 1, -6, -3]))
 def setup_list(self, *args):
     custom_list = CustomList()
     [custom_list.append(x) for x in args]
     return custom_list
Пример #26
0
from vue import VueComponent

from custom_list import CustomList

CustomList.register("custom-list")

class App(VueComponent):
    template = """<custom-list listName="test_list"></custom-list>"""




App("#app")

Пример #27
0
def test1():
    x = CustomList(1, 2, 3, 4, 5, 6)
    assert type(x) == CustomList
    assert len(x) == 6
    x.append(10)
    assert len(x) == 7
Пример #28
0
 def test_eq(self):
     ans = CustomList([0, 0, 0])
     res = self.basic_custom_list - self.basic_custom_list
     self.assertListEqual(list(res), list(ans))
Пример #29
0
 def test_list_and_custom(self):
     ans = CustomList([2, 0, -2])
     res = self.basic_list_2 - self.basic_custom_list
     self.assertListEqual(list(res), list(ans))
Пример #30
0
 def test_custom_and_list(self):
     ans = CustomList([-2, 0, 2])
     res = self.basic_custom_list - self.basic_list_2
     self.assertListEqual(list(res), list(ans))