mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: adapt tests
This commit is contained in:
@ -148,8 +148,8 @@ func (s *Summary) FillMissing() {
|
||||
// inplace!
|
||||
func (s *Summary) FillBy(fromType uint8, toType uint8) {
|
||||
typeItems := s.MappedItems()
|
||||
totalWanted := s.TotalTimeBy(fromType) / time.Second
|
||||
totalActual := s.TotalTimeBy(toType) / time.Second
|
||||
totalWanted := s.TotalTimeBy(fromType)
|
||||
totalActual := s.TotalTimeBy(toType)
|
||||
|
||||
key := UnknownSummaryKey
|
||||
if toType == SummaryLabel {
|
||||
@ -164,12 +164,12 @@ func (s *Summary) FillBy(fromType uint8, toType uint8) {
|
||||
}
|
||||
}
|
||||
if existingEntryIdx >= 0 {
|
||||
(*typeItems[toType])[existingEntryIdx].Total = totalWanted - totalActual
|
||||
(*typeItems[toType])[existingEntryIdx].Total = (totalWanted - totalActual) / time.Second // workaround
|
||||
} else {
|
||||
*typeItems[toType] = append(*typeItems[toType], &SummaryItem{
|
||||
Type: toType,
|
||||
Key: key,
|
||||
Total: totalWanted - totalActual,
|
||||
Total: (totalWanted - totalActual) / time.Second, // workaround
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -189,15 +189,6 @@ func (s *Summary) TotalTime() time.Duration {
|
||||
return timeSum * time.Second
|
||||
}
|
||||
|
||||
func (s *Summary) findFirstPresentType() (uint8, error) {
|
||||
for _, t := range s.Types() {
|
||||
if s.TotalTimeBy(t) > 0 {
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
return 127, errors.New("no type present")
|
||||
}
|
||||
|
||||
func (s *Summary) TotalTimeBy(entityType uint8) (timeSum time.Duration) {
|
||||
mappedItems := s.MappedItems()
|
||||
if items := mappedItems[entityType]; len(*items) > 0 {
|
||||
@ -280,6 +271,15 @@ func (s *Summary) WithResolvedAliases(resolve AliasResolver) *Summary {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Summary) findFirstPresentType() (uint8, error) {
|
||||
for _, t := range s.Types() {
|
||||
if s.TotalTimeBy(t) != 0 {
|
||||
return t, nil
|
||||
}
|
||||
}
|
||||
return 127, errors.New("no type present")
|
||||
}
|
||||
|
||||
func (s *SummaryItem) TotalFixed() time.Duration {
|
||||
// this is a workaround, since currently, the total time of a summary item is mistakenly represented in seconds
|
||||
// TODO: fix some day, while migrating persisted summary items
|
||||
|
@ -31,7 +31,7 @@ func TestSummary_FillUnknown(t *testing.T) {
|
||||
for _, l := range itemLists {
|
||||
assert.Len(t, l, 1)
|
||||
assert.Equal(t, UnknownSummaryKey, l[0].Key)
|
||||
assert.Equal(t, testDuration, l[0].Total)
|
||||
assert.Equal(t, testDuration, l[0].TotalFixed())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user