def test_reduce_with_reducer(): layers = EventLayers(3) layers.add([2, 2, 2], age=1.0) layers.add([2, 2, 2], age=3.0) layers.add([2, 2, 2], age=4.0) layers.reduce(1, 3, age=np.mean) assert_array_equal(layers["age"], [[1.0, 1.0, 1.0], [3.5, 3.5, 3.5]])
def test__str__(): layers = EventLayers(5) layers.add(1.0, age=3.0) vals = str(layers) assert vals.splitlines() == [ "number_of_layers: 1", "number_of_stacks: 5", "tracking: age" ]
def test_reduce_with_attrs(): layers = EventLayers(3) layers.add([1, 1, 1], age=0.0) layers.add([1, 2, 5], age=1.0) layers.add([2, 2, 2], age=2.0) layers.reduce(age=np.sum) assert_array_equal(layers["age"], [[3.0, 3.0, 3.0]])
def test__str__(): layers = EventLayers(5) layers.add(1.0, age=3.0) vals = str(layers) assert vals.splitlines() == [ "number_of_layers: 1", "number_of_stacks: 5", "tracking: age", ]
def test_reduce_with_start(): layers = EventLayers(3) layers.add([3.0, 4.0, 5.0]) layers.add([1.0, 2.0, 0.5]) layers.add([1.0, 2.0, 0.5]) layers.reduce(1, 3) assert_array_equal(layers.dz, [[3.0, 4.0, 5.0], [2.0, 4.0, 1.0]])
def test_reduce_with_stop_less_than_start(): layers = EventLayers(3) layers.add([3.0, 4.0, 5.0]) layers.add([1.0, 2.0, 0.5]) layers.add([1.0, 2.0, 0.5]) layers.add([2.0, 5.0, 6.0]) with pytest.raises(ValueError): layers.reduce(3, 1)
def test_reduce_with_no_args(): layers = EventLayers(3) layers.add(1.5) layers.reduce() assert_array_equal(layers.dz, [[1.5, 1.5, 1.5]]) layers.add(2.5) layers.reduce() assert_array_equal(layers.dz, [[4.0, 4.0, 4.0]])
def test_setitem_with_scalar(): layers = EventLayers(5) layers.add(1., age=3.) layers.add(2., age=4.) truth = np.array([[3., 3., 3., 3., 3.], [4., 4., 4., 4., 4.]]) assert_array_equal(layers["age"], truth) layers["age"] = 2. truth = np.array([[2., 2., 2., 2., 2.], [2., 2., 2., 2., 2.]]) assert_array_equal(layers["age"], truth)
def test_setitem_with_scalar(): layers = EventLayers(5) layers.add(1.0, age=3.0) layers.add(2.0, age=4.0) truth = np.array([[3.0, 3.0, 3.0, 3.0, 3.0], [4.0, 4.0, 4.0, 4.0, 4.0]]) assert_array_equal(layers["age"], truth) layers["age"] = 2.0 truth = np.array([[2.0, 2.0, 2.0, 2.0, 2.0], [2.0, 2.0, 2.0, 2.0, 2.0]]) assert_array_equal(layers["age"], truth)
def test_set_item_with_2d(): layers = EventLayers(5) layers.add(1., age=3.) layers.add(2., age=4.) truth = np.array([[3., 3., 3., 3., 3.], [4., 4., 4., 4., 4.]]) assert_array_equal(layers["age"], truth) layers["age"] = [[4., 4., 4., 4., 4.], [7., 7., 7., 7., 7.]] truth = np.array([[4., 4., 4., 4., 4.], [7., 7., 7., 7., 7.]]) assert_array_equal(layers["age"], truth)
def test_set_item_with_2d(): layers = EventLayers(5) layers.add(1.0, age=3.0) layers.add(2.0, age=4.0) truth = np.array([[3.0, 3.0, 3.0, 3.0, 3.0], [4.0, 4.0, 4.0, 4.0, 4.0]]) assert_array_equal(layers["age"], truth) layers["age"] = [[4.0, 4.0, 4.0, 4.0, 4.0], [7.0, 7.0, 7.0, 7.0, 7.0]] truth = np.array([[4.0, 4.0, 4.0, 4.0, 4.0], [7.0, 7.0, 7.0, 7.0, 7.0]]) assert_array_equal(layers["age"], truth)
def test_adding_untracked_layer(): layers = EventLayers(3) layers.add(1., type=3., size="sand") layers.add([0., 0., 1.], type=3., size="sand") with pytest.raises(ValueError): layers.add([1.], type=3., size="sand", spam="eggs")
def test__repr__(): layers = EventLayers(5) layers.add(1., age=3.) vals = repr(layers) assert vals == "EventLayers(5)"
def test__str__(): layers = EventLayers(5) layers.add(1., age=3.) vals = str(layers) assert vals == "number_of_layers: 1\nnumber_of_stacks: 5\ntracking: age"
def test_reduce_with_start_too_big(): layers = EventLayers(3) layers.add(1) layers.reduce(2, 4) assert_array_equal(layers.dz, [[1, 1, 1]])
def test_reduce_with_unknown_property(): layers = EventLayers(3) for layer in range(4): layers.add(layer) with pytest.raises(TypeError): layers.reduce(1, 3, age=np.mean)
def test_reduce_with_one_layer(): layers = EventLayers(3) layers.add(1.0) layers.reduce() assert_array_equal(layers.dz, [[1, 1, 1]])
def test_reduce_partial_block(): layers = EventLayers(3) for layer in range(6): layers.add(layer) layers.reduce(1, 6, 4) assert_array_equal(layers.dz, [[0, 0, 0], [10, 10, 10], [5, 5, 5]])
def test_reduce_args(args): layers = EventLayers(3) for layer in range(4): layers.add(layer) layers.reduce(4) assert_array_equal(layers.dz, [[6, 6, 6]])
def test_reduce_with_missing_property(): layers = EventLayers(3) for layer in range(4): layers.add(layer, age=layer) with pytest.raises(TypeError): layers.reduce(1, 3)