Merge PR #1534: Check new rat decimal string length
This commit is contained in:
committed by
Christopher Goes
parent
cae6b40221
commit
f1194019cd
@@ -41,6 +41,10 @@ func NewRat(Numerator int64, Denominator ...int64) Rat {
|
||||
// precision is the number of values after the decimal point which should be read
|
||||
func NewRatFromDecimal(decimalStr string, prec int) (f Rat, err Error) {
|
||||
// first extract any negative symbol
|
||||
if len(decimalStr) == 0 {
|
||||
return f, ErrUnknownRequest("decimal string is empty")
|
||||
}
|
||||
|
||||
neg := false
|
||||
if string(decimalStr[0]) == "-" {
|
||||
neg = true
|
||||
|
||||
@@ -27,6 +27,7 @@ func TestNewFromDecimal(t *testing.T) {
|
||||
expErr bool
|
||||
exp Rat
|
||||
}{
|
||||
{"", true, Rat{}},
|
||||
{"0", false, NewRat(0)},
|
||||
{"1", false, NewRat(1)},
|
||||
{"1.1", false, NewRat(11, 10)},
|
||||
|
||||
Reference in New Issue
Block a user