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_off_by_one(): """Test that you fetch the value you put in""" test_list = OffByOneList(['1', '2', '3']) for k in (1, 2, 3): assert test_list[k] == str(k) assert test_list[k:k + 1] == [str(k)] assert test_list.index(str(k)) == k assert test_list.count(str(k)) == 1 assert list(reversed(test_list)) == ['3', '2', '1']
def test_index_type(self): test_list = OffByOneList([]) # Test index type sanity. for value in (None, 2.0, type): with pytest.raises(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 pytest.raises(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 pytest.raises(IndexError): test_list[k]
def test_index_type(): test_list = OffByOneList([]) # Test Index Type Sanity for value in (None, 2.0, type): with pytest.raises(TypeError): test_list[value]
def test_empty_slice(): """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)): assert test_list[s] == []
def test_index_error_no_data(index): """Test that when start or end are -1,0, or 1 we get an index error""" test_list = OffByOneList([]) with pytest.raises(IndexError): test_list[index]