当前位置: 首页>>代码示例>>Golang>>正文


Golang assert.InDelta函数代码示例

本文整理汇总了Golang中github.com/stretchr/testify/assert.InDelta函数的典型用法代码示例。如果您正苦于以下问题:Golang InDelta函数的具体用法?Golang InDelta怎么用?Golang InDelta使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了InDelta函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestLP

// TestLP tests a real-valued linear programming example
func TestLP(t *testing.T) {
	lp := NewLP(0, 2)
	lp.SetVerboseLevel(NEUTRAL)
	lp.SetColName(0, "x")
	lp.SetColName(1, "y")
	assert.Equal(t, "x", lp.ColName(0))
	assert.Equal(t, "y", lp.ColName(1))

	lp.AddConstraint([]float64{120.0, 210.0}, LE, 15000)
	lp.AddConstraintSparse([]Entry{Entry{Col: 0, Val: 110.0}, Entry{Col: 1, Val: 30.0}}, LE, 4000)
	lp.AddConstraintSparse([]Entry{Entry{Col: 1, Val: 1.0}, Entry{Col: 0, Val: 1.0}}, LE, 75)

	lp.SetObjFn([]float64{143, 60})
	lp.SetMaximize()

	lpString := "/* Objective function */\nmax: +143 x +60 y;\n\n/* Constraints */\n+120 x +210 y <= 15000;\n+110 x +30 y <= 4000;\n+x +y <= 75;\n"
	assert.Equal(t, lpString, lp.WriteToString())

	lp.Solve()

	delta := 0.000001
	assert.InDelta(t, 6315.625, lp.Objective(), delta)

	vars := lp.Variables()
	assert.Equal(t, len(vars), 2)
	assert.InDelta(t, 21.875, vars[0], delta)
	assert.InDelta(t, 53.125, vars[1], delta)
}
开发者ID:gaffo,项目名称:golp,代码行数:29,代码来源:lp_test.go

示例2: TestDecodeLineString

func TestDecodeLineString(t *testing.T) {
	data, _ := hex.DecodeString("02000202020808")
	geom, err := Decode(bytes.NewReader(data))

	if err != nil {
		t.Fatalf("Failed to decode point geometry: err = %s", err)
	}

	t.Logf("Geom: %+v\n", geom)

	p, ok := geom.(*LineString)

	if !ok {
		t.Fatalf("Expected LineString geometry")
	}

	assert.Equal(t, LINESTRING, p.Type())
	assert.Equal(t, XY, p.Dim())
	assert.Equal(t, 2, len(p.Coords))

	assert.InDelta(t, 1, p.Coords[0][0], 1e-6)
	assert.InDelta(t, 1, p.Coords[0][1], 1e-6)

	assert.InDelta(t, 5, p.Coords[1][0], 1e-6)
	assert.InDelta(t, 5, p.Coords[1][1], 1e-6)
}
开发者ID:devork,项目名称:twkb,代码行数:26,代码来源:twkb_test.go

示例3: TestTanhKernelShouldPass1

func TestTanhKernelShouldPass1(t *testing.T) {
	k := TanhKernel(1)

	// test different dot products which
	// should be valid

	// when constant is 0, default to -1.0

	assert.InDelta(t, math.Tanh(1.0-1.0), k([]float64{
		0.0, 1.0, 1.0, 0.0,
	}, []float64{
		0.0, 1.0, 0.0, 0.0,
	}), 5e-4, "Dot product should be valid")

	assert.InDelta(t, math.Tanh(6.0-1.0), k([]float64{
		15.0, 1.0, -1.0, 0.0,
	}, []float64{
		1.0, 1.0, 10.0, 0.0,
	}), 5e-4, "Dot product should be valid")

	assert.InDelta(t, math.Tanh(-84.0-1.0), k([]float64{
		15.0, 1.0, -1.0, 0.0,
	}, []float64{
		1.0, 1.0, 100.0, 0.0,
	}), 5e-4, "Dot product should be valid")
}
开发者ID:gao8954,项目名称:goml,代码行数:26,代码来源:kernel_test.go

