valera/internal/states/eat_bot_state/calories_test.go

66 lines
849 B
Go
Raw Normal View History

2023-04-09 06:31:01 +00:00
package eat_bot_state
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-04-09 06:31:01 +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
}
})
}
}