本文整理匯總了Golang中github.com/ready-steady/assert.EqualWithin函數的典型用法代碼示例。如果您正苦於以下問題:Golang EqualWithin函數的具體用法?Golang EqualWithin怎麽用?Golang EqualWithin使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了EqualWithin函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSimpleLinearNew
func TestSimpleLinearNew(t *testing.T) {
x := []float64{
3.181500e+02,
3.281500e+02,
3.381500e+02,
3.481500e+02,
3.581500e+02,
3.681500e+02,
3.781500e+02,
3.881500e+02,
3.981500e+02,
}
y := []float64{
5.459861e-01,
6.303621e-01,
7.325854e-01,
8.549895e-01,
1.000000e+00,
1.171091e+00,
1.373428e+00,
1.606733e+00,
1.873658e+00,
}
model := NewSimpleLinear(x, y)
assert.EqualWithin(model.α, -4.7845715178610932e+00, 1e-12, t)
assert.EqualWithin(model.β, +1.6395978333333290e-02, 1e-12, t)
}
示例2: TestListDelay
func TestListDelay(t *testing.T) {
platform, application, _ := system.Load(findFixture("002_040"))
profile := system.NewProfile(platform, application)
list := NewList(platform, application)
schedule := list.Compute(profile.Mobility)
delay := []float64{
0.0352, 0.0831, 0.0585, 0.0550, 0.0917, 0.0286, 0.0757, 0.0754,
0.0380, 0.0568, 0.0076, 0.0054, 0.0531, 0.0779, 0.0934, 0.0130,
0.0569, 0.0469, 0.0012, 0.0337, 0.0162, 0.0794, 0.0311, 0.0529,
0.0166, 0.0602, 0.0263, 0.0654, 0.0689, 0.0748, 0.0451, 0.0084,
0.0229, 0.0913, 0.0152, 0.0826, 0.0538, 0.0996, 0.0078, 0.0443,
}
start := []float64{
0.0000, 0.0582, 0.1533, 0.4349, 0.2238, 0.3855, 1.7419, 0.3365,
0.3365, 0.5019, 0.6554, 0.4251, 0.6820, 1.2139, 1.6966, 0.5727,
1.3128, 0.7837, 0.9856, 0.6067, 0.6554, 0.9998, 0.8456, 1.3128,
0.7481, 1.4890, 1.1766, 1.0992, 0.8917, 0.9856, 0.7837, 1.3847,
1.8648, 1.3847, 1.1766, 1.6373, 1.8010, 1.5810, 1.5622, 1.5810,
}
finish := make([]float64, len(start))
for i := range finish {
finish[i] = start[i] + (schedule.Finish[i] - schedule.Start[i]) + delay[i]
}
schedule = list.Delay(schedule, delay)
assert.EqualWithin(schedule.Start, start, 1e-15, t)
assert.EqualWithin(schedule.Finish, finish, 2e-15, t)
}
示例3: TestKolmogorovSmirnovGaussian
func TestKolmogorovSmirnovGaussian(t *testing.T) {
data1 := []float64{
+1.8368909586194213e-01, -4.7615301661907383e-01,
+8.6202161155692203e-01, -1.3616944708707543e+00,
+4.5502955644433435e-01, -8.4870937993365902e-01,
-3.3488693896404770e-01, +5.5278334594455014e-01,
+1.0390906535049560e+00, -1.1176386832652081e+00,
+1.2606587091208963e+00, +6.6014314104697769e-01,
-6.7865553542687335e-02, -1.9522119789875436e-01,
-2.1760635014319193e-01, -3.0310762135174091e-01,
+2.3045624425105282e-02, +5.1290355848774699e-02,
+8.2606279021159545e-01, +1.5269766867333727e+00,
}
data2 := []float64{
+4.6691443568470004e-01, -2.0971333838873671e-01,
+6.2519035708762571e-01, +1.8322726300143696e-01,
-1.0297675435666211e+00, +9.4922183113102254e-01,
+3.0706191914670344e-01, +1.3517494209945566e-01,
+5.1524633552484855e-01, +2.6140632405538267e-01,
-9.4148577095543373e-01, -1.6233767280382774e-01,
-1.4605463433152618e-01, -5.3201137680882071e-01,
+1.6821035946631788e+00, -8.7572934616001730e-01,
-4.8381505011012110e-01, -7.1200454902742250e-01,
-1.1742123314568162e+00, -1.9223951753927476e-01,
}
rejected, pvalue, statistic := KolmogorovSmirnov(data1, data2, 0.05)
assert.Equal(rejected, false, t)
assert.EqualWithin(pvalue, 7.7095294467658659e-01, 1e-15, t)
assert.EqualWithin(statistic, 2.0000000000000007e-01, 1e-15, t)
}
示例4: TestParabola
func TestParabola(t *testing.T) {
fixture := &fixtureParabola
algorithm, strategy := prepare(fixture)
surrogate := algorithm.Compute(fixture.target, strategy)
assert.Equal(surrogate.Nodes, fixture.surrogate.Nodes, t)
assert.EqualWithin(surrogate.Integral, fixture.surrogate.Integral, 1e-6, t)
assert.Equal(interpolation.Validate(surrogate.Indices, surrogate.Inputs,
fixture.grid), true, t)
values := algorithm.Evaluate(surrogate, fixture.points)
assert.EqualWithin(values, fixture.values, 1e-6, t)
}
示例5: TestListCompute
func TestListCompute(t *testing.T) {
platform, application, _ := system.Load(findFixture("002_040"))
profile := system.NewProfile(platform, application)
list := NewList(platform, application)
schedule := list.Compute(profile.Mobility)
mapping := []uint{
0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0,
1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0,
}
order := []uint{
0, 1, 2, 4, 7, 8, 5, 11, 3, 9, 15, 19, 20, 10, 12, 24, 30, 17, 22, 28, 29,
18, 21, 27, 34, 26, 13, 16, 23, 31, 33, 25, 38, 39, 37, 35, 14, 36, 6, 32,
}
start := []float64{
0.0000, 0.0230, 0.0350, 0.0910, 0.0470, 0.0790, 0.4220, 0.0680,
0.0680, 0.1030, 0.1530, 0.0900, 0.1720, 0.3150, 0.4040, 0.1170,
0.3360, 0.2040, 0.2590, 0.1380, 0.1530, 0.2720, 0.2190, 0.3360,
0.1850, 0.3640, 0.3040, 0.2920, 0.2340, 0.2590, 0.2040, 0.3510,
0.4250, 0.3510, 0.3040, 0.4000, 0.4150, 0.3880, 0.3770, 0.3880,
}
duration := []float64{
0.0230, 0.0120, 0.0120, 0.0120, 0.0210, 0.0110, 0.0180, 0.0230,
0.0110, 0.0140, 0.0190, 0.0150, 0.0130, 0.0210, 0.0110, 0.0210,
0.0150, 0.0150, 0.0130, 0.0150, 0.0210, 0.0200, 0.0150, 0.0100,
0.0190, 0.0130, 0.0110, 0.0120, 0.0250, 0.0150, 0.0180, 0.0190,
0.0140, 0.0130, 0.0260, 0.0220, 0.0100, 0.0160, 0.0110, 0.0120,
}
finish := make([]float64, len(start))
span := 0.0
for i := range start {
finish[i] = start[i] + duration[i]
if span < finish[i] {
span = finish[i]
}
}
assert.Equal(schedule.Cores, uint(2), t)
assert.Equal(schedule.Tasks, uint(40), t)
assert.EqualWithin(schedule.Span, span, 1e-15, t)
assert.Equal(schedule.Mapping, mapping, t)
assert.Equal(schedule.Order, order, t)
assert.EqualWithin(schedule.Start, start, 1e-15, t)
assert.EqualWithin(schedule.Finish, finish, 1e-15, t)
}
示例6: TestParseRealIndex
func TestParseRealIndex(t *testing.T) {
cases := []struct {
line string
min float64
max float64
result []float64
}{
{"", 0, 1, nil},
{"[]", 0, 1, []float64{}},
{"[0, 0.1, 0.9, 1]", 0, 1, []float64{0.0, 0.1, 0.9, 1.0}},
{"[0, 0.1, 1.1]", 0, 1, nil},
{"[0:1]", 0, 1, []float64{0, 1}},
{"[0.1:0.2:1]", 0, 1, []float64{0.1, 0.3, 0.5, 0.7, 0.9}},
{"[0:0.2:1]", 0, 1, []float64{0.0, 0.2, 0.4, 0.6, 0.8, 1.0}},
{"[0:0.5:1.5]", 0, 1, nil},
{"[0, 0.2, end]", 0, 1, []float64{0.0, 0.2, 1.0}},
{"[0:0.2:end]", 0, 1, []float64{0.0, 0.2, 0.4, 0.6, 0.8, 1.0}},
{"[0:end]", 0, 1, []float64{0, 1}},
}
for _, c := range cases {
result, err := ParseRealIndex(c.line, c.min, c.max)
if c.result != nil {
assert.Success(err, t)
}
assert.EqualWithin(result, c.result, 1e-15, t)
}
}
示例7: TestSolutionCompute
func TestSolutionCompute(t *testing.T) {
config, _ := config.New("fixtures/002_020.json")
system, _ := system.New(&config.System)
uncertainty, _ := uncertainty.NewEpistemic(system, &config.Uncertainty)
quantity, _ := quantity.New(system, uncertainty, &config.Quantity)
ni, no := quantity.Dimensions()
solution, _ := New(ni, no, &config.Solution)
surrogate := solution.Compute(quantity, quantity)
nn := surrogate.Surrogate.Nodes
assert.Equal(nn, uint(841), t)
grid := grid.NewClosed(ni)
nodes := grid.Compute(surrogate.Surrogate.Indices)
values := make([]float64, nn*no)
for i := uint(0); i < nn; i++ {
quantity.Compute(nodes[i*ni:(i+1)*ni], values[i*no:(i+1)*no])
}
assert.EqualWithin(values, solution.Evaluate(surrogate, nodes), 1e-15, t)
}
示例8: TestCompute
func TestCompute(t *testing.T) {
Q := []float64{318.15, 328.15, 338.15, 348.15, 358.15, 368.15, 378.15, 388.15, 398.15}
C := []float64{0.5460, 0.6304, 0.7326, 0.8550, 1.0000, 1.1711, 1.3734, 1.6067, 1.8737}
power := New(1.0, Q, C)
assert.EqualWithin(power.Compute(358.15), 1.088, 0.001, t)
}
示例9: TestHat
func TestHat(t *testing.T) {
fixture := &fixtureHat
algorithm, strategy := prepare(fixture)
surrogate := algorithm.Compute(fixture.target, strategy)
assert.Equal(surrogate, fixture.surrogate, t)
values := algorithm.Evaluate(surrogate, fixture.points)
assert.EqualWithin(values, fixture.values, 1e-15, t)
}
示例10: TestExpectation
func TestExpectation(t *testing.T) {
data := []float64{
+5.3766713954610001e-01, +1.8338850145950865e+00,
-2.2588468610036481e+00, +8.6217332036812055e-01,
+3.1876523985898081e-01, -1.3076882963052734e+00,
-4.3359202230568356e-01, +3.4262446653864992e-01,
+3.5783969397257605e+00, +2.7694370298848772e+00,
}
assert.EqualWithin(Expectation(data), 6.2428219709029698e-01, 1e-15, t)
}
示例11: TestVariance
func TestVariance(t *testing.T) {
data := []float64{
+5.3766713954610001e-01, +1.8338850145950865e+00,
-2.2588468610036481e+00, +8.6217332036812055e-01,
+3.1876523985898081e-01, -1.3076882963052734e+00,
-4.3359202230568356e-01, +3.4262446653864992e-01,
+3.5783969397257605e+00, +2.7694370298848772e+00,
}
assert.EqualWithin(Variance(data), 3.1324921339484746e+00, 1e-15, t)
}
示例12: TestQuadrature
func TestQuadrature(t *testing.T) {
const (
a = -6.0
b = +6.0
)
nodes := uint(math.Ceil((float64(3) + 1.0) / 2.0))
value := quadrature(a, b, nodes, f)
assert.EqualWithin(value, F(b)-F(a), 1e-12, t)
}
示例13: TestBaseForwardInvert
func TestBaseForwardInvert(t *testing.T) {
uncertainty := &base{
tasks: []uint{0, 1, 2},
lower: []float64{10.0, 20.0, 30.0},
upper: []float64{20.0, 30.0, 40.0},
nt: 3,
nu: 3,
nz: 2,
copula: &copula{
C: []float64{
1.0, 2.0, 3.0,
4.0, 5.0, 6.0,
},
D: []float64{
6.0, 5.0,
4.0, 3.0,
2.0, 1.0,
},
},
marginals: []distribution.Continuous{
distribution.NewUniform(0.0, 1.0),
distribution.NewUniform(0.0, 1.0),
distribution.NewUniform(0.0, 1.0),
},
}
forward := uncertainty.Forward([]float64{18.0, 21.0, 36.0})
assert.EqualWithin(forward, []float64{
6.664804998759882e-01,
7.313162037785672e-01,
}, 1e-14, t)
backward := uncertainty.Backward([]float64{0.45, 0.65})
assert.EqualWithin(backward, []float64{
1.921556679782504e+01,
2.953060310728164e+01,
3.973501094321997e+01,
}, 1e-14, t)
}
示例14: TestPartition
func TestPartition(t *testing.T) {
const (
n = 10
ε = 1e-14
)
power, schedule := prepare("002_040")
P, ΔT := power.Partition(schedule, ε)
assert.Equal(P, fixturePartition.P, t)
assert.EqualWithin(ΔT, fixturePartition.ΔT, 1e-15, t)
}
示例15: TestInvert
func TestInvert(t *testing.T) {
n := uint(3)
a := []float64{1.0, -1.0, 0.0, 0.0, 5.0, 3.0, 2.0, 0.0, -9.0}
expectedA := []float64{
+8.823529411764706e-01, +1.764705882352941e-01, +5.882352941176472e-02,
-1.176470588235294e-01, +1.764705882352941e-01, +5.882352941176472e-02,
+1.960784313725490e-01, +3.921568627450981e-02, -9.803921568627452e-02,
}
assert.Equal(Invert(a, n), nil, t)
assert.EqualWithin(a, expectedA, 1e-15, t)
}