示例4: TestThreeSpecsOneOverfull

// TestThreeSpecsOneOverfull verifies that the scheduler behaves reasonably
// if one work spec has more jobs than its weight suggests.
func TestThreeSpecsOneOverfull(t *testing.T) {
	metas := map[string]*WorkSpecMeta{
		"one": &WorkSpecMeta{
			Weight:         1,
			PendingCount:   0,
			AvailableCount: 1000,
		},
		"two": &WorkSpecMeta{
			Weight:         5,
			PendingCount:   0,
			AvailableCount: 1000,
		},
		"three": &WorkSpecMeta{
			Weight:         1,
			PendingCount:   99,
			AvailableCount: 1000,
		},
	}
	trials := 1000
	counts := runScheduler(t, metas, trials)
	// This setup produces a negative score for "three"!  "one"
	// should have a score of 100, and "two" 500, but "three"
	// should come up with
	// (weight * (total pending + 1)) - pending * total weight
	// 1 * 100 - 99 * 7 = 100 - 693 = -593
	// and so "three" should basically just get ignored.
	assert.InDelta(t, trials*1/6, counts["one"], 3*stdDev(trials, 1, 6))
	assert.InDelta(t, trials*5/6, counts["two"], 3*stdDev(trials, 5, 6))
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:31,代码来源:scheduler_test.go

示例5: TestLinearRegression

func TestLinearRegression(t *testing.T) {
	// http://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Norris.dat
	data := [][]float64{{0.1, 0.2}, {338.8, 337.4}, {118.1, 118.2},
		{888.0, 884.6}, {9.2, 10.1}, {228.1, 226.5}, {668.5, 666.3}, {998.5, 996.3},
		{449.1, 448.6}, {778.9, 777.0}, {559.2, 558.2}, {0.3, 0.4}, {0.1, 0.6}, {778.1, 775.5},
		{668.8, 666.9}, {339.3, 338.0}, {448.9, 447.5}, {10.8, 11.6}, {557.7, 556.0},
		{228.3, 228.1}, {998.0, 995.8}, {888.8, 887.6}, {119.6, 120.2}, {0.3, 0.3},
		{0.6, 0.3}, {557.6, 556.8}, {339.3, 339.1}, {888.0, 887.2}, {998.5, 999.0},
		{778.9, 779.0}, {10.2, 11.1}, {117.6, 118.3}, {228.9, 229.2}, {668.4, 669.1},
		{449.2, 448.9}, {0.2, 0.5}}

	var xArray []float64
	var yArray []float64

	for _, values := range data {
		xArray = append(xArray, values[1])
		yArray = append(yArray, values[0])
	}

	regression := NewRegression()
	regression.PushAll(xArray, yArray)
	m, c := regression.Coefficients()

	assert := assert.New(t)
	assert.InDelta(m, 1.0021168180204547, 10E-12, "slope is not equal to spec")
	assert.InDelta(c, -0.262323073774029, 10E-12, "intercept is not equal to spec within reason")
}
开发者ID:jhorwit2,项目名称:simple-regression,代码行数:27,代码来源:regression_test.go

示例6: TestTwoUnequalSpecsWithWork

// TestTwoUnequalSpecsWithWork verifies that the simplified scheduler
// picks two equivalent work specs with very different weights, and
// with some pending work.
func TestTwoUnequalSpecsWithWork(t *testing.T) {
	metas := map[string]*WorkSpecMeta{
		"one": &WorkSpecMeta{
			Weight:         1,
			AvailableCount: 1000,
		},
		"two": &WorkSpecMeta{
			Weight:         10,
			PendingCount:   2,
			AvailableCount: 998,
		},
	}
	trials := 1000
	counts := runScheduler(t, metas, trials)
	// These actual ratios come from the way the scheduler makes
	// its choices.  There are 2 work units pending, and there
	// will be 3 in total if one more is added.  Work spec "one"
	// "wants" 1/11 of this total, or 3/11 in all.  Work spec
	// "two" "wants" 10/11 of this total, or 30/11, but already
	// has 22/11 pending, so it "wants" 8/11 more.
	assert.InDelta(t, trials*3/11, counts["one"],
		3*stdDev(trials, 3, 11))
	assert.InDelta(t, trials*8/11, counts["two"],
		3*stdDev(trials, 8, 11))
}
开发者ID:diffeo,项目名称:go-coordinate,代码行数:28,代码来源:scheduler_test.go

示例7: testJobs

func testJobs(t *testing.T, hd *HealthD) {
	recorder := httptest.NewRecorder()
	request, _ := http.NewRequest("GET", "/healthd/jobs", nil)
	hd.apiRouter().ServeHTTP(recorder, request)
	assert.Equal(t, 200, recorder.Code)

	var resp ApiResponseJobs
	err := json.Unmarshal(recorder.Body.Bytes(), &resp)

	assert.NoError(t, err)
	assert.Equal(t, len(resp.Jobs), 1)
	job := resp.Jobs[0]
	assert.Equal(t, job.Name, "foo")
	assert.EqualValues(t, job.Count, 2)
	assert.EqualValues(t, job.CountSuccess, 1)
	assert.EqualValues(t, job.CountValidationError, 1)
	assert.EqualValues(t, job.CountError, 0)
	assert.EqualValues(t, job.CountPanic, 0)
	assert.EqualValues(t, job.CountJunk, 0)
	assert.EqualValues(t, job.NanosSum, 14443)
	assert.EqualValues(t, job.NanosMin, 5678)
	assert.EqualValues(t, job.NanosMax, 8765)
	assert.InDelta(t, job.NanosAvg, 7221.5, 0.01)
	assert.InDelta(t, job.NanosSumSquares, 1.09064909e+08, 0.01)
	assert.InDelta(t, job.NanosStdDev, 2182.8386, 0.01)
}
开发者ID:leobcn,项目名称:health,代码行数:26,代码来源:healthd_test.go

示例8: TestLinesWithSimilarAngle

func TestLinesWithSimilarAngle(t *testing.T) {
	examples := []struct {
		angle   float64
		lines   []polarLine
		similar []polarLine
		other   []polarLine
	}{
		{
			angle:   0,
			lines:   []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: 0.5}, polarLine{Theta: -0.49}, polarLine{Theta: -0.5}},
			similar: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: -0.49}},
			other:   []polarLine{polarLine{Theta: 0.5}, polarLine{Theta: -0.5}},
		},
		{
			angle:   2 * math.Pi,
			lines:   []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: 0.5}, polarLine{Theta: -0.49}, polarLine{Theta: -0.5}},
			similar: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: -0.49}},
			other:   []polarLine{polarLine{Theta: 0.5}, polarLine{Theta: -0.5}},
		},
		{
			angle:   math.Pi,
			lines:   []polarLine{polarLine{Theta: math.Pi + 0, Distance: 1}, polarLine{Theta: math.Pi + 0, Distance: 1000}, polarLine{Theta: math.Pi + 0.49}, polarLine{Theta: math.Pi + 0.5}, polarLine{Theta: math.Pi - 0.49}, polarLine{Theta: math.Pi - 0.5}},
			similar: []polarLine{polarLine{Theta: math.Pi + 0, Distance: 1}, polarLine{Theta: math.Pi + 0, Distance: 1000}, polarLine{Theta: math.Pi + 0.49}, polarLine{Theta: math.Pi - 0.49}},
			other:   []polarLine{polarLine{Theta: math.Pi + 0.5}, polarLine{Theta: math.Pi - 0.5}},
		},
		{
			angle:   math.Pi,
			lines:   []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: 0.5}, polarLine{Theta: -0.49}, polarLine{Theta: -0.5}},
			similar: []polarLine{},
			other:   []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: 0.5}, polarLine{Theta: -0.49}, polarLine{Theta: -0.5}},
		},
		{
			angle:   0,
			lines:   []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: -0.49}},
			similar: []polarLine{polarLine{Theta: 0, Distance: 1}, polarLine{Theta: 0, Distance: 1000}, polarLine{Theta: 0.49}, polarLine{Theta: -0.49}},
			other:   []polarLine{},
		},
	}

	for _, tt := range examples {
		similar, other := linesWithSimilarAngle(tt.lines, tt.angle)
		if !assert.Len(t, similar, len(tt.similar)) {
			t.Logf("Got:\n%v\nexpecting:\n%v", similar, tt.similar)
			t.FailNow()
		}
		for i, line := range similar {
			assert.InDelta(t, tt.similar[i].Theta, line.Theta, thetaDelta)
			assert.Equal(t, tt.similar[i].Distance, line.Distance)
		}

		if !assert.Len(t, other, len(tt.other)) {
			t.Logf("Got:\n%v\nexpecting:\n%v", similar, tt.similar)
			t.FailNow()
		}
		for i, line := range other {
			assert.InDelta(t, tt.other[i].Theta, line.Theta, thetaDelta)
			assert.Equal(t, tt.other[i].Distance, line.Distance)
		}
	}
}
开发者ID:mrfuxi,项目名称:sudoku,代码行数:60,代码来源:low_structures_test.go

