Ejemplo n.º 1
0
 def test_integer_list_get_biggest__expect_to_return_the_biggest_value(
         self):
     integer_list = IntegerList(1, 10, 3)
     self.assertEqual(10, integer_list.get_biggest())
Ejemplo n.º 2
0
 def test_integer_list_init__when_args_is_not_only_integer__expect_only_integer_to_be_stored(
         self):
     args = [1, 2, 3, "asd"]
     integer_list = IntegerList(*args)
     self.assertEqual(args[:-1], integer_list.get_data())
Ejemplo n.º 3
0
    def test_integer_list_insert__when_value_is_not_int_and_index_is_valid__expect_value_error(
            self):
        integer_list = IntegerList(1, 2, 3)

        with self.assertRaises(ValueError):
            integer_list.insert(1, "asd")
Ejemplo n.º 4
0
    def test_integer_list_get__when_index_is_not_valid__expect_index_error(
            self):
        integer_list = IntegerList(1, 2, 3)

        with self.assertRaises(IndexError):
            integer_list.get(3)
Ejemplo n.º 5
0
 def test_integer_list_insert__when_value_is_int_and_index_is_valid__expect_to_add_it_in_data(
         self):
     integer_list = IntegerList(1, 2, 3)
     integer_list.insert(1, 1)
     self.assertEqual([1, 1, 2, 3], integer_list.get_data())
Ejemplo n.º 6
0
class IntegerListTest(unittest.TestCase):
    def setUp(self):
        self.list = IntegerList([])

    def test_add(self):
        self.assertEqual(self.list.add(42), [42])

    def test_add_raises_value_error(self):
        self.assertRaises(ValueError, self.list.add, 'baba')

    def test_remove_by_index(self):
        self.list.add(42)
        el = self.list.remove_index(0)
        self.assertEqual(el, 42)

    def test_remove_by_index_raises_index_error(self):
        self.assertRaises(IndexError, self.list.remove_index, 0)

    def test_init_takes_only_ints(self):
        list = IntegerList('baba', 42, 'dqdo')
        self.assertEqual(list.get_data(), [42])

    def test_get(self):
        self.list.add(42)
        self.assertEqual(self.list.get(0), 42)

    def test_get_raises_index_error(self):
        self.assertRaises(IndexError, self.list.get, 0)

    def test_insert(self):
        self.assertRaises(IndexError, self.list.insert, 0, 42)
        self.list.add(1)
        self.assertRaises(ValueError, self.list.insert, 0, 'baba')
        self.list.insert(0, 42)
        self.assertEqual(self.list.get_data(), [42, 1])

    def test_get_biggest(self):
        self.list.add(42)
        self.list.add(43)
        self.assertEqual(self.list.get_biggest(), 43)

    def test_get_index(self):
        self.list.add(42)
        self.assertEqual(self.list.get_index(42), 0)
Ejemplo n.º 7
0
 def test__init__other_types_involved__expect_only_integers(self):
     self.int_list = IntegerList(1, 'two', 3, 'four', 5)
     self.assertEqual([1, 3, 5], self.int_list.get_data())
Ejemplo n.º 8
0
 def test_integer_list_add__when_value_is_int__expect_to_add_it_to_the_data_and_return_the_data(
         self):
     integer_list = IntegerList(1, 2, 3)
     self.assertEqual([1, 2, 3, 4], integer_list.add(4))
Ejemplo n.º 9
0
    def test_integer_list_add__when_value_is_not_int__expect_value_error(self):
        integer_list = IntegerList(1, 2, 3)

        with self.assertRaises(ValueError):
            integer_list.add("asd")
