Exemple #1
0
    def test_returns_int(self):
        """
        Test list_even to make sure it returns an int.
        """
        return_type = type(count_all(1))
        self.assertEqual(
            return_type, int, "count_even should return type " +
            "int, but instead returned type {}.".format(return_type))

        return_type = type(count_all([1]))
        self.assertEqual(
            return_type, int, "count_even should return type " +
            "int, but instead returned type {}.".format(return_type))
Exemple #2
0
    def test_count_all(self, list_values, list_indices):
        """
        Test the submitted count_even against a randomly generated list.
        """

        # Gather all of the even values
        expected = len(list_values)

        # Create up to 2 levels of nesting for the values in list_values, where
        # the indices we turn into sublists are contained in
        # nesting_indices_1 and nesting_indices_2
        nesting_indices_1 = list_indices[:len(list_indices) // 2]
        nesting_indices_2 = list_indices[len(list_indices) // 2:]
        nesting_indices_1.sort()
        nesting_indices_2.sort()

        obj = create_nested_list(list_values,
                                 [nesting_indices_1, nesting_indices_2])

        # Ignoring the order of the values, in case students have an
        # out-of-order version for some reason.
        actual = count_all(obj)

        self.assertEqual(actual, expected,
                         ("Using count_even on {} returned" +
                          " {} instead of {}.").format(obj, actual, expected))
Exemple #3
0
 def test_one_nested_sublist(self):
     """
     Test list_even on a list with only one sublist in it.
     """
     self.assertEqual(
         count_all([[2]]), 1, "count_all should return " +
         "the number of integers in nested sublists.")
Exemple #4
0
 def test_integer(self):
     """
     Test list_even on an integer.
     """
     self.assertEqual(
         count_all(1), 1,
         "count_all should return 1 " + "when passed a single integer.")
Exemple #5
0
 def test_one_nested_sublist_and_integers(self):
     """
     Test list_even on a list with at most one level of nested sublists in
     it mixed with integers.
     """
     self.assertEqual(
         count_all([[2], 3,
                    [4]]), 3, "count_even should return the number of " +
         "integers in nested sublists and in the list passed " + "in.")