本文整理汇总了Golang中github.com/stretchr/testify/assert.InDelta函数的典型用法代码示例。如果您正苦于以下问题:Golang InDelta函数的具体用法?Golang InDelta怎么用?Golang InDelta使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InDelta函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestDistance
func TestDistance(t *testing.T) {
assert.InDelta(t, float64(distance(waterloo, kingsCross)), 3080.074, 0.001)
d := math.Sqrt(float64(approximateSquareDistance(waterloo, kingsCross)))
assert.InDelta(t, d, 3074.987, 0.001)
d = math.Sqrt(float64(approximateSquareDistance(leicester, coventGarden)))
assert.InDelta(t, d, 305.662, 0.001)
d = math.Sqrt(float64(approximateSquareDistance(oxford, embankment)))
assert.InDelta(t, d, 1593.763, 0.001)
}
开发者ID:skateinmars,项目名称:go-geoindex,代码行数:12,代码来源:point_test.go
示例17: TestCentroidsAndTraces
func TestCentroidsAndTraces(t *testing.T) {
centroids, traces, f, reverse := CentroidsAndTraces(paramset, traceparams, 2)
assert.Equal(t, 2, len(centroids))
assert.Equal(t, 4, len(traces))
var tr4 *Trace
for _, clusterable := range traces {
tr4 = clusterable.(*Trace)
if tr4.ID == "tr4" {
break
}
}
assert.Equal(t, 0, tr4.Params[1], "Missing param should map to 0.")
assert.Equal(t, 3, tr4.Params[0], "The value gpu should sort to last of the three params.")
assert.Equal(t, traceparams["tr4"], reverse(tr4))
kmeansCentroid := f([]kmeans.Clusterable{tr4, tr4})
centroid := kmeansCentroid.(*Centroid)
assert.Equal(t, 0.0, centroid.Distance(tr4))
var tr1 *Trace
for _, clusterable := range traces {
tr1 = clusterable.(*Trace)
if tr1.ID == "tr1" {
break
}
}
assert.Equal(t, 2.0, centroid.Distance(tr1))
// Now run the k-means algorithm, which is deterministic for a fixed set of
// starting centroids, so pick our centroids explicitly so we always get the
// same answer.
obs := make([]kmeans.Clusterable, len(traces))
for i, tr := range traces {
obs[i] = tr
}
cent := []kmeans.Centroid{
f([]kmeans.Clusterable{tr1}),
f([]kmeans.Clusterable{tr4}),
}
kmCentroids, kmClusters := kmeans.KMeans(obs, cent, 2, 10, f)
assert.Equal(t, 2, len(kmCentroids))
assert.Equal(t, 2, len(kmClusters))
assert.Equal(t, 3, len(kmClusters[0]))
assert.Equal(t, 1, len(kmClusters[1]))
assert.Equal(t, "tr4", kmClusters[1][0].(*Trace).ID, "tr4 should be the singe member of the second cluster.")
assert.InDelta(t, 2.7748, kmeans.TotalError(obs, kmCentroids), 0.01)
// Run k-means again but with just one centroid and show the total error gets
// larger.
kmCentroids, kmClusters = kmeans.KMeans(obs, cent[:1], 2, 10, f)
assert.Equal(t, 1, len(kmCentroids))
assert.Equal(t, 1, len(kmClusters))
assert.Equal(t, 4, len(kmClusters[0]))
assert.InDelta(t, 4.42496, kmeans.TotalError(obs, kmCentroids), 0.01)
}
开发者ID:saltmueller,项目名称:skia-buildbot,代码行数:53,代码来源:kmlabel_test.go
示例18: TestProcessPingOutput
// Test that ping command output is processed properly
func TestProcessPingOutput(t *testing.T) {
trans, rec, avg, err := processPingOutput(bsdPingOutput)
assert.NoError(t, err)
assert.Equal(t, 5, trans, "5 packets were transmitted")
assert.Equal(t, 5, rec, "5 packets were transmitted")
assert.InDelta(t, 20.224, avg, 0.001)
trans, rec, avg, err = processPingOutput(linuxPingOutput)
assert.NoError(t, err)
assert.Equal(t, 5, trans, "5 packets were transmitted")
assert.Equal(t, 5, rec, "5 packets were transmitted")
assert.InDelta(t, 43.628, avg, 0.001)
}
开发者ID:jeichorn,项目名称:telegraf,代码行数:14,代码来源:ping_test.go
示例19: TestQueueConsumerRunStopsGracefullyWhenCancelled
func TestQueueConsumerRunStopsGracefullyWhenCancelled(t *testing.T) {
// log to /dev/null because the deleter is chatty
log.SetOutput(ioutil.Discard)
defer func() {
log.SetOutput(os.Stderr)
}()
ctl := gomock.NewController(t)
defer ctl.Finish()
// delay so that the cancel occurs mid-receive
delay := func(x interface{}) {
time.Sleep(10 * time.Millisecond)
}
m := mock.NewMockSQSAPI(ctl)
m.EXPECT().ReceiveMessage(gomock.Any()).Do(delay).Return(&sqs.ReceiveMessageOutput{}, nil).AnyTimes()
m.EXPECT().DeleteMessageBatch(gomock.Any()).AnyTimes().Return(&sqs.DeleteMessageBatchOutput{}, nil)
m.EXPECT().ChangeMessageVisibilityBatch(gomock.Any()).AnyTimes()
s := &SQSService{Svc: m}
q := NewConsumer(s, noop)
q.delayAfterReceiveError = time.Millisecond
ngo := runtime.NumGoroutine()
// wait long enough to ensure ReceiveMessage is running
ctx, _ := context.WithTimeout(context.Background(), 5*time.Millisecond)
err := q.Run(ctx)
assert.Error(t, err)
time.Sleep(time.Millisecond) // time for goroutines to end
assert.InDelta(t, ngo, runtime.NumGoroutine(), 2, "Should not leak goroutines")
}
开发者ID:Wattpad,项目名称:sqsconsumer,代码行数:34,代码来源:queue_consumer_test.go
示例20: TestHighTrafficUDP
func TestHighTrafficUDP(t *testing.T) {
listener := UdpListener{
ServiceAddress: ":8126",
AllowedPendingMessages: 100000,
}
listener.parser, _ = parsers.NewInfluxParser()
acc := &testutil.Accumulator{}
// send multiple messages to socket
err := listener.Start(acc)
require.NoError(t, err)
time.Sleep(time.Millisecond * 25)
conn, err := net.Dial("udp", "127.0.0.1:8126")
require.NoError(t, err)
for i := 0; i < 20000; i++ {
// arbitrary, just to give the OS buffer some slack handling the
// packet storm.
time.Sleep(time.Microsecond)
fmt.Fprintf(conn, testMsgs)
}
time.Sleep(time.Millisecond)
listener.Stop()
// this is not an exact science, since UDP packets can easily get lost or
// dropped, but assume that the OS will be able to
// handle at least 90% of the sent UDP packets.
assert.InDelta(t, 100000, len(acc.Metrics), 10000)
}
开发者ID:jeichorn,项目名称:telegraf,代码行数:29,代码来源:udp_listener_test.go
注:本文中的github.com/stretchr/testify/assert.InDelta函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论