Пример #1
0
def test_database_double_arg(arg):
    # Test the database where there are two command line parameters.
    # The first parameter is the name of the method to test.
    # The second parameter is the input parameter for the method that is being test.
    arg1 = arg[1].lower()
    arg2 = arg[2].lower()
    db = Database()
    if arg1 == "__contains__":
        print(arg2 in db)
    elif arg1 == "pokemon_id_exists":
        print(db.pokemon_id_exists(arg2))
    elif arg1 == "pokemon_name_exists":
        print(db.pokemon_name_exists(arg2))
    elif arg1 == "get_pokemon":
        print(db.get_pokemon(arg2))
    elif arg1 == "get_pokemon_by_name":
        print(db.get_pokemon_by_name(arg2))
    elif arg1 == "get_pokemon_by_id":
        print(db.get_pokemon_by_id(arg2))
    elif arg1 == "names_with_prefix":
        print_items(db.names_with_prefix(arg2))
    elif arg1 == "names_with_infix":
        print_items(db.names_with_infix(arg2))
    elif arg1 == "get_light":
        print_items(db.get_light(threshold=int(arg2) / 10, all_pkmn=True))
    elif arg1 == "get_dark":
        print_items(db.get_dark(threshold=int(arg2) / 10, all_pkmn=True))
    else:
        print("No such public method '" + arg + "' with two parameters"
              " exists in the Database class.")
Пример #2
0
def region_test(region_name):
    db = Database()
    # test db.get_region()
    pokemon = get_region(db, region_name)
    assert pokemon, 'No pokemon found in region: ' + region_name
    # test that region_name is in region_dict
    region_info = region_dict[region_name]
    delta = region_info.end - region_info.start
    fmt = 'Testing {}({} vs. {}): {}'
    print(fmt.format(region_name, len(pokemon), delta + 1, region_info))
    # test db.get_pokemon(id)
    middle_pokemon = db.get_pokemon(region_info.start + (delta // 2))
    assert middle_pokemon in pokemon
    # test db.get_pokemon(name)
    name = middle_pokemon.get_name()
    assert db.get_pokemon(name) in pokemon