53 lines
986 B
Go
53 lines
986 B
Go
package invoice
|
|
|
|
import "testing"
|
|
|
|
func TestParseQuantity(t *testing.T) {
|
|
cases := []struct {
|
|
input string
|
|
want Quantity
|
|
}{
|
|
{"1", 100},
|
|
{"0.5", 50},
|
|
{"2,25", 225},
|
|
{"10.00", 1000},
|
|
}
|
|
for _, tc := range cases {
|
|
got, err := ParseQuantity(tc.input)
|
|
if err != nil {
|
|
t.Fatalf("ParseQuantity(%q) unexpected error: %v", tc.input, err)
|
|
}
|
|
if got != tc.want {
|
|
t.Fatalf("ParseQuantity(%q)=%v want %v", tc.input, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFormatQuantity(t *testing.T) {
|
|
cases := []struct {
|
|
input Quantity
|
|
want string
|
|
}{
|
|
{100, "1"},
|
|
{50, "0.5"},
|
|
{225, "2.25"},
|
|
{1010, "10.1"},
|
|
}
|
|
for _, tc := range cases {
|
|
got := FormatQuantity(tc.input)
|
|
if got != tc.want {
|
|
t.Fatalf("FormatQuantity(%v)=%q want %q", tc.input, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLineAmountNegative(t *testing.T) {
|
|
item := Item{
|
|
UnitPrice: -29500,
|
|
Quantity: 100,
|
|
}
|
|
if got := LineAmount(item); got != -29500 {
|
|
t.Fatalf("LineAmount negative mismatch: %v", got)
|
|
}
|
|
}
|