def test_its_data_becomes_invalid_if_updates_are_not_y_coordinate_consecutive( ): grid = Grid(width=3, height=3) setup_grid_cells(grid) # all fine so far grid._update_linebuffer(0) assert grid.linebuffer[grid.linebuffer_index] == [1, 0, 0] grid._update_linebuffer(2) assert grid.linebuffer[grid.linebuffer_index] == [0, 0, 1] # this'd be the correct value assert grid.linebuffer[grid.linebuffer_prev_index] != [0, 1, 0] # but instead has just the swapped old value, returning wrong data assert grid.linebuffer[grid.linebuffer_prev_index] == [1, 0, 0]
def test_indexes_swap_when_updating_the_linebuffer(): irrelevant_y_coordinate = 1 grid = Grid(width=4, height=3) grid._update_linebuffer(irrelevant_y_coordinate) assert grid.linebuffer_index == 0 assert grid.linebuffer_prev_index == 1 grid._update_linebuffer(irrelevant_y_coordinate) assert grid.linebuffer_index == 1 assert grid.linebuffer_prev_index == 0 grid._update_linebuffer(irrelevant_y_coordinate) assert grid.linebuffer_index == 0 assert grid.linebuffer_prev_index == 1
def test_fills_current_index_with_y_coordinate_line(): grid = Grid(width=3, height=3) setup_grid_cells(grid) # this also works as edge-detection case grid._update_linebuffer(0) assert grid.linebuffer[grid.linebuffer_index] == [1, 0, 0] # the other line should be empty grid._update_linebuffer(1) assert grid.linebuffer[grid.linebuffer_index] == [0, 1, 0] assert grid.linebuffer[grid.linebuffer_prev_index] == [1, 0, 0] grid._update_linebuffer(2) assert grid.linebuffer[grid.linebuffer_index] == [0, 0, 1] assert grid.linebuffer[grid.linebuffer_prev_index] == [0, 1, 0]
with context("grid setup"): with it("linebuffer is created with appropiate width and always 2 lines"): grid = Grid(width=4, height=3) expect(len(grid.linebuffer)).to(equal(2)) expect(len(grid.linebuffer[0])).to(equal(grid.width)) with it("linebuffer indexes start with current=1, previous=0"): grid = Grid(width=4, height=3) expect(grid.linebuffer_index).to(equal(1)) expect(grid.linebuffer_prev_index).to(equal(0)) with it("when updating the linebuffer, indexes swap"): irrelevant_y_coordinate = 1 grid = Grid(width=4, height=3) grid._update_linebuffer(irrelevant_y_coordinate) expect(grid.linebuffer_index).to(equal(0)) expect(grid.linebuffer_prev_index).to(equal(1)) grid._update_linebuffer(irrelevant_y_coordinate) expect(grid.linebuffer_index).to(equal(1)) expect(grid.linebuffer_prev_index).to(equal(0)) grid._update_linebuffer(irrelevant_y_coordinate) expect(grid.linebuffer_index).to(equal(0)) expect(grid.linebuffer_prev_index).to(equal(1)) with it("fills current index with y coordinate line"): grid = Grid(width=3, height=3) setup_grid_cells(grid)