def test_flow_accumulator_properties_D4():
    # %% set update_hill_flow_instantaneous to false and update hill flow properties explicitly

    mg = RasterModelGrid((4, 4), xy_spacing=(1, 1))
    _ = mg.add_field("topographic__elevation",
                     mg.node_x * 2 + mg.node_y,
                     at="node")
    fa = PriorityFloodFlowRouter(
        mg,
        flow_metric="D4",
        suppress_out=True,
        separate_hill_flow=True,
        hill_flow_metric="D4",
        accumulate_flow_hill=True,
        update_hill_flow_instantaneous=False,
    )
    # from landlab.components.flow_accum import FlowAccumulator
    # fa = FlowAccumulator(mg)
    fa.run_one_step()
    fa.update_hill_fdfa()

    node_drainage_area = np.array([
        0.0, 0.0, 0.0, 0.0, 2.0, 2.0, 1.0, 0.0, 2.0, 2.0, 1.0, 0.0, 0.0, 0.0,
        0.0, 0.0
    ])

    assert_array_equal(fa.node_water_discharge, node_drainage_area.flatten())
    assert_array_equal(fa.node_drainage_area, node_drainage_area.flatten())

    # Hill flow accumulation should be similar
    assert_array_equal(mg.at_node["hill_surface_water__discharge"],
                       node_drainage_area.flatten())
    assert_array_equal(mg.at_node["hill_drainage_area"],
                       node_drainage_area.flatten())
def test_seperate_hillflow_update():
    # %%
    """
    Hillflow fields cannot be updated if not initialized
    """

    # %% Default configuration
    mg1 = RasterModelGrid((6, 6), xy_spacing=(1, 1))
    mg1.add_field("topographic__elevation", mg1.node_x + mg1.node_y, at="node")
    fa1 = PriorityFloodFlowRouter(mg1, suppress_out=True)
    fa1.run_one_step()
    with pytest.raises(ValueError):
        fa1.update_hill_fdfa()