From 1abb8f7e73f7ad16aeb2e238eb66a5042454fc95 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Mon, 14 Nov 2016 07:56:52 -0600 Subject: [PATCH] Add test case for "70000000000000000" and fix --- go/hexadecimal/hexadecimal.go | 2 +- go/hexadecimal/hexadecimal_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go/hexadecimal/hexadecimal.go b/go/hexadecimal/hexadecimal.go index 7330d76..30fb21e 100644 --- a/go/hexadecimal/hexadecimal.go +++ b/go/hexadecimal/hexadecimal.go @@ -45,7 +45,7 @@ func convertNumStringBase(in string, base int64) (int64, error) { } n += a - if n < 0 { + if n <= 0 && in[0] != '0' { return 0, errors.New("range") } } diff --git a/go/hexadecimal/hexadecimal_test.go b/go/hexadecimal/hexadecimal_test.go index f097057..241aacd 100644 --- a/go/hexadecimal/hexadecimal_test.go +++ b/go/hexadecimal/hexadecimal_test.go @@ -30,6 +30,7 @@ var testCases = []struct { {"2cg134", 0, "syntax"}, {"8000000000000000", 0, "range"}, {"9223372036854775809", 0, "range"}, + {"70000000000000000", 0, "range"}, } func TestParseHex(t *testing.T) {