66 lines
849 B
Go
66 lines
849 B
Go
package eat_bot_state
|
|
|
|
import (
|
|
"fmt"
|
|
"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",
|
|
"чай",
|
|
130,
|
|
false,
|
|
},
|
|
{
|
|
"чай 250 text",
|
|
"чай 250",
|
|
162,
|
|
false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
count, err := calcCalories(tt.text)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("error calc calories: %v", err)
|
|
return
|
|
}
|
|
if count != tt.want {
|
|
fmt.Println(count, tt.want)
|
|
fmt.Println(count, tt.want)
|
|
t.Errorf("error count: %v", err)
|
|
return
|
|
}
|
|
})
|
|
}
|
|
}
|