Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Drop CompareInfo function in favor of builtin ==
Browse files Browse the repository at this point in the history
Signed-off-by: Wagner Riffel <wgrriffel@gmail.com>
  • Loading branch information
wgrr committed Mar 30, 2020
1 parent 1f9c34e commit c06cfe2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 49 deletions.
15 changes: 2 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type LastValues struct {
Confirmed uint `json:"confirmed"`
Deaths uint `json:"deaths"`
Recovered uint `json:"recovered"`
UpdatedAt time.Time
// UpdatedAt time.Time XXX: move somewhere else
}

type response struct {
Expand Down Expand Up @@ -62,7 +62,6 @@ func GetDataCOVID19(ctx context.Context) (*LastValues, error) {
Confirmed: resp.Data.Confirmed,
Deaths: resp.Data.Deaths,
Recovered: resp.Data.Recovered,
UpdatedAt: time.Now(),
}
}()
select {
Expand All @@ -75,16 +74,6 @@ func GetDataCOVID19(ctx context.Context) (*LastValues, error) {
}
}

// CompareInfos ...
func CompareInfos(currentValues LastValues) bool {
if lastValues.Confirmed != currentValues.Confirmed ||
lastValues.Deaths != currentValues.Deaths ||
lastValues.Recovered != currentValues.Recovered {
return true
}
return false
}

func routine(duration time.Duration) {
const timeout = time.Second * 2
for ctx, cancel := context.WithTimeout(context.Background(), timeout); ; cancel() {
Expand All @@ -93,7 +82,7 @@ func routine(duration time.Duration) {
panic(err)
}

if CompareInfos(*currentValue) {
if lastValues == *currentValue {
err := beeep.Alert("COVID-19 Brazil", currentValue.String(), IMG)
if err != nil {
panic(err)
Expand Down
36 changes: 0 additions & 36 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,8 @@ package main

import (
"testing"
"time"
)

func TestCompareInfos(t *testing.T) {
lastValues := &LastValues{
Confirmed: 1,
Deaths: 0,
Recovered: 0,
UpdatedAt: time.Now(),
}
type args struct {
currentValues LastValues
}
tests := []struct {
name string
args args
want bool
}{
{
name: "Test Compare Infos returns true",
args: args{currentValues: *lastValues},
want: true,
},
{
name: "Test Compare Infos returns false",
args: args{currentValues: LastValues{}},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CompareInfos(tt.args.currentValues); got != tt.want {
t.Errorf("CompareInfos() = %v, want %v", got, tt.want)
}
})
}
}

func TestLastValues_String(t *testing.T) {
type fields struct {
Confirmed uint
Expand Down

0 comments on commit c06cfe2

Please sign in to comment.