Refactor target charging apis (#5649)

This commit is contained in:
andig 2023-01-19 19:01:22 +01:00 • committed by GitHub
parent 8d805306ff
commit dcaadb783f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 799 additions and 642 deletions

View file

@ -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]
}

View file

@ -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)
}