示例9: TestMIP

// TestMIP tests a mixed-integer programming example
func TestMIP(t *testing.T) {
	lp := NewLP(0, 4)
	lp.AddConstraintSparse([]Entry{{0, 1.0}, {1, 1.0}}, LE, 5.0)
	lp.AddConstraintSparse([]Entry{{0, 2.0}, {1, -1.0}}, GE, 0.0)
	lp.AddConstraintSparse([]Entry{{0, 1.0}, {1, 3.0}}, GE, 0.0)
	lp.AddConstraintSparse([]Entry{{2, 1.0}, {3, 1.0}}, GE, 0.5)
	lp.AddConstraintSparse([]Entry{{2, 1.0}}, GE, 1.1)
	lp.SetObjFn([]float64{-1.0, -2.0, 0.1, 3.0})

	lp.SetInt(2, true)
	assert.Equal(t, lp.IsInt(2), true)

	lp.Solve()

	delta := 0.000001
	assert.InDelta(t, -8.133333333, lp.Objective(), delta)

	vars := lp.Variables()
	assert.Equal(t, lp.NumCols(), 4)
	assert.Equal(t, len(vars), 4)
	assert.InDelta(t, 1.6666666666, vars[0], delta)
	assert.InDelta(t, 3.3333333333, vars[1], delta)
	assert.InDelta(t, 2.0, vars[2], delta)
	assert.InDelta(t, 0.0, vars[3], delta)
}
开发者ID:gaffo,项目名称:golp,代码行数:26,代码来源:lp_test.go

