Beispiel #1
0
def check_spline(xs, ys):
    spline_xs = range(0, int(max(xs))+1)
    spline_ys = emd_evaluate_spline(xs, ys)
    ref_spline_ys = get_reference_spline(xs, ys, spline_xs)
    try:
        check_arrays_equal(spline_ys, ref_spline_ys, decimals=12)
    except AssertionError:
        from pylab import plot, show, title, figure, legend
        figure()
        plot(ref_spline_ys, 'ro', label="Reference")
        plot(spline_ys, 'bx', ms=10, label="Result")
        legend(loc="upper left")
        title("Spline comparison")
        show()
        print("xs:", list(xs))
        print("ys:", list(ys))
        print("spline_ys:", list(spline_ys))
        print("ref_spline_ys:", list(ref_spline_ys))
        absdiff = abs(spline_ys - ref_spline_ys)
        print("absolute difference", list(absdiff))
        print("maximal difference", max(absdiff))
        raise
def test_invalid_x_notsorted():
    emd_evaluate_spline(x=[0, 2, 1], y=range(3))
def test_invalid_x_firstnotzero():
    emd_evaluate_spline(x=range(1, 4), y=range(3))
def test_invalid_x_lastnotinteger():
    emd_evaluate_spline(x=[0, 1, 2.3], y=range(3))
def test_not_equal_size():
    emd_evaluate_spline(x=range(3), y=range(4))
def test_invalid_shape():
    x = array(range(4))
    x = x.reshape((2, 2))
    emd_evaluate_spline(x=x, y=x)
def test_too_short():
    emd_evaluate_spline(x=[0], y=[1])
def test_missing():
    emd_evaluate_spline(x=range(3))
def test_bogus1():
    emd_evaluate_spline(x="foo", y="bar")