Beispiel #1
0
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
Beispiel #2
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_eval(placeholders, 1, 'y-1', [{'y': 14}, {'y': 16}]):
        return False
    if not test_eval(placeholders, 2, 'z+1', [{'z': 20}, {'z': 50}]):
        return False
    if not test_eval(placeholders, 3, 'y+1', [{'y': 14}, {'y': 16}]):
        return False
    if not test_eval(placeholders, 4, 'x', [{'x': 100}, {'x': 50}]):
        return False
    if not test_eval(placeholders, 5, 'y', [{'y': 14}, {'y': 16}]):
        return False
    passed()
    return True
Beispiel #3
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_string(placeholders, 0, "15"):
        return False
    if not test_string(placeholders, 1, "20"):
        return False
    if not test_string(placeholders, 2, "10"):
        return False
    if not test_exec(placeholders, 3,
                     "node_dict[(16, 20, 10)] = 'default:glass'", [{
                         'node_dict': {
                             (15, 20, 10): 'default:wood'
                         }
                     }]):
        return False
    if not test_exec(placeholders, 4,
                     "node_dict[(16, 20, z)] = 'default:stone'", [{
                         'z': 10,
                         'node_dict': {
                             (15, 20, 10): 'default:wood',
                             (16, 20, 10): 'default:glass'
                         }
                     }, {
                         'z': 11,
                         'node_dict': {
                             (15, 20, 10): 'default:wood',
                             (16, 20, 10): 'default:glass'
                         }
                     }]):
        return False
    if not test_exec(placeholders, 5, "del(node_dict[(x, y, z)])", [{
            'x': 15,
            'y': 20,
            'z': 10.1,
            'node_dict': {
                (15, 20, 10.1): 'wool:blue'
            }
    }]):
        return False
    if not test_eval(placeholders,
                     6,
                     "math.floor(z+0.5)", [{
                         'z': -1.49
                     }, {
                         'z': -0.51
                     }, {
                         'z': -0.49
                     }, {
                         'z': 0.49
                     }, {
                         'z': 0.51
                     }, {
                         'z': 1.49
                     }],
                     modules="math"):
        return False
    passed()
    return True
Beispiel #4
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    s = placeholders[0]
    if not s or len(s) < 4:
        failed("Answer 1 missing. You have " + str(s))
        return False
    if s[1] != "{" or s[-2] != "}":
        failed(
            "Answer 1 required a JSON string (starts with '{' and ends with '}'. You have "
            + str(s))
        return False
    try:
        j = json.loads(s[1:-1])
    except:
        failed("Answer 1 exception when converting from JSON. You have " +
               str(s))
        return False
    if "param2" not in j:
        failed("Answer 1 requires a param2 attribute. You have " + str(s))
        return False
    if str(j["param2"]) != "1":
        failed(
            "Answer 1 has wrong value of param2. Needs to be for upward in increasing x direction. You have "
            + str(s))
        return False
    if not test_eval(placeholders, 1, "'carts:rail'", [{}]):
        return False
    if not test_eval(placeholders, 2, "'carts:powerrail'", [{}]):
        return False
    if not test_eval(placeholders, 3, "x//2%2", [{
            'x': 0
    }, {
            'x': 1
    }, {
            'x': 2
    }, {
            'x': 3
    }, {
            'x': 4
    }]):
        return False
    passed()
    return True
Beispiel #5
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_eval(placeholders, 1, 'x+1', [{'x': 50}, {'x': 100}]):
        return False
    if not test_eval(placeholders, 2, 'y+1', [{'y': 14}, {'y': 16}]):
        return False
    if not test_eval(placeholders, 3, 'z+1', [{'z': 20}, {'z': 50}]):
        return False
    if not test_string(placeholders, 4, 'glass'): return False
    if not test_eval(placeholders, 5, "x, y, z", [{
            'x': 100,
            'y': 14,
            'z': 0
    }]):
        return False
    if placeholders[6].find("wool:") != 0:
        failed("Answer 7 should start with 'wool:'. Your answer is '" +
               placeholders[6] + "'")
        return False
    passed()
    return True
Beispiel #6
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()

    # Answer 0 can be str or dict. If str then convert to dict before testing
    s = eval(placeholders[0])
    if isinstance(s, str):
        placeholders[0] = s
    s = eval(placeholders[0])
    if "direction" in s:
        if not test_eval(
                placeholders, 0,
                '{"name": "stairs:stair_stonebrick", "direction": "+x"}',
            [{}]):
            return False
    else:
        if not test_eval(placeholders, 0,
                         '{"name": "stairs:stair_stonebrick", "param2": "1"}'):
            return False
    if not test_eval(placeholders, 1, "'carts:rail'", [{}]):
        return False
    if not test_eval(placeholders, 2, "'carts:powerrail'", [{}]):
        return False
    if not test_eval(placeholders, 3, "x//2%2", [{
            'x': 0
    }, {
            'x': 1
    }, {
            'x': 2
    }, {
            'x': 3
    }, {
            'x': 4
    }]):
        return False
    passed()
    return True