Ejemplo n.º 10
0
class TestIntegerList(TestCase):
    def setUp(self):
        self.list_integers = IntegerList(5, 6, 7)

    def test_init_creates_all_attributes(self):
        self.assertEqual([5, 6, 7], self.list_integers._IntegerList__data)

    def test_init_takes_non_integers(self):
        list_integers = IntegerList(5.6, "6", 7.2)
        self.assertEqual([], list_integers._IntegerList__data)

    def test_add_integer_is_added(self):
        result = self.list_integers.add(100)
        self.assertEqual([5, 6, 7, 100], result)

    def test_add_non_integer_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.list_integers.add(5.5)
        self.assertEqual("Element is not Integer", str(ex.exception))

    def test_remove_index_returns_element(self):
        el = self.list_integers.remove_index(0)
        self.assertEqual(5, el)
        self.assertEqual([6, 7], self.list_integers._IntegerList__data)

    def test_remove_index_not_in_range_raises(self):
        with self.assertRaises(IndexError) as ex:
            self.list_integers.remove_index(3)
        self.assertEqual("Index is out of range", str(ex.exception))

    def test_get_with_valid_index_returns_element(self):
        el = self.list_integers.get(0)
        self.assertEqual(5, el)
        self.assertEqual([5, 6, 7], self.list_integers._IntegerList__data)

    def test_get_with_not_valid_index_raises(self):
        with self.assertRaises(IndexError) as ex:
            self.list_integers.get(3)
        self.assertEqual("Index is out of range", str(ex.exception))

    def test_insert_adds_element_at_index(self):
        self.list_integers.insert(0, 100)
        self.assertEqual([100, 5, 6, 7], self.list_integers._IntegerList__data)

    def test_insert_non_integer_raises(self):
        with self.assertRaises(ValueError) as ex:
            self.list_integers.insert(0, 5.6)
        self.assertEqual("Element is not Integer", str(ex.exception))

    def test_insert_integer_to_non_valid_index_raises(self):
        with self.assertRaises(IndexError) as ex:
            self.list_integers.insert(3, 5)
        self.assertEqual("Index is out of range", str(ex.exception))

    def test_get_biggest(self):
        res = self.list_integers.get_biggest()
        self.assertEqual(7, res)

    def test_get_index(self):
        index = self.list_integers.get_index(5)
        self.assertEqual(0, index)
Ejemplo n.º 11
0
 def setUp(self):
     self.list_integers = IntegerList(5, 6, 7)
Ejemplo n.º 12
0
 def test_init_takes_non_integers(self):
     list_integers = IntegerList(5.6, "6", 7.2)
     self.assertEqual([], list_integers._IntegerList__data)
Ejemplo n.º 13
0
 def setUp(self):
     self.int_list = IntegerList(1, 2, 3, 4, 5)
Ejemplo n.º 14
0
class IntegerListTests(TestCase):
    def setUp(self):
        self.int_list = IntegerList(1, 2, 3, 4, 5)

    def test_add__element_not_integer__expect_value_error(self):
        with self.assertRaises(ValueError) as ex:
            self.int_list.add("asd")
        self.assertEqual('Element is not Integer', str(ex.exception))

    def test_add__valid_element__expect_return_list(self):
        self.assertEqual([1, 2, 3, 4, 5, 6], self.int_list.add(6))

    def test_remove_index__index_not_in_range__expect_index_error(self):
        with self.assertRaises(IndexError) as ex:
            self.int_list.remove_index(5)
        self.assertEqual('Index is out of range', str(ex.exception))

    def test_remove_index__return_element__expect_removed_element(self):
        self.assertEqual(self.int_list.remove_index(0), 1)
        self.assertEqual([2, 3, 4, 5], self.int_list.get_data())

    def test__init__other_types_involved__expect_only_integers(self):
        self.int_list = IntegerList(1, 'two', 3, 'four', 5)
        self.assertEqual([1, 3, 5], self.int_list.get_data())

    def test_get__index_not_in_range_expect_index_error(self):
        with self.assertRaises(IndexError) as ex:
            self.int_list.get(5)
        self.assertEqual('Index is out of range', str(ex.exception))

    def test_insert__index_not_in_range__expect_index_error(self):
        with self.assertRaises(IndexError) as ex:
            self.int_list.insert(5, 6)
        self.assertEqual('Index is out of range', str(ex.exception))

    def test_insert__element_not_integer__expect_value_error(self):
        with self.assertRaises(ValueError) as ex:
            self.int_list.insert(0, 'zero')
        self.assertEqual('Element is not Integer', str(ex.exception))

    def test_insert__element_valid__expect_change_in_list(self):
        self.int_list.insert(0, 0)
        self.assertEqual([0, 1, 2, 3, 4, 5], self.int_list.get_data())

    def test_get_biggest(self):
        self.assertEqual(self.int_list.get_biggest(), 5)

    def test_get_index(self):
        self.assertEqual(1, self.int_list.get_index(2))
