def test_off_by_one(self): """Test that you fetch the value you put in.""" test_list = OffByOneList(['1', '2', '3']) for k in (1, 2, 3): self.assertEqual(str(k), test_list[k]) self.assertEqual([str(k)], test_list[k:k + 1]) self.assertEqual(k, test_list.index(str(k))) self.assertEqual(1, test_list.count(str(k))) self.assertEqual(['3', '2', '1'], list(reversed(test_list)))
def test_index_type(self): test_list = OffByOneList([]) # Test index type sanity. for value in (None, 2.0, type): with self.assertRaises(TypeError): test_list[value]
def test_empty_slice(self): """Test that we get an empty list if no elements in slice.""" test_list = OffByOneList([]) for s in (slice(1, 1), slice(1, 2), slice(-2, -1)): self.assertEqual([], test_list[s])
def test_index_error_no_data(self): """Test that when start or end are -1,0, or 1 we get an index error.""" for index in [-1, 0, 1, slice(-1, 0), slice(0, 1)]: test_list = OffByOneList([]) with self.assertRaises(IndexError): test_list[index]
def test_index_error_with_data(self): """Test index errors with data in list.""" test_list = OffByOneList([]) for k in (0, 4): with self.assertRaises(IndexError): test_list[k]