Example #1
0
    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)
Example #2
0
    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"])
Example #3
0
    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
Example #4
0
    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)])
Example #5
0
    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()
Example #6
0
    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())
Example #7
0
 def test_append_not_string(self):
     s = StringList()
     s.append(10)
     self.assertEqual(len(s), 1)
     self.assertEqual(s[0], "10")
Example #8
0
    def test_in_and_not_in(self):
        s = StringList(["A", "list", "of", "strings"])

        self.assertTrue("A" in s)
        self.assertTrue("Bjarne" not in s)
Example #9
0
 def test_append_not_string(self):
     s = StringList()
     s.append(10)
     self.assertEqual( len(s) , 1)
     self.assertEqual(s[0] , "10")
Example #10
0
    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"])
Example #12
0
 def test_append(self):
     s = StringList(["A", "B"])
     s.append("C")
     self.assertEqual(list(s), ["A", "B", "C"])