mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
fix/scale: fix typo and add some more tests
This commit is contained in:
parent
f92bcda51d
commit
d51a802315
|
@ -151,7 +151,7 @@ func (s *LinearScale) Call(x float64) (y float64) {
|
|||
if x <= s.Domain[0] {
|
||||
return s.Range[0]
|
||||
} else if x >= s.Domain[1] {
|
||||
return s.Range[0]
|
||||
return s.Range[1]
|
||||
}
|
||||
|
||||
y = s.Range[0] + (x-s.Domain[0])*s.a
|
||||
|
|
|
@ -75,6 +75,7 @@ func TestLinearScale(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, "f(x) = 3.000000 + (x - 1000.000000) * 0.007000", scale.String())
|
||||
assert.InDelta(t, 3, scale.Call(1000), delta)
|
||||
assert.InDelta(t, 6.5, scale.Call(1500), delta)
|
||||
assert.InDelta(t, 10, scale.Call(2000), delta)
|
||||
for x := 1000; x <= 2000; x += 100 {
|
||||
y := scale.Call(float64(x))
|
||||
|
@ -92,6 +93,7 @@ func TestLinearScale2(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, "f(x) = 0.100000 + (x - 1.000000) * 0.150000", scale.String())
|
||||
assert.InDelta(t, 0.1, scale.Call(1), delta)
|
||||
assert.InDelta(t, 0.25, scale.Call(2), delta)
|
||||
assert.InDelta(t, 0.4, scale.Call(3), delta)
|
||||
}
|
||||
|
||||
|
@ -105,6 +107,7 @@ func TestLinearScaleNegative(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, "f(x) = 0.100000 + (x - -1.000000) * 0.075000", scale.String())
|
||||
assert.InDelta(t, 0.1, scale.Call(-1), delta)
|
||||
assert.InDelta(t, 0.25, scale.Call(1), delta)
|
||||
assert.InDelta(t, 0.4, scale.Call(3), delta)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user