-
-
Notifications
You must be signed in to change notification settings - Fork 759
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only ever start first slot late if not last slot
- Loading branch information
Showing
5 changed files
with
101 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,49 @@ | ||
package planner | ||
|
||
import ( | ||
"math/rand" | ||
"testing" | ||
"time" | ||
|
||
"github.com/benbjohnson/clock" | ||
"github.com/evcc-io/evcc/api" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSlotHasPreDecessor(t *testing.T) { | ||
func TestSlotHasSuccessor(t *testing.T) { | ||
plan := rates([]float64{20, 60, 10, 80, 40, 90}, time.Now(), time.Hour) | ||
for i := 1; i < len(plan); i++ { | ||
require.True(t, SlotHasPredecessor(plan[i], plan)) | ||
|
||
last := plan[len(plan)-1] | ||
rand.Shuffle(len(plan)-1, func(i, j int) { | ||
plan[i], plan[j] = plan[j], plan[i] | ||
}) | ||
|
||
for i := 0; i < len(plan); i++ { | ||
if plan[i] != last { | ||
require.True(t, SlotHasSuccessor(plan[i], plan)) | ||
} | ||
} | ||
require.False(t, SlotHasPredecessor(plan[0], plan)) | ||
|
||
require.False(t, SlotHasSuccessor(last, plan)) | ||
} | ||
|
||
func TestSlotHasSuccessor(t *testing.T) { | ||
plan := rates([]float64{20, 60, 10, 80, 40, 90}, time.Now(), time.Hour) | ||
for i := 0; i < len(plan)-1; i++ { | ||
require.True(t, SlotHasSuccessor(plan[i], plan)) | ||
func TestIsFirst(t *testing.T) { | ||
clock := clock.NewMock() | ||
plan := rates([]float64{20, 60, 10, 80, 40, 90}, clock.Now(), time.Hour) | ||
|
||
first := plan[0] | ||
rand.Shuffle(len(plan), func(i, j int) { | ||
plan[i], plan[j] = plan[j], plan[i] | ||
}) | ||
|
||
for i := 1; i < len(plan); i++ { | ||
if plan[i] != first { | ||
require.False(t, IsFirst(plan[i], plan)) | ||
} | ||
} | ||
require.False(t, SlotHasSuccessor(plan[len(plan)-1], plan)) | ||
|
||
require.True(t, IsFirst(first, plan)) | ||
|
||
// ensure single slot is always first | ||
require.True(t, IsFirst(first, []api.Rate{first})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters