Example #1
0
    def optional_test_plot_labels(self):
        axes = self.plt.gca()
        title = axes.get_title()
        xlabel = axes.get_xlabel()
        ylabel = axes.get_ylabel()
        points = 0

        if xlabel:
            points += 1
            Feedback.add_feedback('Plot has xlabel')
        else:
            Feedback.add_feedback('Plot is missing xlabel')

        if title:
            points += 1
            Feedback.add_feedback('Plot has title')
        else:
            Feedback.add_feedback('Plot is missing title')

        if ylabel:
            points += 1
            Feedback.add_feedback('Plot has ylabel')
        else:
            Feedback.add_feedback('Plot is missing ylabel')

        Feedback.set_score(points / 3.0)
Example #2
0
 def test_2(self):
     user_dict = Feedback.call_user(self.st.bif_dict, 7)
     correct_dict = self.ref.bif_dict(7)
     if self.check(user_dict, correct_dict):
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)
Example #3
0
 def test_4(self):
     if Feedback.check_numpy_array_allclose('right_side',
                                            self.ref.right_side,
                                            self.st.right_side):
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)
Example #4
0
    def test_0(self):
        studentL = {
            "".join(s)
            for s in exploreCFG(self.st.cfg, MAX_LENGTH_TO_CHECK + 3)
        }
        # The "+ 3" is for wiggle room
        # See exploreCFG documentation for an explanation of why this is necessary

        studentL = {s for s in studentL if len(s) <= MAX_LENGTH_TO_CHECK}
        correctL = generateLanguage(MAX_LENGTH_TO_CHECK)

        falsePositives = studentL.difference(correctL)
        if falsePositives:
            Feedback.add_feedback(
                "Your CFG generated the string "
                f"'{min(falsePositives, key=lambda s: len(s))}', "
                "which is not in the language.")
            return

        falseNegatives = correctL.difference(studentL)
        if falseNegatives:
            Feedback.add_feedback(
                "Your CFG did not generate the string "
                f"'{min(falseNegatives, key=lambda s: len(s))}', "
                "which is in the language.")
            return

        Feedback.set_score(1)
Example #5
0
 def test_0(self):
     if self.ref.lcs("crows eat yay",
                     "ows eat ") == self.st.lcs("crows eat yay",
                                                "ows eat "):
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)
Example #6
0
 def test_0(self):
     if Feedback.check_dataframe("df",
                                 self.ref.df,
                                 self.st.df,
                                 display_input=True):
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)
Example #7
0
 def test_0(self):
     if Feedback.check_plot('plot',
                            self.ref.plot,
                            self.st.plot,
                            check_axes_scale='xy'):
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)
Example #8
0
    def test_0(self):
        num_distinct_elements = len({
            Feedback.call_user(self.st.getFoolingSetElement, i)
            for i in range(1, NUM_ELEMENTS_TO_CHECK + 1)
        })

        if num_distinct_elements == NUM_ELEMENTS_TO_CHECK:
            Feedback.set_score(1)
        else:
            Feedback.set_score(0)
Example #9
0
 def test_3(self):
     points = 0
     num_tests = 10
     test_values = np.random.choice(np.arange(2, 30), size=num_tests, replace=False)
     for in_val in test_values:
         correct_val = self.ref.fib(in_val)
         user_val = Feedback.call_user(self.st.fib, in_val)
         if Feedback.check_scalar(f"fib({in_val})", correct_val, user_val):
             points += 1
     Feedback.set_score(points / num_tests)
Example #10
0
 def check(self, user_dict, correct_dict):
     if not isinstance(user_dict,
                       dict) or len(user_dict) != len(correct_dict):
         Feedback.set_score(0)
         return False
     for key in correct_dict:
         if key not in user_dict or correct_dict[key] != user_dict[key]:
             Feedback.set_score(0)
             return False
     return True
Example #11
0
 def test_2(self):
     enrollment = {"A": 8, "B": 12, "C": 23, "D": 17, "E": 5}
     attendance = {"A": [8, 9, 8, 10, 10, 2, 6, 7, 3, 1], 
                   "B": [19, 18, 16, 14, 12, 11, 10, 5, 5, 5],
                   "C": [25, 22, 23, 24, 25, 22, 22, 20, 25, 25], 
                   "D": [20, 15, 15, 12, 17, 17, 16, 16, 18, 20], 
                   "E": [5, 5, 4, 2, 3, 10, 11, 12, 4, 2]}
     user_val = Feedback.call_user(self.st.TAs_with_at_least_half_discussions_full, enrollment, attendance)
     if self.ref.TAs_with_at_least_half_discussions_full(enrollment, attendance) == user_val:
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)
Example #12
0
 def test_3(self):
     points = 0
     num_tests = 8
     test_values = np.random.choice(np.arange(6, 20),
                                    size=num_tests,
                                    replace=False)
     for value in test_values:
         user_dict = Feedback.call_user(self.st.bif_dict, value)
         correct_dict = self.ref.bif_dict(value)
         if self.check(user_dict, correct_dict):
             points += 1
     Feedback.set_score(points / num_tests)
