def test_windows(): windows = get_task_windows() if "number" in windows[0] and "number" in windows[1]: passed() else: failed("Use % operator")
def test_published_date1(): placeholders = get_answer_placeholders() placeholder = placeholders[2] if "DateTimeField" in placeholder and "blank" in placeholder and "null" in placeholder: passed() else: failed("Define variable as DateTimeField(blank=True, null=True)")
def test_published_date(): placeholders = get_answer_placeholders() placeholder = placeholders[2] if "published_date" in placeholder: passed() else: failed("Define published_date variable")
def test_answer_placeholders1(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if "views.post_list" in placeholder: passed() else: failed("Map url to the views.post_list")
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if placeholder == "models.Model": passed() else: failed("Use models.Model as an ancestor")
def test_title(): placeholders = get_answer_placeholders() placeholder = placeholders[1] if "title" in placeholder: passed() else: failed("Define title variable")
def test_title1(): placeholders = get_answer_placeholders() placeholder = placeholders[1] if "CharField" in placeholder and "max_length" in placeholder and "200" in placeholder: passed() else: failed("Create models.CharField(max_length=200) here")
def test_window(): window = get_answer_placeholders()[0] if " in " in window: passed() else: failed("Use 'in' operator for this check")
def test_ice_cream(): window = get_answer_placeholders()[0] if "ice cream" in window or "ice_cream": passed() else: failed("Check if there is 'ice' in 'ice cream'")
def test_windows(): windows = get_answer_placeholders() if "number" in windows[0] and "number" in windows[1]: passed() else: failed("Use % operator")
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if placeholder.find('service_address') != -1: passed() else: failed('Sorry that is not correct. Check the Hint for more help.')
def test_answer_placeholders2(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if "{{" in placeholder and "}}" in placeholder and "post" in placeholder: passed() else: failed("Use {{ post }} to print post content")
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if "{%" in placeholder and "%}" in placeholder and "for" in placeholder: passed() else: failed("Use '{% for ... in ... %}' tag")
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[1] if "raw_input(" in placeholder: passed() else: failed("Remember to use raw_input(prompt)")
def test_answer_placeholders1(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if "{%" in placeholder and "%}" in placeholder and "endfor" in placeholder: passed() else: failed("Don't forget to close for tag")
def test_value(): file = import_task_file() if file.greetings == "greetings": failed("You should assign different value to the variable") else: passed()
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if (placeholder[:7] == 'print("' or placeholder[:7] == "print('") and (placeholder[-2:] == '")' or placeholder[-2:] == "')") : passed() else: failed()
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if placeholder == "%a %b %d %Y %I:%M:%S%p": passed() else: failed('Sorry, that is not correct. Check the Hint for the correct answer.')
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0].replace('"', "'") if placeholder == "'%(asctime)s %(levelname)s %(message)s'": passed() else: failed()
def test_answer_placeholders(): placeholders = get_answer_placeholders() if placeholders[1].replace("\'", "\"") == '"hot "' and placeholders[0].replace(" ", "").replace("\'", "\"") == '"grass"+"hopper"' \ and placeholders[2].replace(" ", "").replace("\'", "\"") == '"l"+"a"+"d"+"y"+"b"+"u"+"g"': passed() else: failed()
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if placeholder == "root": passed() else: failed()
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if placeholder == "print": # TODO: your condition here passed() else: failed("Use the print luke.")
def test_answer_placeholders(): placeholders = get_answer_placeholders() not_correct = placeholders[0] while_condition = placeholders[1] user_input = placeholders[2] equals_to = placeholders[3] less_than = placeholders[4] if not_correct == "True": # TODO: your condition here passed() else: failed("When we start, should the user be correct or incorrect?") if while_condition == "not_correct": passed() else: failed("We want the loop to keep running when what is True?") if "raw_input(" in user_input: passed() else: failed("This is where we ask the user to guess the number") if "==" in equals_to: passed() else: failed("When does the user win?") if "<" in less_than: passed() else: failed("When should we say higher than?")
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if placeholder == "logger.addHandler(logging.NullHandler())": passed() else: failed()
def test_outputs(): outputs = get_file_output() if len(outputs) >= 3 and outputs[-3:] == ['IT IS STILL SNOWING', 'SHOULD WE GO SLEDDING', 'I CANNOT FIND MY BOOTS']: passed() else: failed(message='Please try again.')
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0].replace('"', "'") if placeholder == "filename=log_filename": passed() else: failed()
def test_window(): windows = get_answer_placeholders() if windows[0] == "%d": passed() else: failed("Use %d special symbol")
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if placeholder == "False" or placeholder == '0': passed() else: failed()
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0] if "^$" in placeholder: passed() else: failed("Use '^$' to match empty string")
def test_answer_placeholders(): placeholders = get_answer_placeholders() placeholder = placeholders[0].replace('"', "'") if placeholder.startswith("logger.exception(") and placeholder.find("'") != -1: passed() else: failed("That is not correct. Be sure to call exception() with a string argument.")
from test_helper import run_common_tests, failed, passed, check_tests_pass from closest_points import minimum_distance_squared, minimum_distance_squared_naive, Point from math import fabs from random import randint if __name__ == '__main__': run_common_tests() check_tests_pass("closest_points_unit_tests.py") all_tests_passed = True for points in ([Point(-10**9, -10**9), Point(10**9, 10**9)], [Point(i, i + 1) for i in range(100)], [Point(randint(1, 10), randint(1, 10)) for _ in range(5)], [Point(randint(1, 10), randint(1, 10)) for _ in range(500)]): if fabs( minimum_distance_squared(points) - minimum_distance_squared_naive(points)) > 1e-03: all_tests_passed = False failed("Wrong answer for points={}".format(points)) break if all_tests_passed: passed()
def test_window(): window = get_answer_placeholders()[0] if "for " in window: passed() else: failed("Use a for loop to iterate over the hello_world string")
def test_window(): window = get_answer_placeholders()[0] if "print" in window and "line" in window: passed() else: failed("Use print function")
def test_window1(): window = get_answer_placeholders()[0] if "1" in window: passed() else: failed("Initialize b with 1")
def test_window3(): window = get_answer_placeholders()[2] if "tmp_var" in window: passed() else: failed("Update a with tmp_var")
def test_window2(): window = get_answer_placeholders()[1] if "b" in window and "a" in window: passed() else: failed("Update b with a + b")
def test_window(): window = get_answer_placeholders()[0] if "from " in window: passed() else: failed("Benutze hello_world importiert aus my_module")
def test_value(): output = get_file_output() if "[4, 9, 16]" in output: passed() else: failed("Use list slicing lst[index1:index2]")
self.assertRegex(helper.answers[1], "list|List|array|Array") def testAnswer3(self): self.assertEqual(helper.answers[2], "emptyArray") def testAnswer4(self): self.assertRegex(helper.answers[3], helper.re.listRegex("\"first\"", "\"second\"")) def testAnswer5(self): self.assertRegex(helper.answers[4], helper.re.listRegex("1", "2", "3", "1")) def testAnswer6(self): self.assertRegex(helper.answers[5], helper.re.listRegex("\"1\"", "\"2\"", "\"3\"", "\"4\"")) def testAnswer7(self): self.assertRegex(helper.answers[6], helper.re.listRegex("13", "1", "2", "3", "1")) if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(testCaseClass=varAanmaken) res = unittest.TextTestRunner().run(suite) if res.wasSuccessful(): passed("Congratulations") else: for el in res.failures: failed(f"There is an error in " + str(el[0])[4:12])
def test_window(): window = get_answer_placeholders()[0] if "Car" in window and "(" in window and ")" in window: passed() else: failed("Create a new car using Car()")
def test_window2(): window = get_answer_placeholders("read_file.py")[1] if "f1" in window and "readline" in window: passed() else: failed("Use 'readline' method")
def test_window(): window = get_answer_placeholders()[0] if "squares" in window and "[" in window and "]" in window and ":" in window: passed() else: failed("Use list slicing lst[index1:index2]")
def test_window(): window = get_answer_placeholders()[0] if "=" in window: passed() else: failed("Füge einen Standardwert hinzu")
def test_window3(): window = get_answer_placeholders("read_file.py")[2] if "f1" in window and "close" in window and "(" in window: passed() else: failed("Call 'close' method")
def test_answer_placeholders(): placeholders = get_answer_placeholders() list_wool = [ "white", "grey", "dark_grey", "black", "blue", "cyan", "green", "dark_green", "yellow", "orange", "brown", "red", "pink", "magenta", "violet" ] if not test_string_in(placeholders, 0, list_wool): return False if not test_string_in(placeholders, 1, list_wool): return False if not test_string(placeholders, 2, '9'): return False if not test_string(placeholders, 3, '9'): return False if not test_eval(placeholders, 4, 'cx - width // 2', [{ 'cx': 100, 'width': 9 }, { 'cx': 110, 'width': 21 }]): return False if not test_eval(placeholders, 5, 'cy - height // 2', [{ 'cy': 14, 'height': 9 }, { 'cy': 15, 'height': 21 }]): return False list_var = [x.strip() for x in placeholders[6].strip().split(",")] if len(list_var) != 2 and len(list_var) != 3: failed( "Wrong number of arguments in answer 7. Should be 2 (or 3). You have " + str(len(list_var))) + str(list_var) return False if not test_eval_phi(list_var[0], "First argument in answer 7", 'y1', [{ 'y1': 28 }, { 'y1': 36 }]): return False if not test_eval_phi(list_var[1], "Second argument in answer 7", 'y2', [{ 'y2': 28 }, { 'y2': 36 }]): return False list_var = [x.strip() for x in placeholders[7].strip().split(",")] if len(list_var) != 2 and len(list_var) != 3: failed( "Wrong number of arguments in answer 8. Should be 2 (or 3). You have " + str(len(list_var))) return False if not test_eval_phi(list_var[0], "First argument in answer 8", 'x1', [{ 'x1': 96 }, { 'x1': 104 }]): return False if not test_eval_phi(list_var[1], "Second argument in answer 8", 'x2', [{ 'x2': 96 }, { 'x2': 104 }]): return False # Can't test 8 because may have formula over several lines #if not test_formula(placeholders, 6, 'colours[(y+x)%2]') passed() return True
def test_window(): window = get_answer_placeholders()[0] if "my_object" in window and "variable1" in window: passed() else: failed("Benutze my_object.variable1 für den Zugriff")
def test_negative_index(): window = get_answer_placeholders()[0] if "-" in window: passed() else: failed("Use negative index")
def test_window_names(): window = get_answer_placeholders()[0] if "subject" in window and "name" in window: passed() else: failed("Füge einen Standardwert hinzu")
def test_column(): window = get_answer_placeholders()[0] if ":" in window: passed() else: failed("Vergesse nicht : am Ende")
def test_value(): file = import_task_file() if hasattr(file, "exclamation") and file.exclamation == "!": passed() else: failed("Use -1 index to get the last character")
def test_columns(): windows = get_answer_placeholders() if ":" in windows[0] and ":" in windows[1]: passed() else: failed("Don't forget a colon at the end")
def test_window(): window = get_answer_placeholders()[0] if "square" in window and "def " in window: passed() else: failed("Nenne die Funktion square")
def test_window(): window = get_answer_placeholders()[0] if "len(" in window: passed() else: failed("Use len() function")
def test_window(): window = get_answer_placeholders()[0] if "prime" in window and "for " in window and "primes" in window and " in " in window: passed() else: failed("Use for loop to iterate over 'primes'")
def test_window(): window = get_answer_placeholders()[0] if "==" in window: passed() else: failed("Benutze ==")
def test_window2(): window = get_answer_placeholders()[1] if "else" in window: passed() else: failed("Use else keyword")
def test_window(): window = get_answer_placeholders()[0] if "name" in window and "John" in window and "and" in window and "23" in window: passed() else: failed("Benutze das and-Schlüsselwort und den != Operator")
def test_value(): file = import_task_file() if not file.is_equal: passed() else: failed("Benutze ==")
def test_value(): file = import_task_file() if file.length == 13: passed() else: failed("Count again")
def test_window(): window = get_answer_placeholders()[0] if "phone_book" in window and "Jane" in window: passed() else: failed("Use indexing e.g. dct[key]")