def absloc(ndim_M, grid_shape_M, request, loc_with_3coord_M): if request.param == 'middle': loc = AbsLoc((np.array(grid_shape_M) - 1) // 2, ndim_M) assert loc.shape == (1, ndim_M) return loc elif request.param == 'end': loc = AbsLoc(np.array(grid_shape_M) - 1, ndim_M) assert loc.shape == (1, ndim_M) return loc elif request.param == 'origin': loc = AbsLoc(np.repeat(0, ndim_M), ndim_M) assert loc.shape == (1, ndim_M) return loc elif request.param == '3coord': loc = loc_with_3coord_M assert loc.shape == (3, ndim_M) return loc raise UserWarning("misconfiguration of test fixture")
def test_visit_counts4(cart_M, agent_id, loc_at_origin_M, loc_at_ones_M): '''when a distributed agent moves such that two of its coordinates are the same, ensure we count that visit as 1 rather than 2 visits ''' # absolute loc at [[0, ...], [1, ...]] loc_2coords = AbsLoc(np.concatenate( [loc_at_origin_M, loc_at_ones_M]), ndim=loc_at_origin_M.shape[1]) # relative loc at [[1, ...], [0, ...]] relloc = RelLoc(np.zeros(loc_2coords.shape, dtype='int')) relloc[0] = 1 relloc[-1] = 0 cart_M.add_agent(agent_id, loc_2coords) cart_M._process_agent_move(agent_id, relloc) assert (cart_M.visit_counts(loc_2coords + relloc) == np.array([1, 1])).all() # sanity check that the location of each coordinate is the same newloc = cart_M.agent_location(agent_id) assert (newloc == newloc[[0]].repeat(2, axis=0)).all()
def loc_at_ones_M(ndim_M): return AbsLoc(np.ones((1, ndim_M), dtype='int'), ndim_M)
def loc_at_origin_M(ndim_M): return AbsLoc(np.zeros((1, ndim_M), dtype='int'), ndim_M)
def loc_with_3coord_M(grid_shape_M, ndim_M): return AbsLoc(np.array([ np.array(grid_shape_M) - 1, # max point on each dimension (np.array(grid_shape_M) - 1) // 2, # middle point in each dimension np.repeat(0, ndim_M), # min point on each dimension ], dtype='int'), ndim_M)
def cart_big_twos(cart_big): return 1 + AbsLoc(np.ones((1, cart_big.grid_ndim), dtype='int'))
def relloc_small(): return AbsLoc((1, -1))
def origin_small(): return AbsLoc((0,0))