Example #13
0
 def test_0(self):
     sp19_enrollment = {"Murtaza": 10, "Lara": 20, "Mansi": 20, "Niki": 15, "Brendan": 10}
     sp19_attendance = {"Murtaza": [10, 9, 10, 10, 10, 2, 9, 10, 9, 1],
                        "Lara": [19, 18, 16, 14, 12, 11, 10, 5, 5, 5],
                        "Mansi": [25, 22, 23, 24, 25, 22, 22, 20, 25, 25],
                        "Niki": [20, 15, 15, 12, 17, 17, 17, 16, 18, 20],
                        "Brendan": [5, 5, 4, 2, 3, 10, 11, 12, 4, 2]}
     user_val = Feedback.call_user(self.st.TAs_with_at_least_half_discussions_full, sp19_enrollment, sp19_attendance)
     if self.ref.TAs_with_at_least_half_discussions_full(sp19_enrollment, sp19_attendance) == user_val:
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)
Example #14
0
    def test_0(self):
        points = 0

        a = np.random.rand(4)
        b = np.random.rand(4)

        user_val = Feedback.call_user(self.st.my_dot_product, a, b)
        ref_val = Feedback.call_user(self.ref.my_dot_product, a, b)
        if Feedback.check_scalar("my_dot_product return value", ref_val,
                                 user_val):
            points += 1

        Feedback.set_score(points)
Example #15
0
    def test_0(self):
        points = 0

        feedback.check_numpy_array_features('b',
                                            self.ref.a,
                                            self.st.b,
                                            accuracy_critical=True)

        suma = self.ref.beta * np.sum(self.ref.a)
        sumb = np.sum(self.st.b)

        if feedback.check_scalar('b', suma, sumb):
            points += 1

        feedback.set_score(points)
Example #16
0
 def test_0(self):
     points = 0
     # use the same input vector for both u and v to avoid ambiguity in the order of iteration
     results = Feedback.call_user(
         self.st.power_iteration, self.ref.M_test, self.ref.x_test)
     if results is None:
         Feedback.add_feedback(
             'Your function is not returning any variables.')
         self.fail()
     if Feedback.check_numpy_array_allclose('The return value from your function power_iteration', self.ref.xc, results):
         points += 0.5
     results_hidden = Feedback.call_user(
         self.st.power_iteration, self.ref.M_hidden, self.ref.x_hidden)
     if Feedback.check_numpy_array_allclose('The return value from your function power_iteration (hidden test case)', self.ref.xc_hidden, results_hidden):
         points += 0.5
     Feedback.set_score(points)
Example #17
0
    def test_0(self):
        tests = 50
        points = 0

        xs = np.linspace(-1, 1, tests)
        alphas = np.linspace(0.1, 0.001, tests)
        np.random.shuffle(xs)
        np.random.shuffle(alphas)

        for i in range(tests):
            x = xs[i]
            alpha = alphas[i]
            ref_xnew = self.ref.gradient_descent(x, alpha)
            st_xnew = Feedback.call_user(self.st.gradient_descent, x, alpha)
            if Feedback.check_scalar(f'x={x}, alpha={alpha}', ref_xnew, st_xnew, report_success=True, report_failure=True):
                points += 1
        Feedback.set_score(points / tests)
Example #18
0
    def test_1(self):
        for i in range(1, NUM_ELEMENTS_TO_CHECK + 1):
            for j in range(i + 1, NUM_ELEMENTS_TO_CHECK + 1):
                x = Feedback.call_user(self.st.getFoolingSetElement, i)
                y = Feedback.call_user(self.st.getFoolingSetElement, j)
                z = Feedback.call_user(self.st.getDistinguishingSuffix, i, j)

                if not (isInLanguage(x + z) ^ isInLanguage(y + z)):
                    Feedback.add_feedback(
                        f"When i = {i} and j = {j}, the suffix\n\n"
                        f"z = '{z}'\n\n"
                        f"fails to distinguish the two fooling set elements\n\n"
                        f"x = '{x}'\n"
                        f"y = '{y}'")
                    Feedback.set_score(0)
                    return

        Feedback.set_score(1)
Example #19
0
 def test_0(self):
     points = 0
     test_strings = ['', 'a', 'peak']
     num_tests = len(test_strings)
     for s in test_strings:
         correct_val = self.ref.checkPalindrome(s)
         user_val = True
         if self.ref.function == 'is_palindrome_all':
             user_val = Feedback.call_user(self.st.is_palindrome_all, s)
         elif self.ref.function == 'is_palindrome_any':
             user_val = Feedback.call_user(self.st.is_palindrome_any, s)
         else:
             user_val = Feedback.call_user(self.st.is_palindrome_none, s)
         if Feedback.check_scalar(f"checkPalindrome({s})", correct_val,
                                  user_val):
             points += 1
     if points < 3:
         points = 0
     Feedback.set_score(points / num_tests)
Example #20
0
 def test_1(self):
     sequence = "uc berkeley also cal"
     if self.ref.function == "most_common":
         user_val = Feedback.call_user(self.st.most_common, sequence)
         if self.ref.most_common(sequence) == user_val:
             Feedback.set_score(1)
         else:
             Feedback.set_score(0)
     elif self.ref.function == "least_common":
         user_val = Feedback.call_user(self.st.least_common, sequence)
         if self.ref.least_common(sequence) == user_val:
             Feedback.set_score(1)
         else:
             Feedback.set_score(0)
Example #21
0
 def test_3(self):
     sequence = "sphinxofquartz"
     if self.ref.function == "most_common":
         user_val = Feedback.call_user(self.st.most_common, sequence)
         if self.ref.most_common(sequence) == user_val:
             Feedback.set_score(1)
         else:
             Feedback.set_score(0)
     elif self.ref.function == "least_common":
         user_val = Feedback.call_user(self.st.least_common, sequence)
         if self.ref.least_common(sequence) == user_val:
             Feedback.set_score(1)
         else:
             Feedback.set_score(0)
Example #22
0
 def test_2(self):
     sequence = [1, 2, 3, 4, 5, 6, 7, 8]
     if self.ref.function == "most_common":
         user_val = Feedback.call_user(self.st.most_common, sequence)
         if self.ref.most_common(sequence) == user_val:
             Feedback.set_score(1)
         else:
             Feedback.set_score(0)
     elif self.ref.function == "least_common":
         user_val = Feedback.call_user(self.st.least_common, sequence)
         if self.ref.least_common(sequence) == user_val:
             Feedback.set_score(1)
         else:
             Feedback.set_score(0)
Example #23
0
    def test_0(self):
        # Check type

        for str_length in range(0, MAX_LENGTH_TO_CHECK + 1):
            for char_list in itertools.product(alphabet, repeat=str_length):
                x = "".join(char_list)

                in_language = isInLanguage(x)
                accepted = self.st.fa.accepts_input(x)

                if in_language and not accepted:
                    Feedback.add_feedback(
                        f"Your DFA/NFA did not accept the string '{x}', "
                        "which is in the language.")
                    return
                elif not in_language and accepted:
                    Feedback.add_feedback(
                        f"Your DFA/NFA accepted the string '{x}', "
                        "which is not in the language.")
                    return

        Feedback.set_score(1)
Example #24
0
 def test_3(self):
     enrollment = {"A": 8, "B": 12, "C": 23, "D": 17, "E": 5, "Murtaza": 10, "Lara": 20, "Mansi": 20, "Niki": 15, "Brendan": 10, "F": 10, "G": 20, "H": 30, "I": 20, "J": 10}
     attendance = {"A": [8, 9, 8, 10, 10, 2, 6, 7, 3, 1], 
                   "B": [19, 18, 16, 14, 12, 11, 10, 5, 5, 5],
                   "C": [25, 22, 23, 24, 25, 22, 22, 20, 25, 25], 
                   "D": [20, 15, 15, 12, 17, 17, 16, 16, 18, 20], 
                   "E": [5, 5, 4, 2, 3, 10, 11, 12, 4, 2], 
                   "Murtaza": [10, 9, 10, 10, 10, 2, 9, 10, 9, 1],
                   "Lara": [19, 18, 16, 14, 12, 11, 10, 5, 5, 5],
                   "Mansi": [25, 22, 23, 24, 25, 22, 22, 20, 25, 25],
                   "Niki": [20, 15, 15, 12, 17, 17, 17, 16, 18, 20],
                   "Brendan": [5, 5, 4, 2, 3, 10, 11, 12, 4, 2], 
                   "F": [8, 9, 8, 10, 10, 2, 9, 10, 9, 1], 
                   "G": [19, 18, 16, 14, 12, 11, 10, 5, 5, 5],
                   "H": [25, 22, 23, 24, 25, 22, 22, 20, 25, 25], 
                   "I": [20, 15, 15, 12, 17, 17, 17, 16, 18, 20], 
                   "J": [5, 5, 4, 2, 3, 10, 11, 12, 4, 2]}
     user_val = Feedback.call_user(self.st.TAs_with_at_least_half_discussions_full, enrollment, attendance)
     if self.ref.TAs_with_at_least_half_discussions_full(enrollment, attendance) == user_val:
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)
Example #25
0
 def test_4(self):
     sequence = []
     for i in range(20):
         sequence += [random.randint(0, 20)]
     if self.ref.function == "most_common":
         user_val = Feedback.call_user(self.st.most_common, sequence)
         if self.ref.most_common(sequence) == user_val:
             Feedback.set_score(1)
         else:
             Feedback.set_score(0)
     elif self.ref.function == "least_common":
         user_val = Feedback.call_user(self.st.least_common, sequence)
         if self.ref.least_common(sequence) == user_val:
             Feedback.set_score(1)
         else:
             Feedback.set_score(0)
Example #26
0
    def test_0(self):
        allowed_chars = {'(', ')', '+', '*', 'e', ' '}.union(alphabet)
        for char in self.st.reg_exp:
            if char not in allowed_chars:
                Feedback.add_feedback(
                    f"Your regular expression contains the character '{char}', "
                    "which is not permitted.")
                return

        processed_re = self.st.reg_exp.replace('e', '').replace('+',
                                                                '|').replace(
                                                                    ' ', '')
        try:
            compiled_re = re.compile(processed_re)
        except re.error:
            Feedback.add_feedback("Your regular expression failed to compile.")
            return

        for str_length in range(0, MAX_LENGTH_TO_CHECK + 1):
            for char_list in itertools.product(alphabet, repeat=str_length):
                x = "".join(char_list)

                in_language = isInLanguage(x)
                match = compiled_re.fullmatch(x)

                if in_language and not match:
                    Feedback.add_feedback(
                        f"Your regular expression did not match the string '{x}', "
                        "which is in the language.")
                    return
                elif not in_language and match:
                    Feedback.add_feedback(
                        f"Your regular expression matched the string '{x}', "
                        "which is not in the language.")
                    return

        Feedback.set_score(1)
Example #27
0
    def test_1(self):
        points = 0
        results = feedback.call_user(self.st.array_to_scalar, self.ref.a1,
                                     self.ref.a2)
        ## Testing if the return values are given correctly
        if results is not None:
            if hasattr(results, '__len__'):
                if (len(results) != 2):
                    feedback.add_feedback(
                        'Your function is not returning the correct number of variables'
                    )
                    self.fail()
                else:
                    (st_c, st_sumc) = results
            else:
                feedback.add_feedback(
                    'The return variables do not appear to be in tuple format')
                self.fail()
        else:
            feedback.add_feedback(
                'Your function is not returning any variables.')
            self.fail()

        if feedback.check_numpy_array_allclose('c',
                                               self.ref.c,
                                               st_c,
                                               accuracy_critical=False):
            points += 0.5

        if feedback.check_scalar('sum_c',
                                 self.ref.sum_c,
                                 st_sumc,
                                 accuracy_critical=True):
            points += 0.5

        feedback.set_score(points)
Example #28
0
 def test_3(self):
     points = 0
     test_strings = [
         'abc', 'c al', 'aabb', 'abcdefghi', 'palindrome', 'abbba', 'abcba',
         'abca', 'refer', 'berkeley', 'abccba', 'abcdedcba'
     ]
     num_tests = 8
     for s in test_strings:
         correct_val = self.ref.checkPalindrome(s)
         if isinstance(correct_val, bool):
             user_val = True
             if self.ref.function == 'is_palindrome_all':
                 user_val = Feedback.call_user(self.st.is_palindrome_all, s)
             elif self.ref.function == 'is_palindrome_any':
                 user_val = Feedback.call_user(self.st.is_palindrome_any, s)
             else:
                 user_val = Feedback.call_user(self.st.is_palindrome_none,
                                               s)
             if Feedback.check_scalar(f"checkPalindrome({s})", correct_val,
                                      user_val):
                 points += 1
     if points <= 5:
         points = 0
     Feedback.set_score(points / num_tests)
Example #29
0
 def test_0(self):
     user_val = Feedback.call_user(self.st.return_number)
     if ((user_val % 2 == 0) and (self.ref.number_type == 'even')):
         Feedback.set_score(1)
         Feedback.add_feedback('Your answer is correct.')
     elif ((user_val % 2 != 0) and (self.ref.number_type == 'odd')):
         Feedback.set_score(1)
         Feedback.add_feedback('Your answer is correct.')
     else:
         Feedback.set_score(0)
         Feedback.add_feedback('The return value is not correct.')
Example #30
0
 def test_2(self):
     user_val = Feedback.call_user(self.st.fib, 7)
     if Feedback.check_scalar("fib(7)", self.ref.fib(7), user_val):
         Feedback.set_score(1)
     else:
         Feedback.set_score(0)