I am currently writing unittest for my class function.
def test_getitem(self):
test1 = List(3)
for i in range(3):
test1.append(i)
self.assertEqual(test1[2], 2)
test1 = List(3)
for i in range(3):
test1.append(i)
self.assertRaises(IndexError, test1[4])
The problem that I am facing now is in part of self.assertRaisesmy code. I'm not sure what it was, but when I start unittestit gives an error Index out of range. In truth, it should be OK.
List- my class, and List(3)creates a list based on an array. therefore, when I am test1.append(i), now it is [0,1,2].
test1[2]- a method of calling a function getitemin my class, similar self[index].
I am wondering if I am arguing correctly? self.assertEqualfine.
Maxxx source
share