summaryrefslogtreecommitdiff
path: root/si_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'si_test.go')
-rw-r--r--si_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/si_test.go b/si_test.go
index bc5bac6..e15fc69 100644
--- a/si_test.go
+++ b/si_test.go
@@ -94,6 +94,29 @@ func TestSI(t *testing.T) {
}
}
+func TestSIWithDigits(t *testing.T) {
+ tests := []struct {
+ name string
+ num float64
+ digits int
+ formatted string
+ }{
+ {"e-12", 2.234e-12, 0, "2 pF"},
+ {"e-12", 2.234e-12, 1, "2.2 pF"},
+ {"e-12", 2.234e-12, 2, "2.23 pF"},
+ {"e-12", 2.234e-12, 3, "2.234 pF"},
+ {"e-12", 2.234e-12, 4, "2.234 pF"},
+ }
+
+ for _, test := range tests {
+ got := SIWithDigits(test.num, test.digits, "F")
+ if got != test.formatted {
+ t.Errorf("On %v (%v), got %v, wanted %v",
+ test.name, test.num, got, test.formatted)
+ }
+ }
+}
+
func BenchmarkParseSI(b *testing.B) {
for i := 0; i < b.N; i++ {
ParseSI("2.2346ZB")