示例10: TestEncodePoint

func TestEncodePoint(t *testing.T) {
	expected := &geom.Point{
		geom.Hdr{
			Dim:  geom.XYZ,
			Srid: 27700,
		},
		[]float64{-0.118340, 51.503475, -12.34567890},
	}

	var sb bytes.Buffer
	err := Encode(expected, &sb)

	if err != nil {
		t.Fatalf("failed to marshal point: %s", err)
	}

	got := make(map[string]interface{})
	err = json.Unmarshal(sb.Bytes(), &got)

	if err != nil {
		t.Fatalf("Failed to parse generated GeoJSON: error %s", err)
	}

	t.Logf("%s\n", string(sb.Bytes()))

	assert.Equal(t, "Point", got["type"])

	coords := got["coordinates"].([]interface{})
	assert.InDelta(t, -0.118340, coords[0].(float64), 1e-9)
	assert.InDelta(t, 51.503475, coords[1].(float64), 1e-9)
	assert.InDelta(t, -12.34567890, coords[2].(float64), 1e-9)
}
开发者ID:devork,项目名称:geom,代码行数:32,代码来源:encoder_test.go

示例11: TestPolygon

func TestPolygon(t *testing.T) {
	datasets := []struct {
		data string
		srid uint32
		dim  geom.Dimension
	}{
		{"002000000300006c340000000100000005403e0000000000004024000000000000404400000000000040440000000000004034000000000000404400000000000040240000000000004034000000000000403e0000000000004024000000000000", 27700, geom.XY}, // ewkb_xdr
		{"0103000020346c000001000000050000000000000000003e4000000000000024400000000000004440000000000000444000000000000034400000000000004440000000000000244000000000000034400000000000003e400000000000002440", 27700, geom.XY}, // ewkb_hdr
		{"00000000030000000100000005403e0000000000004024000000000000404400000000000040440000000000004034000000000000404400000000000040240000000000004034000000000000403e0000000000004024000000000000", 0, geom.XY},             // wkb_hdr
		{"010300000001000000050000000000000000003e4000000000000024400000000000004440000000000000444000000000000034400000000000004440000000000000244000000000000034400000000000003e400000000000002440", 0, geom.XY},             // wkb_xdr
	}

	for _, dataset := range datasets {
		t.Log("Decoding HEX String: DIM = ", dataset.dim, ", Data = ", dataset.data)
		data, err := hex.DecodeString(dataset.data)

		if err != nil {
			t.Fatal("Failed to decode HEX string: err = ", err)
		}

		r := bytes.NewReader(data)

		g, err := Decode(r)

		if err != nil {
			t.Fatal("Failed to parse Polygon: err = ", err)
		}

		assert.Equal(t, "polygon", g.Type())

		polygon := g.(*geom.Polygon)

		t.Log(polygon)

		assert.Equal(t, dataset.dim, polygon.Dimension(), "Expected dim %v, but got %v ", dataset.dim, g.Dimension())
		assert.Equal(t, dataset.srid, polygon.SRID(), "Expected srid %v, but got %v ", dataset.srid, g.SRID())

		assert.Equal(t, 1, len(polygon.Rings))

		lr := polygon.Rings[0]

		assert.Equal(t, 5, len(lr.Coordinates))

		assert.InDelta(t, 30, lr.Coordinates[0][0], 1e-9)
		assert.InDelta(t, 10, lr.Coordinates[0][1], 1e-9)

		assert.InDelta(t, 40, lr.Coordinates[1][0], 1e-9)
		assert.InDelta(t, 40, lr.Coordinates[1][1], 1e-9)

		assert.InDelta(t, 20, lr.Coordinates[2][0], 1e-9)
		assert.InDelta(t, 40, lr.Coordinates[2][1], 1e-9)

		assert.InDelta(t, 10, lr.Coordinates[3][0], 1e-9)
		assert.InDelta(t, 20, lr.Coordinates[3][1], 1e-9)

		assert.InDelta(t, 30, lr.Coordinates[4][0], 1e-9)
		assert.InDelta(t, 10, lr.Coordinates[4][1], 1e-9)
	}
}
开发者ID:devork,项目名称:geom,代码行数:59,代码来源:decoder_test.go

