...

Text file src/golang.conradwood.net/go-easyops/utils/interpolator_test.go~

Documentation: golang.conradwood.net/go-easyops/utils

     1package main
     2
     3import "testing"
     4
     5func TestInterpolate(t *testing.T) {
     6	testinterpol(t, map[float64]float64{3: 30, 5: 50, 10: 100}, 7, 70)
     7	testinterpol(t, map[float64]float64{3: 30, 5: 50, 10: 100}, 8, 80)
     8	testinterpol(t, map[float64]float64{3: 30, 5: 50, 10: 100}, 4, 40)
     9	testinterpol(t, map[float64]float64{3: 30, 5: 50, 10: 100}, 2, 20)
    10	testinterpol(t, map[float64]float64{3: 30, 5: 50, 10: 100}, 11, 100)
    11
    12	testinterpol(t, map[float64]float64{3: 30, 5: 50, 7: 100}, 4, 40)
    13	testinterpol(t, map[float64]float64{3: 30, 5: 50, 7: 100}, 6, 75)
    14
    15}
    16func testinterpol(t *testing.T, ipm map[float64]float64, num, expected float64) {
    17	ip := &Interpolator{}
    18	ip.AddReferencePoints(ipm)
    19	res := ip.Interpolate(num)
    20	if res == expected {
    21		return
    22	}
    23	t.Logf("For interpolator (%s), value %0.1f, expected %0.1f, but got %0.1f", ip.String(), num, expected, res)
    24	t.Fail()
    25
    26}

View as plain text