package display import ( "fmt" "testing" ) func TestFormatPrice(t *testing.T) { cases := []struct { in float64 want string }{ {0, "0.00"}, {1898.76, "1898.76"}, {1, "1.00"}, {0.00000059, "0.00000059"}, {-0.00000059, "-0.00000059"}, {0.5, "0.5"}, } for _, tc := range cases { if got := FormatPrice(tc.in); got != tc.want { t.Errorf("FormatPrice(%v)=%q want %q", tc.in, got, tc.want) } } } func TestDecimalPrintfKeepsTinyPrice(t *testing.T) { d := Decimal(0.00000059) if got := fmt.Sprintf("%.2f", d); got != "0.00000059" { t.Fatalf("%%.2f=%q", got) } if got := fmt.Sprintf("%v", d); got != "0.00000059" { t.Fatalf("%%v=%q", got) } if got := fmt.Sprintf("%.2f", Decimal(1898.76)); got != "1898.76" { t.Fatalf("eth %%.2f=%q", got) } if got := fmt.Sprintf("%.2f", Decimal(1000000000)); got != "1000000000.00" { t.Fatalf("qty %%.2f=%q", got) } } func TestWrapMapDoesNotMutate(t *testing.T) { in := map[string]interface{}{"price": 0.00000059} out := WrapMap(in) if _, ok := in["price"].(float64); !ok { t.Fatalf("input mutated: %T", in["price"]) } if _, ok := out["price"].(Decimal); !ok { t.Fatalf("wrapped type=%T", out["price"]) } }