def test_2(self): if self.ref.function == "find_GC": GP = {1: 10, 2: 20, 3: 30} PC = {10: 100, 15: 150, 20: 200} user_val = Feedback.call_user(self.st.find_GC, GP, PC) if self.ref.find_GC(GP, PC) == user_val: Feedback.set_score(1) else: Feedback.set_score(0) elif self.ref.function == "same_keys": D1 = {1: 10, 2: 10, 3: 10, 4: 10} D2 = {1: 20, 2: 20, 7: 30, 8: 40} user_val = Feedback.call_user(self.st.same_keys, D1, D2) if self.ref.same_keys(D1, D2) == user_val: Feedback.set_score(1) else: Feedback.set_score(0) elif self.ref.function == "same_values": D1 = {1: 10, 2: 12, 3: 11} D2 = {1: 10, 4: 9, 5: 10} user_val = Feedback.call_user(self.st.same_values, D1, D2) if self.ref.same_values(D1, D2) == user_val: Feedback.set_score(1) else: Feedback.set_score(0)
def test_1(self): if self.ref.function == "find_GC": GP = {12: 140, 19: 199, 21: 192} PC = {166: 1200, 195: 1300} user_val = Feedback.call_user(self.st.find_GC, GP, PC) if self.ref.find_GC(GP, PC) == user_val: Feedback.set_score(1) else: Feedback.set_score(0) elif self.ref.function == "same_keys": D1 = {1: 10, 2: 10, 3: 10, 4: 10} D2 = {5: 20, 6: 20, 7: 30, 8: 40} user_val = Feedback.call_user(self.st.same_keys, D1, D2) if self.ref.same_keys(D1, D2) == user_val: Feedback.set_score(1) else: Feedback.set_score(0) elif self.ref.function == "same_values": D1 = {1: 10, 2: 10, 3: 10} D2 = {1: 15, 2: 15, 3: 15} user_val = Feedback.call_user(self.st.same_values, D1, D2) if self.ref.same_values(D1, D2) == user_val: Feedback.set_score(1) else: Feedback.set_score(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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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.')
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)
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)
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)
def test_4(self): if self.ref.function == "find_GC": GP = { 1: 10, 2: 10, 3: 20, 4: 20, 5: 30, 6: 30, 7: 30, 8: 40, 9: 40, 10: 50, 11: 60 } PC = {10: 100, 20: 200, 30: 300, 40: 400, 70: 700, 80: 800} user_val = Feedback.call_user(self.st.find_GC, GP, PC) if self.ref.find_GC(GP, PC) == user_val: Feedback.set_score(1) else: Feedback.set_score(0) elif self.ref.function == "same_keys": D1 = {1: 10, 2: 10, 3: 10, 4: 10, 5: 40, 6: 70, 7: 80} D2 = {1: 20, 2: 20, 3: 30, 4: 40, 6: 90, 9: 100} user_val = Feedback.call_user(self.st.same_keys, D1, D2) if self.ref.same_keys(D1, D2) == user_val: Feedback.set_score(1) else: Feedback.set_score(0) elif self.ref.function == "same_values": D1 = {1: 10, 2: 12, 3: 11, 4: 12, 5: 13, 6: 14, 7: 16} D2 = {1: 10, 2: 11, 4: 11, 5: 12, 6: 13, 7: 14, 8: 15} user_val = Feedback.call_user(self.st.same_values, D1, D2) if self.ref.same_values(D1, D2) == user_val: Feedback.set_score(1) else: Feedback.set_score(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)
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)
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)
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)
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)
def test_1(self): user_val = Feedback.call_user(self.st.nib, 1) if Feedback.check_scalar("nib(1)", self.ref.nib(1), user_val): Feedback.set_score(1) else: Feedback.set_score(0)
def test_0(self): user_val = Feedback.call_user(self.st.trib, 0) if Feedback.check_scalar("trib(0)", self.ref.trib(0), user_val): Feedback.set_score(1) else: Feedback.set_score(0)