def test_find_first(self): s = StringList(["A", "B", "C"]) self.assertEqual(s.index("A"), 0) self.assertEqual(s.index("B"), 1) self.assertEqual(s.index("C"), 2) self.assertEqual(s.index("D"), -1)
def test_append(self): s1 = StringList(["A", "B"]) s1.append("C") s2 = StringList(["A","B","C"]) self.assertEqual(s1, ["A", "B", "C"]) self.assertEqual(s1, s2) self.assertFalse(s1 == ["A","B","D"]) self.assertFalse(s1 == ["A","B","C" , "D"])
def test_last(self): s = StringList(initial=["A", "list", "of", "strings"]) self.assertEqual(s.last, "strings") with self.assertRaises(IndexError): s.pop() s.pop() s.pop() s.pop() s.last
def test_append(self): s1 = StringList(["A", "B"]) s1.append("C") s2 = StringList(["A","B","C"]) self.assertEqual(s1, ["A", "B", "C"]) self.assertEqual(s1, s2) self.assertFalse(s1 == ["A","B","D"]) self.assertFalse(s1 == ["A","B","C" , "D"]) pfx = 'StringList(size' # __repr__ self.assertEqual(pfx, repr(s2)[:len(pfx)])
def test_pop( self ): s = StringList(initial=["A", "list", "of", "strings"]) s1 = s.pop() self.assertTrue(len(s) == 3) self.assertTrue(s1 == "strings") s1 = s.pop() self.assertTrue(len(s) == 2) self.assertTrue(s1 == "of") s1 = s.pop() self.assertTrue(len(s) == 1) self.assertTrue(s1 == "list") s1 = s.pop() self.assertTrue(len(s) == 0) self.assertTrue(s1 == "A") with self.assertRaises(IndexError): s.pop()
def test_front_back(self): s = StringList() with self.assertRaises(LookupError): s.front() with self.assertRaises(LookupError): s.back() s.append("S1") s.append("S2") s.append("S3") self.assertEqual("S1", s.front()) self.assertEqual("S3", s.back())
def test_append_not_string(self): s = StringList() s.append(10) self.assertEqual(len(s), 1) self.assertEqual(s[0], "10")
def test_in_and_not_in(self): s = StringList(["A", "list", "of", "strings"]) self.assertTrue("A" in s) self.assertTrue("Bjarne" not in s)
def test_append_not_string(self): s = StringList() s.append(10) self.assertEqual( len(s) , 1) self.assertEqual(s[0] , "10")
def test_front_back(self): s = StringList() with self.assertRaises(LookupError): s.front() with self.assertRaises(LookupError): s.back() s.append("S1") s.append("S2") s.append("S3") self.assertEqual( "S1" , s.front() ) self.assertEqual( "S3" , s.back() )
def test_append(self): s = StringList(["A", "B"]) s.append("C") self.assertEqual(list(s), ["A", "B", "C"])