示例12: assertEqualColours

func assertEqualColours(t *testing.T, expected *Colour, c *Colour) {
	assert := assert.New(t)
	colourEpsilon := 0.0001

	assert.InDelta(expected.R, c.R, colourEpsilon)
	assert.InDelta(expected.G, c.G, colourEpsilon)
	assert.InDelta(expected.B, c.B, colourEpsilon)
}
开发者ID:DexterLB,项目名称:traytor,代码行数:8,代码来源:colours_test.go

示例13: TestEncodeMultiPoint

func TestEncodeMultiPoint(t *testing.T) {
	expected := &geom.MultiPoint{
		geom.Hdr{
			Dim:  geom.XY,
			Srid: 4326,
		},
		[]geom.Point{
			{
				geom.Hdr{
					Dim:  geom.XY,
					Srid: 4326,
				},
				[]float64{-105.01621, 39.57422},
			},
			{
				geom.Hdr{
					Dim:  geom.XY,
					Srid: 4326,
				},
				[]float64{-80.6665134, 35.0539943},
			},
		},
	}

	var sb bytes.Buffer
	err := Encode(expected, &sb)

	if err != nil {
		t.Fatalf("failed to marshal MultiPoint: %s", err)
	}

	got := make(map[string]interface{})
	err = json.Unmarshal(sb.Bytes(), &got)

	if err != nil {
		t.Fatalf("Failed to parse generated GeoJSON: error %s", err)
	}

	t.Logf("%s\n", string(sb.Bytes()))

	assert.Equal(t, "MultiPoint", got["type"])

	coords := got["coordinates"].([]interface{})

	assert.Equal(t, 2, len(coords))

	coord := coords[0].([]interface{})

	for idx, value := range expected.Points[0].Coordinate {
		assert.InDelta(t, value, coord[idx].(float64), 1e-9)
	}

	coord = coords[1].([]interface{})

	for idx, value := range expected.Points[1].Coordinate {
		assert.InDelta(t, value, coord[idx].(float64), 1e-9)
	}
}
开发者ID:devork,项目名称:geom,代码行数:58,代码来源:encoder_test.go

示例14: TestNormalising

func TestNormalising(t *testing.T) {
	assert := assert.New(t)
	v := NewVec3(1, 2, 3)
	normalised := v.Normalised()
	v.Normalise()

	assert.InDelta(1, v.Length(), Epsilon, "Normalising should make vector's lenght 1")
	assert.InDelta(1, normalised.Length(), Epsilon, "Normalised should return vector with length 1")
}
开发者ID:DexterLB,项目名称:traytor,代码行数:9,代码来源:vector_test.go

示例15: TestOnlineOneDXShouldPass1

func TestOnlineOneDXShouldPass1(t *testing.T) {
	// create the channel of data and errors
	stream := make(chan base.Datapoint, 100)
	errors := make(chan error, 20)

	model := NewLogistic(base.StochasticGA, .0001, 0, 0, nil, nil, 1)

	go model.OnlineLearn(errors, stream, func(theta [][]float64) {})

	// start passing data to our datastream
	//
	// we could have data already in our channel
	// when we instantiated the Perceptron, though
	for iter := 0; iter < 3000; iter++ {
		for i := -40.0; i < 40; i += 0.15 {
			if 10+i/2 > 0 {
				stream <- base.Datapoint{
					X: []float64{i},
					Y: []float64{1.0},
				}
			} else {
				stream <- base.Datapoint{
					X: []float64{i},
					Y: []float64{0},
				}
			}
		}
	}

	// close the dataset
	close(stream)

	err, more := <-errors

	assert.Nil(t, err, "Learning error should be nil")
	assert.False(t, more, "There should be no errors returned")

	// test a larger dataset now
	iter := 0
	for i := -100.0; i < 100; i += 0.347 {
		guess, err := model.Predict([]float64{i})
		assert.Nil(t, err, "Prediction error should be nil")
		assert.Len(t, guess, 1, "Guess should have length 1")

		if i/2+10 > 0 {
			assert.InDelta(t, 1.0, guess[0], 0.499, "Guess should be 1 for i=%v", i)
		} else {
			assert.InDelta(t, 0.0, guess[0], 0.499, "Guess should be 0 for i=%v", i)
		}
		iter++
	}
	fmt.Printf("Iter: %v\n", iter)
}
开发者ID:JustAdam,项目名称:goml,代码行数:53,代码来源:logistic_test.go


注:本文中的github.com/stretchr/testify/assert.InDelta函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。