コード例 #1
0
    def test_max_list_iter(self):
        """tests that the max_list_inter function in Lab1 returns the maximum of a list"""
        tlist = None
        with self.assertRaises(ValueError):  # used to check for exception
            max_list_iter(tlist)
        self.assertEqual(lab1.max_list_iter([]),
                         None)  # tests that an empty list returns None

        self.assertEqual(max_list_iter([1, 2, 3, 4, 5]),
                         5)  # tests one maximum in various locations
        self.assertEqual(max_list_iter([1, 2, 3, 5, 4]), 5)
        self.assertEqual(max_list_iter([1, 2, 5, 3, 4]), 5)
        self.assertEqual(max_list_iter([1, 5, 2, 3, 4]), 5)
        self.assertEqual(max_list_iter([5, 1, 2, 3, 4]), 5)

        self.assertEqual(max_list_iter([1, 1, 1, 1, 1]),
                         1)  # tests all values equal

        self.assertEqual(max_list_iter([9, 1, 1, 1, 1]),
                         9)  # tests multiple min values and 1 max
        self.assertEqual(max_list_iter([1, 9, 1, 1, 1]), 9)
        self.assertEqual(max_list_iter([1, 1, 9, 1, 1]), 9)
        self.assertEqual(max_list_iter([1, 1, 1, 9, 1]), 9)
        self.assertEqual(max_list_iter([1, 1, 1, 1, 9]), 9)

        self.assertEqual(max_list_iter([1, 9, 9, 9, 9]),
                         9)  # tests multiple max values and 1 min
        self.assertEqual(max_list_iter([9, 1, 9, 9, 9]), 9)
        self.assertEqual(max_list_iter([9, 9, 1, 9, 9]), 9)
        self.assertEqual(max_list_iter([9, 9, 9, 1, 9]), 9)
        self.assertEqual(max_list_iter([9, 9, 9, 9, 1]), 9)
コード例 #2
0
ファイル: lab1_test_cases.py プロジェクト: JacobWren/CPE202
 def test_max_list_iter(self):
     """test max_list_iter function. Edge cases include empty lists and lists of length 1"""
     tlist = None
     with self.assertRaises(ValueError):  # used to check for exception
         lab1.max_list_iter(tlist)
     self.assertEqual(lab1.max_list_iter([]), None)
     self.assertEqual(lab1.max_list_iter([1]), 1)
     self.assertEqual(lab1.max_list_iter([1, 2]), 2)
     self.assertEqual(lab1.max_list_iter([2, 1]), 2)
     self.assertEqual(lab1.max_list_iter([1, 2, 3]), 3)
     self.assertEqual(lab1.max_list_iter([1, 3, 2]), 3)
コード例 #3
0
 def test_max_list_iter(self):
     tlist1 = [0, 1, 2, 3, 4, 5]
     self.assertEqual(lab1.max_list_iter(tlist1), 5)
     tlist2 = [5, 4, 3, 2, 1, 0]
     self.assertEqual(lab1.max_list_iter(tlist2), 5)
     tlist3 = [3, 5, 6, 8, 2, 9]
     self.assertEqual(lab1.max_list_iter(tlist3), 9)
     tlist4 = [1, 1, 1, 1, 1, 1]
     self.assertEqual(lab1.max_list_iter(tlist4), 1)
     tlist5 = [9, 0, 0, 0, 0, 10]
     self.assertEqual(lab1.max_list_iter(tlist5), 10)
     tlist6 = []
     with self.assertRaises(ValueError):
         lab1.max_list_iter(tlist6)
     tlist7 = [-1, -5, -8, -2, -10]
     self.assertEqual(lab1.max_list_iter(tlist7), -2)
     tlist8 = [-1, -1, -1, -1, -1]
     self.assertEqual(lab1.max_list_iter(tlist8), -1)
コード例 #4
0
 def test_max_list(self):
     tlist = [10, 9, 8, 4, 9]
     self.assertEqual(lab1.max_list_iter(tlist), 10)
     tlist = []
     with self.assertRaises(ValueError):  # magic - uses context manager
         lab1.max_list_iter(tlist)