@@ -5,34 +5,36 @@ import (
55 "time"
66
77 "github.com/benbjohnson/clock"
8+ "github.com/evcc-io/evcc/api"
89 "github.com/jinzhu/now"
910 "github.com/stretchr/testify/suite"
1011)
1112
12- func TestTimeseries (t * testing.T ) {
13- suite .Run (t , new (timeseriesTestSuite ))
13+ func TestSolarRates (t * testing.T ) {
14+ suite .Run (t , new (solarTestSuite ))
1415}
1516
16- type timeseriesTestSuite struct {
17+ type solarTestSuite struct {
1718 suite.Suite
1819 clock * clock.Mock
19- rr timeseries
20+ rr api. Rates
2021}
2122
22- func (t * timeseriesTestSuite ) rate (start int , val float64 ) tsval {
23- return tsval {
24- Timestamp : t .clock .Now ().Add (time .Duration (start ) * time .Hour ),
25- Value : val ,
23+ func (t * solarTestSuite ) rate (start int , val float64 ) api.Rate {
24+ return api.Rate {
25+ Start : t .clock .Now ().Add (time .Duration (start ) * time .Hour ),
26+ End : t .clock .Now ().Add (time .Duration (start + 1 ) * time .Hour ),
27+ Value : val ,
2628 }
2729}
2830
29- func (t * timeseriesTestSuite ) SetupSuite () {
31+ func (t * solarTestSuite ) SetupSuite () {
3032 t .clock = clock .NewMock ()
3133 t .clock .Set (now .BeginningOfDay ())
32- t .rr = timeseries {t .rate (0 , 0 ), t .rate (1 , 1 ), t .rate (2 , 2 ), t .rate (3 , 3 ), t .rate (4 , 4 )}
34+ t .rr = api. Rates {t .rate (0 , 0 ), t .rate (1 , 1 ), t .rate (2 , 2 ), t .rate (3 , 3 ), t .rate (4 , 4 )}
3335}
3436
35- func (t * timeseriesTestSuite ) TestIndex () {
37+ func (t * solarTestSuite ) TestIndex () {
3638 for i , tc := range []struct {
3739 ts float64
3840 idx int
@@ -45,30 +47,13 @@ func (t *timeseriesTestSuite) TestIndex() {
4547 {99 , len (t .rr ), false },
4648 } {
4749 ts := t .clock .Now ().Add (time .Duration (float64 (time .Hour ) * tc .ts ))
48- res , ok := t .rr . search ( ts )
50+ res , ok := search ( t .rr , ts )
4951 t .Equal (tc .idx , res , "%d. idx %+v" , i + 1 , tc )
5052 t .Equal (tc .ok , ok , "%d. ok %+v" , i + 1 , tc )
5153 }
5254}
5355
54- func (t * timeseriesTestSuite ) TestValue () {
55- for i , tc := range []struct {
56- ts , val float64
57- }{
58- {- 1 , 0 },
59- {0 , 0 },
60- {0.5 , 0.5 },
61- {1 , 1 },
62- {4 , 4 },
63- {99 , 0 },
64- } {
65- ts := t .clock .Now ().Add (time .Duration (float64 (time .Hour ) * tc .ts ))
66- res := t .rr .value (ts )
67- t .Equal (tc .val , res , "%d. %+v" , i + 1 , tc )
68- }
69- }
70-
71- func (t * timeseriesTestSuite ) TestEnergy () {
56+ func (t * solarTestSuite ) TestEnergy () {
7257 for i , tc := range []struct {
7358 from , to float64
7459 expected float64
@@ -90,14 +75,14 @@ func (t *timeseriesTestSuite) TestEnergy() {
9075 from := t .clock .Now ().Add (time .Duration (float64 (time .Hour ) * tc .from ))
9176 to := t .clock .Now ().Add (time .Duration (float64 (time .Hour ) * tc .to ))
9277
93- res := t .rr . energy ( from , to )
78+ res := solarEnergy ( t .rr , from , to )
9479 t .Equal (tc .expected , res , "%d. %+v" , i + 1 , tc )
9580 }
9681}
9782
98- func (t * timeseriesTestSuite ) TestShort () {
83+ func (t * solarTestSuite ) TestShort () {
9984 t .clock .Set (now .BeginningOfDay ())
100- rr := timeseries {t .rate (0 , 0 ), t .rate (1 , 1 )}
85+ rr := api. Rates {t .rate (0 , 0 ), t .rate (1 , 1 )}
10186
10287 for i , tc := range []struct {
10388 from , to , energy , value float64
@@ -114,7 +99,6 @@ func (t *timeseriesTestSuite) TestShort() {
11499 from := t .clock .Now ().Add (time .Duration (float64 (time .Hour ) * tc .from ))
115100 to := t .clock .Now ().Add (time .Duration (float64 (time .Hour ) * tc .to ))
116101
117- t .Equal (tc .energy , rr .energy (from , to ), "%d. energy %+v" , i + 1 , tc )
118- t .Equal (tc .value , rr .value (to ), "%d. value %+v" , i + 1 , tc )
102+ t .Equal (tc .energy , solarEnergy (rr , from , to ), "%d. energy %+v" , i + 1 , tc )
119103 }
120104}
0 commit comments