Beispiel #7
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_string(placeholders, 0, str(x1)): return False
    if not test_string(placeholders, 1, str(x2)): return False
    if not test_string(placeholders, 2, str(y)): return False
    if not test_eval(placeholders, 4, 'y', [{'y': 14}, {'y': 16}]):
        return False
    if not test_eval(placeholders, 5, 'z-2', [{'z': 20}, {'z': 50}]):
        return False
    if not test_eval(placeholders, 6, 'y+6', [{'y': 14}, {'y': 16}]):
        return False
    if not test_eval(placeholders, 7, 'z+2', [{'z': 20}, {'z': 50}]):
        return False
    if not test_eval(placeholders, 8, 'y+1', [{'y': 14}, {'y': 16}]):
        return False
    if not test_eval(placeholders, 9, 'z-1', [{'z': 20}, {'z': 50}]):
        return False
    if not test_eval(placeholders, 10, 'y+5', [{'y': 14}, {'y': 16}]):
        return False
    if not test_eval(placeholders, 11, 'z+1', [{'z': 20}, {'z': 50}]):
        return False
    passed()
    return True
Beispiel #8
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_eval(placeholders, 0, "math.floor(x+0.5)", [{'x': -1.49}, {'x': -0.51}, {'x': -0.49}, {'x': 0.49}, {'x': 0.51}, {'x': 1.49}], "math"):
        return False
    if not test_eval(placeholders, 1, "math.floor(y+0.5)", [{'y': -1.49}, {'y': -0.51}, {'y': -0.49}, {'y': 0.49}, {'y': 0.51}, {'y': 1.49}], "math"):
        return False
    if not test_eval(placeholders, 2, "math.floor(z+0.5)", [{'z': -1.49}, {'z': -0.51}, {'z': -0.49}, {'z': 0.49}, {'z': 0.51}, {'z': 1.49}], "math"):
        return False
    if not test_string(placeholders, 3, "15"):
        return False
    if not test_string(placeholders, 4, "20"):
        return False
    if not test_string(placeholders, 5, "10"):
        return False
    if not test_eval(placeholders, 6, '"default:wood"'):
        return False
    if not test_eval(placeholders, 7, '16, 20, 10, "default:glass"', [{}]):
        return False
    if not test_eval(placeholders, 8, '16, 20, z, "default:stone"', [{'z':10}, {'z':11}]):
        return False
    if not test_eval(placeholders, 9, 'x, y, z, "wool:blue"', [{'x':5,'y':25,'z':10}, {'x':55,'y':255,'z':11}]):
        return False
    passed()
    return True
Beispiel #9
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_eval(placeholders, 0, "platform['z']", [{
            'platform': {
                'z': 10
            }
    }, {
            'platform': {
                'z': 20
            }
    }]):
        return False
    if not test_eval(placeholders, 1,
                     "room['height'] if 'height' in room else 5", [{
                         'room': {
                             'height': 6
                         }
                     }, {
                         'room': {
                             'height': 1
                         }
                     }, {
                         'room': {
                             'length': 20
                         }
                     }]):
        return False
    if not test_eval(
            placeholders, 2,
            "materials['station_stair'] if 'station_stair' in materials else 'stairs:stair_wood'",
        [{
            'materials': {
                'station_stair': 'stairs:stair_stonebrick'
            }
        }, {
            'materials': {
                'station_stair': 'stairs:stair_stone'
            }
        }, {
            'materials': {
                'length': 20
            }
        }]):
        return False
    if not test_eval(placeholders, 3, "door[:-2]", [{
            'door': 'doors:door_wood_a'
    }, {
            'door': 'doors:door_wood_b'
    }, {
            'door': 'doors:door_iron_a'
    }]):
        return False
    if not test_eval(placeholders, 4, "range(levels)", [{
            'levels': 3
    }, {
            'levels': 5
    }]):
        return False
    if not test_eval(placeholders, 5, "station_width + 2 - 2 * roof_layer",
                     [{
                         'station_width': 10,
                         'roof_layer': 1
                     }, {
                         'station_width': 9,
                         'roof_layer': 3
                     }]):
        return False
    passed()
Beispiel #10
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_exec(placeholders, 0,
                     "xmin, y_at_xmin, xmax, y_at_xmax = x2, y2, x1, y1",
                     [{
                         'xmin': 1,
                         'y_at_xmin': 2,
                         'xmax': 3,
                         'y_at_xmax': 4,
                         'x2': 50,
                         'y2': 10,
                         'x1': 100,
                         'y1': 15
                     }, {
                         'xmin': 4,
                         'y_at_xmin': 3,
                         'xmax': 2,
                         'y_at_xmax': 1,
                         'x2': 55,
                         'y2': 12,
                         'x1': 150,
                         'y1': 11
                     }]):
        return False
    if not test_eval(placeholders, 1, "tunnel_y > y_at_xmin", [{
            'tunnel_y': 50,
            'y_at_xmin': 40
    }, {
            'tunnel_y': 30,
            'y_at_xmin': 35
    }]):
        return False
    phi = 'dict(' + placeholders[2] + ")"
    if not test_eval_phi(
            phi, "Answer 3",
            'dict(platform_at_xmax, room=room, materials=materials, levels=3)',
        [{
            'platform_at_xmax': {
                'x': 1,
                'levels': 1
            },
            'room': {
                'length': 10
            },
            'materials': {
                'stair': 'wood'
            },
            'levels': 2
        }, {
            'platform_at_xmax': {
                'x': 3,
                'levels': 1
            },
            'room': {
                'length': 15
            },
            'materials': {
                'stair': 'wool'
            },
            'levels': 1
        }]):
        return False
    phi = 'dict(' + placeholders[3] + ")"
    if not test_eval_phi(
            phi, "Answer 4",
            'dict(platform_at_xmin, room=room, materials=materials, levels=1)',
        [{
            'platform_at_xmin': {
                'x': 1,
                'levels': 1
            },
            'room': {
                'length': 10
            },
            'materials': {
                'stair': 'wood'
            },
            'levels': 2
        }, {
            'platform_at_xmin': {
                'x': 3,
                'levels': 1
            },
            'room': {
                'length': 15
            },
            'materials': {
                'stair': 'wool'
            },
            'levels': 1
        }]):
        return False
    passed()
    return True
Beispiel #11
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_eval(placeholders, 0, "dict()", list_data=[{}]): return False
    if not test_exec(placeholders, 1, "scores['andy']=10", [{"scores": {}}]):
        return False
    if not test_exec(placeholders, 2, "scores['betty']=15", [{
            "scores": {
                'andy': 10
            }
    }]):
        return False
    if not test_exec(placeholders, 3, "scores['cathy']=12", [{
            "scores": {
                'andy': 10,
                'betty': 15
            }
    }]):
        return False
    if not test_exec(placeholders, 4, "scores['andy']=scores['andy']+3", [{
            "scores": {
                'andy': 10,
                'betty': 15,
                'cathy': 12
            }
    }]):
        return False
    if not test_eval(placeholders,
                     5,
                     "scores.items()",
                     list_data=[{
                         "scores": {
                             'andy': 13,
                             'betty': 15,
                             'cathy': 12
                         }
                     }]):
        return False
    if not test_eval(placeholders,
                     6,
                     "score",
                     list_data=[{
                         "score": 13
                     }, {
                         'score': 15
                     }, {
                         'score': 12
                     }]):
        return False
    if not test_eval(placeholders,
                     7,
                     "score",
                     list_data=[{
                         "score": 13
                     }, {
                         'score': 15
                     }, {
                         'score': 12
                     }]):
        return False
    if not test_eval(placeholders,
                     8,
                     "name",
                     list_data=[{
                         "name": 'andy'
                     }, {
                         'name': 'betty'
                     }, {
                         'name': 'cathy'
                     }]):
        return False
    passed()
    return True
Beispiel #12
0
def test_answer_placeholders():
    placeholders = get_answer_placeholders()
    if not test_exec(placeholders, 0, "from minetest_helper import set_node",
                     []):
        return False
    if not test_eval(placeholders, 1, "1 if x2 > x1 else -1", [{
            'x1': 1,
            'x2': 5
    }, {
            'x1': 10,
            'x2': 9
    }]):
        return False
    if not test_eval(placeholders, 2, "1 if y2 > y1 else -1", [{
            'y1': 1,
            'y2': 5
    }, {
            'y1': 10,
            'y2': 9
    }]):
        return False
    if not test_eval(placeholders, 3, "1 if z2 > z1 else -1", [{
            'z1': 1,
            'z2': 5
    }, {
            'z1': 10,
            'z2': 9
    }]):
        return False
    if not test_exec(placeholders, 4, "node_lists[item] = []",
                     [{
                         'node_lists': {},
                         'item': "air"
                     }, {
                         'node_lists': {
                             'air': [(1, 2, 3)]
                         },
                         'item': "default:stone"
                     }]):
        return False
    if not test_exec(placeholders, 5, "node_lists[item].append(pos)",
                     [{
                         'node_lists': {
                             'air': []
                         },
                         'item': "air",
                         "pos": (10, 20, 30)
                     }, {
                         'node_lists': {
                             'air': [(1, 2, 3)]
                         },
                         'item': "air",
                         'pos': (2, 3, 4)
                     }]):
        return False
    if not test_exec(placeholders, 6, "item_list.append(key)",
                     [{
                         'item_list': ['air'],
                         'item': "default:stone"
                     }, {
                         'item_list': ['default:glass'],
                         'item': "default:wood"
                     }]):
        return False
    if not test_eval(placeholders, 7, "node_lists[item]", [{
            'node_lists': {
                'air': [(10, 20, 30)]
            },
            'item': "air"
    }, {
            'node_lists': {
                'air': [(1, 2, 3), (2, 3, 4)]
            },
            'item': "air"
    }]):
        return False
    passed()
    return True