valera/internal/calories/calories_test.go

66 lines
844 B
Go
Raw Normal View History

2023-03-18 07:35:05 +00:00
package calories
2023-03-13 18:15:11 +00:00
2023-03-18 07:47:45 +00:00
import (
"fmt"
"testing"
)
2023-03-13 18:15:11 +00:00
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",
"чай",
2023-03-18 12:02:32 +00:00
130,
false,
},
{
"чай 250 text",
"чай 250",
162,
2023-03-13 18:15:11 +00:00
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 {
2023-03-18 12:02:32 +00:00
fmt.Println(count, tt.want)
2023-03-18 07:47:45 +00:00
fmt.Println(count, tt.want)
2023-03-13 18:15:11 +00:00
t.Errorf("error count: %v", err)
return
}
})
}
}