New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Napsat testy #20

Closed
encukou opened this Issue Oct 30, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@encukou
Member

encukou commented Oct 30, 2018

No description provided.

@zstankova

This comment has been minimized.

Contributor

zstankova commented Nov 5, 2018

První test je v #27

@befeleme befeleme self-assigned this Nov 8, 2018

@befeleme

This comment has been minimized.

Contributor

befeleme commented Nov 14, 2018

def get_tiles(data):
    """
    Return the complete list of tiles.
    data: a dict created from decoded Tiled 1.2 JSON file
    Get the list of all tiles from the list "data" within the list "layers". 
    """
    rotation_dict = {0:0, 10:90, 12:180, 6:270}
    tilelist = {}
    for layer in data['layers']:
        tilelist_layer = []
        for data in layer['data']:
            real_tile = data & 0xFFFFFF
            rotation_index = data >> (4*7)
            rotation = rotation_dict[rotation_index]
            tile = Tile(real_tile, rotation)
            tilelist_layer.append(tile)
        tilelist[layer['id']] = tilelist_layer
    return tilelist

Divam se na tuto funkci a zjistuju, ze nevim, jak ji testovat.
Zaprve - dela strasne moc veci a pro ty testy mam chut ji rozkouskovat minimalne jeste na:

  • get_decimal_id_from_hex(int) -> int (v desitkove soustave)
  • get_decimal_rotation_from_hex(int) -> int (v desitkove soustave)

pak se zde vytvari objekty tridy Tile, ktere se pridaji do seznamu dane vrstvy, a ty pak do slovniku. Slovnik ma nasledne podobu, u ktere taky nevim, jak nadefinovat test, priklad nize:

{1: [<__main__.Tile object at 0x7ff32797f5c0>, <__main__.Tile object at 0x7ff32797f5f8>, <__main__.Tile object at 0x7ff32797f630>, <__main__.Tile object at 0x7ff32797f668>, <__main__.Tile object at 0x7ff32797f6a0>, <__main__.Tile object at 0x7ff32797f6d8>, <__main__.Tile object at 0x7ff32797f710>]}
Any ideas? @encukou, @zstankova ?

@encukou

This comment has been minimized.

Member

encukou commented Nov 14, 2018

Začni těma dvěma menšíma funkcema.

Výsledek se dá testovat tak, že zkontroluješ např. tilelist[1].rotation == 0. (V úterý k tomu pak můžu říct víc, dej to na agendu.)

@encukou

This comment has been minimized.

Member

encukou commented Nov 14, 2018

get_decimal_id_from_hex(int) -> int (v desitkove soustave)

Číslo samo o sobě není v nějaké soustavě, jen se tak dá zapsat. 16 a 0x10 je ta samá hodnota, jen jinak zapsaná. Podobně jako „modrý robot“ a „Ivetin robot“ jsou jen jiné popisy téhož.

Lepší názvy funkcí by byly get_tile_id a get_tile_rotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment