trying to fix price
This commit is contained in:
parent
7feee7f8a3
commit
8194cea85e
10 changed files with 145 additions and 54 deletions
55
models/price_test.go
Normal file
55
models/price_test.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package models
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFormatPrice(t *testing.T) {
|
||||
var a Price
|
||||
var s string
|
||||
a = 12345678900
|
||||
s = a.String()
|
||||
if s != "123456789" {
|
||||
t.Fatal(a, s)
|
||||
}
|
||||
a = 123456789
|
||||
s = a.String()
|
||||
if s != "1234567.89" {
|
||||
t.Fatal(a, s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePrice(t *testing.T) {
|
||||
var p Price
|
||||
var s string
|
||||
var err error
|
||||
s = "199"
|
||||
p, err = ParsePrice(s)
|
||||
if err != nil || p != 19900 {
|
||||
t.Fatal(s, p)
|
||||
}
|
||||
s = "1.99"
|
||||
p, err = ParsePrice(s)
|
||||
if err != nil || p != 199 {
|
||||
t.Fatal(s, p)
|
||||
}
|
||||
s = "1123"
|
||||
p, err = ParsePrice(s)
|
||||
if err != nil || p != 112300 {
|
||||
t.Fatal(s, p)
|
||||
}
|
||||
s = "1123.123"
|
||||
_, err = ParsePrice(s)
|
||||
if err == nil {
|
||||
t.Fatal(s, "should error")
|
||||
}
|
||||
s = "1123.3"
|
||||
_, err = ParsePrice(s)
|
||||
if err == nil {
|
||||
t.Fatal(s, "should error")
|
||||
}
|
||||
|
||||
s = "1123,33"
|
||||
_, err = ParsePrice(s)
|
||||
if err == nil {
|
||||
t.Fatal(s, "should error")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue