Skip to content

Commit

Permalink
feat: implement unit tests for parse.Quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
DaruZero committed May 22, 2023
1 parent 619e917 commit 7753921
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions parse/quantity_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package parse

import "testing"

func TestParseQuantity(t *testing.T) {
type args struct {
str string
}
tests := []struct {
name string
args args
want int
wantErr bool
}{
{"empty", args{""}, 0, true},
{"zero", args{"0"}, 0, false},
{"zeroes", args{"000"}, 0, false},
{"one", args{"1"}, 1, false},
{"negative one", args{"-1"}, -1, false},
{"decimal", args{"1.1"}, 0, true},
{"decimal suffix milli", args{"1.1m"}, 0, true},
{"decimal suffix million", args{"1.1M"}, 1100000, false},
{"decimal suffix million zero", args{"0.1M"}, 100000, false},
{"binary", args{"10Mi"}, 10485760, false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Quantity(tt.args.str)
if (err != nil) != tt.wantErr {
t.Errorf("Quantity() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("%s: Quantity() = %v, want %v", tt.name, got, tt.want)
}
})
}
}

0 comments on commit 7753921

Please sign in to comment.