Merge PR #1534: Check new rat decimal string length

This commit is contained in:
Yukai Tu
2018-07-04 05:29:05 +02:00
committed by Christopher Goes
parent cae6b40221
commit f1194019cd
3 changed files with 34 additions and 0 deletions
+4
View File
@@ -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
+1
View File
@@ -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)},