valera/calories/calories_test.go

55 lines
701 B
Go
Raw Normal View History

2023-03-18 07:35:05 +00:00
package calories
2023-03-13 18:15:11 +00:00
import "testing"
func TestCalcCalories(t *testing.T) {
t.Parallel()
tests := []struct {
name string
text string
want int
wantErr bool
}{
{
"empty text",
"",
0,
false,
},
{
"1 text",
"1",
1,
false,
},
{
"2 5 text",
"20 50",
10,
false,
},
{
"чай text",
"чай",
39,
false,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
2023-03-18 07:36:41 +00:00
count, err := CalcCalories(tt.text)
2023-03-13 18:15:11 +00:00
if (err != nil) != tt.wantErr {
t.Errorf("error calc calories: %v", err)
return
}
if count != tt.want {
t.Errorf("error count: %v", err)
return
}
})
}
}