本文整理汇总了Golang中github.com/stretchr/testify/assert.InEpsilon函数的典型用法代码示例。如果您正苦于以下问题:Golang InEpsilon函数的具体用法?Golang InEpsilon怎么用?Golang InEpsilon使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InEpsilon函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestWaldTest
func TestWaldTest(t *testing.T) {
tests := []struct {
wald Wald
sample Sample
result Result
}{
{
wald: Wald{Size: 0.05, NullValue: 0},
sample: sample{mle: 1, variance: 1},
result: Result{
Statistic: 1.0,
Power: 1 - stdNormal.Cdf(-1+1.95996) + stdNormal.Cdf(-1-1.95996),
ConfidenceInterval: []float64{-0.95996, 2.95996},
ConfidenceLevel: .95,
PValue: 2 * stdNormal.Cdf(-1.0),
RejectNull: false,
Size: 0.05,
NullValue: 0,
},
},
}
for _, tt := range tests {
actual := tt.wald.Test(tt.sample)
assert.Equal(t, tt.result.Statistic, actual.Statistic)
assert.Equal(t, tt.result.Power, actual.Power)
// Confidence interval
assert.InEpsilon(t, tt.result.ConfidenceInterval[0], actual.ConfidenceInterval[0], 0.0001)
assert.InEpsilon(t, tt.result.ConfidenceInterval[1], actual.ConfidenceInterval[1], 0.0001)
assert.Equal(t, tt.result.PValue, actual.PValue)
assert.Equal(t, tt.result.RejectNull, actual.RejectNull)
}
}
示例2: TestStddevBesselWeighted
func TestStddevBesselWeighted(t *testing.T) {
result, err := mino.FromPoints(weightedFib).Transform(transform.Stddev{Bessel: true})
r := result.(transform.StddevResults)
assert.Nil(t, err)
assert.InEpsilon(t, 6.84670, r.Deviation, epsilon)
assert.InEpsilon(t, 8.48138, r.Average, epsilon)
}
示例3: TestStddevNormalOne
func TestStddevNormalOne(t *testing.T) {
result, err := mino.FromList(one).Transform(transform.Stddev{})
r := result.(transform.StddevResults)
assert.Equal(t, transform.InsufficientDataError, err)
assert.InEpsilon(t, 0, r.Deviation, epsilon)
assert.InEpsilon(t, 1, r.Average, epsilon)
}
示例4: TestStddevBessel
func TestStddevBessel(t *testing.T) {
result, err := mino.FromList(fibonacci).Transform(transform.Stddev{Bessel: true})
assert.Nil(t, err)
r := result.(transform.StddevResults)
assert.InEpsilon(t, 7.0660, r.Deviation, epsilon)
assert.InEpsilon(t, 6.7500, r.Average, epsilon)
}
示例5: Test_DeterministicTrigger_Unmarshal
func Test_DeterministicTrigger_Unmarshal(t *testing.T) {
var trigger triggers.DeterministicTrigger
var err error
// unmarshal with type and parameter
err = json.Unmarshal([]byte(`{"type":"deterministic","parameter":0.123}`), &trigger)
assert.Nil(t, err)
assert.InEpsilon(t, trigger.GetParameter(), 0.123, 0.001)
// unmarshal with type, parameter and comment
err = json.Unmarshal([]byte(`{"type":"deterministic","parameter":0.456,"comment":"ok"}`), &trigger)
assert.Nil(t, err)
assert.InEpsilon(t, trigger.GetParameter(), 0.456, 0.001)
assert.Equal(t, trigger.GetComment(), "ok")
}
示例6: TestReservation
func TestReservation(t *testing.T) {
pod := buildPod("p1", 100, 200000)
pod2 := &kube_api.Pod{
Spec: kube_api.PodSpec{
Containers: []kube_api.Container{
{
Resources: kube_api.ResourceRequirements{
Requests: kube_api.ResourceList{},
},
},
},
},
}
nodeInfo := schedulercache.NewNodeInfo(pod, pod, pod2)
node := &kube_api.Node{
Status: kube_api.NodeStatus{
Capacity: kube_api.ResourceList{
kube_api.ResourceCPU: *resource.NewMilliQuantity(2000, resource.DecimalSI),
},
},
}
reservation, err := calculateReservation(node, nodeInfo, kube_api.ResourceCPU)
assert.NoError(t, err)
assert.InEpsilon(t, 1.0/10, reservation, 0.01)
_, err = calculateReservation(node, nodeInfo, kube_api.ResourceMemory)
assert.Error(t, err)
}
示例7: TestSum
func TestSum(t *testing.T) {
s := Sum(DiceMust("2"), DiceMust("d5"))
min, max := s.Bound()
assert.Equal(t, 3, min)
assert.Equal(t, 7, max)
assert.InEpsilon(t, 5, convergentAvg(s), near)
}
示例8: TestFloat32
func TestFloat32(t *testing.T) {
p := parserMixin{}
v := p.Float32()
err := p.value.Set("123.45")
assert.NoError(t, err)
assert.InEpsilon(t, 123.45, *v, 0.001)
}
示例9: TestLearnOnSegments
func TestLearnOnSegments(t *testing.T) {
tmp := NewTemporalMemoryParams()
tm := NewTemporalMemory(tmp)
connections := tm.Connections
connections.CreateSegment(0)
connections.CreateSynapse(0, 23, 0.6)
connections.CreateSynapse(0, 37, 0.4)
connections.CreateSynapse(0, 477, 0.9)
connections.CreateSegment(1)
connections.CreateSynapse(1, 733, 0.7)
connections.CreateSegment(8)
connections.CreateSynapse(2, 486, 0.9)
connections.CreateSegment(100)
prevActiveSegments := []int{0, 2}
learningSegments := []int{1, 3}
prevActiveSynapsesForSegment := map[int][]int{
0: []int{0, 1},
1: []int{3},
}
winnerCells := []int{0}
prevWinnerCells := []int{10, 11, 12, 13, 14}
tm.learnOnSegments(prevActiveSegments,
learningSegments,
prevActiveSynapsesForSegment,
winnerCells,
prevWinnerCells,
connections)
//Check segment 0
assert.Equal(t, 0.7, connections.DataForSynapse(0).Permanence)
assert.Equal(t, 0.5, connections.DataForSynapse(1).Permanence)
assert.Equal(t, 0.8, connections.DataForSynapse(2).Permanence)
//Check segment 1
assert.InEpsilon(t, 0.8, connections.DataForSynapse(3).Permanence, 0.1)
assert.Equal(t, 2, len(connections.synapsesForSegment[1]))
//Check segment 2
assert.Equal(t, 0.9, connections.DataForSynapse(4).Permanence)
assert.Equal(t, 1, len(connections.synapsesForSegment[2]))
// Check segment 3
assert.Equal(t, 1, len(connections.synapsesForSegment[3]))
}
示例10: testCollapseTimeSamples
func testCollapseTimeSamples(t *testing.T) {
now := time.Now()
metrics := heapster.MetricResult{
Metrics: []heapster.MetricPoint{
{Timestamp: now, Value: 50, FloatValue: nil},
{Timestamp: now.Add(-15 * time.Second), Value: 100, FloatValue: nil},
{Timestamp: now.Add(-60 * time.Second), Value: 100000, FloatValue: nil}},
LatestTimestamp: now,
}
val, timestamp, hadMetrics := collapseTimeSamples(metrics, time.Minute)
assert.True(t, hadMetrics, "should report that it received a populated list of metrics")
assert.InEpsilon(t, float64(75), val, 0.1, "collapsed sample value should be as expected")
assert.True(t, timestamp.Equal(now), "timestamp should be the current time (the newest)")
}
示例11: TestExponentialBackoff
func TestExponentialBackoff(t *testing.T) {
clock := &MockClock{}
rp := NewDefaultRetryPolicy(clock)
rp.MaxAttempts = 9999999
rp.MinDelay = time.Second
rp.MaxDelay = time.Minute
rp.TimeLimit = time.Hour
rp.RandomizeDelays = false
op := rp.StartOperation()
assert.True(t, op.ShouldRetry("Attempt 1"))
assert.Equal(t, time.Duration(0), clock.LastSleepDuration) // first retry is immediate
assert.True(t, op.ShouldRetry("Attempt 2"))
assert.Equal(t, time.Second, clock.LastSleepDuration) // MinDelay
assert.True(t, op.ShouldRetry("Attempt 3"))
assert.InEpsilon(t, 1.62, clock.LastSleepDuration.Seconds(), 0.01)
assert.True(t, op.ShouldRetry("Attempt 4"))
assert.InEpsilon(t, 2.62, clock.LastSleepDuration.Seconds(), 0.01)
assert.True(t, op.ShouldRetry("Attempt 5"))
assert.InEpsilon(t, 4.24, clock.LastSleepDuration.Seconds(), 0.01)
for i := 0; i < 7; i++ {
assert.True(t, op.ShouldRetry("Attempt X"))
}
assert.Equal(t, time.Minute, clock.LastSleepDuration) // MaxDelay
}
示例12: TestDiceBounds
func TestDiceBounds(t *testing.T) {
for _, tc := range []struct {
string
min, max int
avg float64
}{
{"4d8", 4, 8 * 4, (4 + 8*4) / 2},
{"d4", 1, 4, float64(1+4) / 2.0},
} {
r := DiceMust(tc.string)
min, max := r.Bound()
assert.Equal(t, tc.min, min)
assert.Equal(t, tc.max, max)
assert.InEpsilon(t, tc.avg, convergentAvg(r), near)
}
}
示例13: TestUtilization
func TestUtilization(t *testing.T) {
pod := BuildTestPod("p1", 100, 200000)
pod2 := BuildTestPod("p2", -1, -1)
nodeInfo := schedulercache.NewNodeInfo(pod, pod, pod2)
node := BuildTestNode("node1", 2000, 2000000)
utilization, err := CalculateUtilization(node, nodeInfo)
assert.NoError(t, err)
assert.InEpsilon(t, 2.0/10, utilization, 0.01)
node2 := BuildTestNode("node1", 2000, -1)
_, err = CalculateUtilization(node2, nodeInfo)
assert.Error(t, err)
}
示例14: TestAggregateSumSingle
func TestAggregateSumSingle(t *testing.T) {
now := time.Now()
result := heapster.MetricResultList{
Items: []heapster.MetricResult{
{
Metrics: []heapster.MetricPoint{
{now, 50, nil},
{now.Add(-65 * time.Second), 100000, nil}},
LatestTimestamp: now,
},
},
}
sum, cnt, _ := calculateSumFromTimeSample(result, time.Minute)
assert.Equal(t, int64(50), sum.intValue)
assert.InEpsilon(t, 50.0, sum.floatValue, 0.1)
assert.Equal(t, 1, cnt)
}
示例15: TestShuffler
func TestShuffler(t *testing.T) {
rand.Seed(time.Now().Unix())
fixture := Whisper{}
in := make(chan *points.Points)
out1 := make(chan *points.Points)
out2 := make(chan *points.Points)
out3 := make(chan *points.Points)
out4 := make(chan *points.Points)
out := [](chan *points.Points){out1, out2, out3, out4}
go fixture.shuffler(in, out, nil)
buckets := [4]int{0, 0, 0, 0}
runlength := 10000
var wg sync.WaitGroup
wg.Add(4)
for index, _ := range out {
outChan := out[index]
i := index
go func() {
for {
_, ok := <-outChan
if !ok {
break
}
buckets[i]++
}
wg.Done()
}()
}
randomPoints(runlength, in)
close(in)
wg.Wait()
total := 0
for b := range buckets {
assert.InEpsilon(t, float64(runlength)/4, buckets[b], (float64(runlength)/4)*.005, fmt.Sprintf("shuffle distribution is greater than .5% across 4 buckets after %d inputs", runlength))
total += buckets[b]
}
assert.Equal(t, runlength, total, "total output of shuffle is not equal to input")
}