Ejemplo n.º 15
0
 def test_integer_list_get_index__expect_to_return_the_index_by_value(self):
     integer_list = IntegerList(1, 2, 3)
     self.assertEqual(1, integer_list.get_index(2))
Ejemplo n.º 16
0
 def test_integer_list_remove__when_index_is_valid__expect_to_remove_the_value_and_return_it(
         self):
     integer_list = IntegerList(1, 2, 3)
     self.assertEqual(2, integer_list.remove_index(1))
Ejemplo n.º 17
0
 def test_init_takes_only_ints(self):
     list = IntegerList('baba', 42, 'dqdo')
     self.assertEqual(list.get_data(), [42])
Ejemplo n.º 18
0
 def test_integer_list_get__when_index_is_valid__expect_to_return_the_value(
         self):
     integer_list = IntegerList(1, 2, 3)
     self.assertEqual(3, integer_list.get(2))
Ejemplo n.º 19
0
 def setUp(self):
     self.list = IntegerList([])
Ejemplo n.º 20
0
class TestIntegerList(unittest.TestCase):
    def setUp(self):
        self.int_list = IntegerList(1, 2, 3, '4')
    
    def test_add__should_add_element_and_return_list(self):
        self.int_list.add(4)
        expected = [1, 2, 3, 4]
        actual = self.int_list.get_data()
        self.assertEqual(actual, expected)
    
    def test_add__raise_ValueError_if_element_not_integer(self):
        with self.assertRaises(ValueError) as cm:
            self.int_list.add('5')
        self.assertEqual(str(cm.exception), "Element is not Integer")
    
    def test_remove_index__removes_element_on_given_index_and_returns_it(self):
        self.assertEqual(self.int_list.remove_index(1), 2)
        self.assertEqual(self.int_list.get_data(), [1, 3])
    
    def test_remove_index__should_raise_IndexError__if_given_index_incorrect(self):
        with self.assertRaises(IndexError) as cm:
            self.int_list.remove_index(3)
        self.assertEqual(str(cm.exception), "Index is out of range")
    
    def test_get__should_return_element_in_given_index(self):
        self.assertEqual(self.int_list.get(2), 3)
    
    def test_get__should_raise_IndexError__if_given_index_incorrect(self):
        with self.assertRaises(IndexError) as cm:
            self.int_list.get(3)
        self.assertEqual(str(cm.exception), "Index is out of range")
    
    def test_insert__must_add_integer_to_given_index(self):
        self.int_list.insert(2, 4)
        expected = [1, 2, 4, 3]
        actual = self.int_list.get_data()
        self.assertEqual(actual, expected)
    
    def test_insert__must_raise_IndexError_if_given_index_invalid(self):
        with self.assertRaises(IndexError) as cm:
            self.int_list.insert(3, 4)
        self.assertEqual(str(cm.exception), "Index is out of range")
    
    def test_insert__must_raise_ValueError_if_given_element_not_integer(self):
        with self.assertRaises(ValueError) as cm:
            self.int_list.insert(2, '4')
        self.assertEqual(str(cm.exception), "Element is not Integer")
    
    def test_get_biggest_must_return_biggest_integer(self):
        self.assertEqual(self.int_list.get_biggest(), 3)
    
    def test_get_index__return_index_of_given_element(self):
        self.assertEqual(self.int_list.get_index(3), 2)