def test_costl2_small_data():
    """Test if CostL2 returns the correct segmentation for small data."""
    signal = np.array([0.0, 0.1, 1.2, 1.0])
    n_samples = signal.shape[0]
    algo = Binseg(model="l2", min_size=1, jump=1).fit(signal)
    computed_break_dict = {}
    for n_bkps in range(n_samples):
        try:
            result = algo.predict(n_bkps=n_bkps)
        except Exception as e:
            result = e
            computed_break_dict
        computed_break_dict[n_bkps] = result

    expected_break_dict = {0: [4], 1: [2, 4], 2: [2, 3, 4], 3: [1, 2, 3, 4]}
    err_msg = (
        f"Wrong segmentation, expected {expected_break_dict}, ",
        "got {computed_break_dict}.",
    )
    assert expected_break_dict == computed_break_dict, err_msg
Test if CostL2 returns the correct segmentation for small data.
tests/test_costs.py