Refactor target charging apis (#5649)
This commit is contained in:
parent
8d805306ff
commit
dcaadb783f
53 changed files with 799 additions and 642 deletions
17
api/rates.go
17
api/rates.go
|
|
@ -15,20 +15,3 @@ func (r Rates) Current(now time.Time) (Rate, error) {
|
|||
|
||||
return Rate{}, errors.New("no matching rate")
|
||||
}
|
||||
|
||||
// implement sort.Interface
|
||||
func (r Rates) Len() int {
|
||||
return len(r)
|
||||
}
|
||||
|
||||
func (r Rates) Less(i, j int) bool {
|
||||
if r[i].Price == r[j].Price {
|
||||
return r[i].Start.After(r[j].Start)
|
||||
}
|
||||
|
||||
return r[i].Price < r[j].Price
|
||||
}
|
||||
|
||||
func (r Rates) Swap(i, j int) {
|
||||
r[i], r[j] = r[j], r[i]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/benbjohnson/clock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRatesSortLateSlotsFirst(t *testing.T) {
|
||||
clock := clock.NewMock()
|
||||
|
||||
r := Rates{
|
||||
{
|
||||
Price: 1,
|
||||
Start: clock.Now(),
|
||||
},
|
||||
{
|
||||
Price: 1,
|
||||
Start: clock.Now().Add(time.Hour),
|
||||
},
|
||||
}
|
||||
|
||||
sort.Sort(r)
|
||||
assert.Equal(t, clock.Now().Add(time.Hour), r[0].Start)
|
||||
assert.Equal(t, clock.Now(), r[1].Start)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue