From c1c3695829625a8b5528e979e0a6bb45d3f1c5a7 Mon Sep 17 00:00:00 2001 From: Steve Kroll Date: Wed, 1 May 2019 18:11:47 -0500 Subject: [PATCH 1/5] added currency count --- currency_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/currency_test.go b/currency_test.go index 2a2f510..178f8a7 100644 --- a/currency_test.go +++ b/currency_test.go @@ -5,6 +5,11 @@ import ( "testing" ) +func TestCurrencyCount(t *testing.T) { + num := len(CurrencyList) + t.Log("Currency Count: ", num) +} + var TestFormattedStringToUintData = []struct { Num string Alpha string From 410f30696fb40b9ce5055193bfac174007a74a35 Mon Sep 17 00:00:00 2001 From: Steve Kroll Date: Fri, 10 May 2019 12:12:48 -0500 Subject: [PATCH 2/5] updated package name --- currency.go | 2 +- currency_list.go | 2 +- currency_test.go | 2 +- error.go | 2 +- function.go | 2 +- function_test.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/currency.go b/currency.go index b8022fd..3774368 100644 --- a/currency.go +++ b/currency.go @@ -1,4 +1,4 @@ -package currency +package dough import ( "math" diff --git a/currency_list.go b/currency_list.go index 4d0367a..692016a 100644 --- a/currency_list.go +++ b/currency_list.go @@ -1,4 +1,4 @@ -package currency +package dough // Currency - struct containing currency variables type Currency struct { diff --git a/currency_test.go b/currency_test.go index 178f8a7..8187099 100644 --- a/currency_test.go +++ b/currency_test.go @@ -1,4 +1,4 @@ -package currency +package dough import ( "reflect" diff --git a/error.go b/error.go index a721aab..b5c995e 100644 --- a/error.go +++ b/error.go @@ -1,4 +1,4 @@ -package currency +package dough import "errors" diff --git a/function.go b/function.go index cae1f80..6d88cbe 100644 --- a/function.go +++ b/function.go @@ -1,4 +1,4 @@ -package currency +package dough import ( "fmt" diff --git a/function_test.go b/function_test.go index 9efd7c4..82bfbe8 100644 --- a/function_test.go +++ b/function_test.go @@ -1,4 +1,4 @@ -package currency +package dough import "testing" From 575481a3f7b9d9b91b270a4924228694faede488 Mon Sep 17 00:00:00 2001 From: bvoelker Date: Fri, 10 May 2019 12:14:55 -0500 Subject: [PATCH 3/5] string to int - simplified to just string to int and updated tests --- currency.go | 17 +++--------- currency_test.go | 69 +++++++++++++++--------------------------------- 2 files changed, 25 insertions(+), 61 deletions(-) diff --git a/currency.go b/currency.go index 3774368..488f871 100644 --- a/currency.go +++ b/currency.go @@ -7,15 +7,15 @@ import ( "strings" ) -// FormattedStringToUint : returns a uint from a string value -func FormattedStringToUint(num string, alpha string) (uint, error) { +// StringToInt : returns a uint from a string value +func StringToInt(num string, alpha string) (int, error) { ISO, err := GetISOFromAlpha(alpha) if err != nil { return 0, err } // Find all numbers and a decimal - reg := regexp.MustCompile("[0-9" + ISO.Decimal + "]+") + reg := regexp.MustCompile("[-0-9" + ISO.Decimal + "]+") strArray := reg.FindAllString(num, -1) str := strings.Join(strArray, "") @@ -29,16 +29,7 @@ func FormattedStringToUint(num string, alpha string) (uint, error) { } // Return a mulitple of the fraction to give us our uint - return uint(fl * math.Pow10(ISO.Fraction)), nil -} - -// PlainStringToInt returns a int64 from a purely numerical string -func PlainStringToInt(str string, alpha string) (int64, error) { - _, err := GetISOFromAlpha(alpha) - if err != nil { - return 0, err - } - return strconv.ParseInt(str, 10, 64) + return int(fl * math.Pow10(ISO.Fraction)), nil } // DisplayFull : returns a string with full currency formatting... "num" being the amount, "alpha" being the ISO three digit alphabetic code. diff --git a/currency_test.go b/currency_test.go index 8187099..994fbd7 100644 --- a/currency_test.go +++ b/currency_test.go @@ -19,59 +19,32 @@ var TestFormattedStringToUintData = []struct { {" ", "USD", ErrorUnableToFormatCurrencyFromString.Error()}, {"abcd", "USD", ErrorUnableToFormatCurrencyFromString.Error()}, {"$5", "USA", ErrorInvalidISO.Error()}, - {"$5", "USD", uint(500)}, - {"$500", "USD", uint(50000)}, - {"$05", "USD", uint(500)}, - {"$0.05", "USD", uint(5)}, - {"$5.0", "USD", uint(500)}, - {"$5.52", "USD", uint(552)}, - {"$0.00", "USD", uint(0)}, - {"$0.01", "USD", uint(1)}, - {"$0.10", "USD", uint(10)}, - {"$1.00", "USD", uint(100)}, - {"$10.00", "USD", uint(1000)}, - {"$100.00", "USD", uint(10000)}, - {"$1,000.00", "USD", uint(100000)}, - {"$10,000.00", "USD", uint(1000000)}, - {"$100,000.00", "USD", uint(10000000)}, - {"$1,000,000.00", "USD", uint(100000000)}, + {"$5", "USD", 500}, + {"$500", "USD", 50000}, + {"-500", "USD", -50000}, + {"$05", "USD", 500}, + {"$0.05", "USD", 5}, + {"$5.0", "USD", 500}, + {"$5.52", "USD", 552}, + {"$0.00", "USD", 0}, + {"$0.01", "USD", 1}, + {"$0.10", "USD", 10}, + {"$1.00", "USD", 100}, + {"$10.00", "USD", 1000}, + {"$100.00", "USD", 10000}, + {"$1,000.00", "USD", 100000}, + {"$10,000.00", "USD", 1000000}, + {"$100,000.00", "USD", 10000000}, + {"$1,000,000.00", "USD", 100000000}, // Non USD - {"$100.00,00", "ARS", uint(1000000)}, - {"$10,000,000", "JPY", uint(10000000)}, -} - -func TestFormattedStringToUint(t *testing.T) { - for _, v := range TestFormattedStringToUintData { - result, err := FormattedStringToUint(v.Num, v.Alpha) - if err != nil { - if err.Error() != v.Output { - t.Error("input: ", v.Num, " error: ", err) - } - } else if result != v.Output { - t.Error("got: ", result, " expected: ", v.Output) - } - } -} - -var TestPlainStringToIntData = []struct { - Num string - Alpha string - Output interface{} -}{ - {"0", "USA", ErrorInvalidISO.Error()}, - {"0", "USD", int64(0)}, - {"1", "USD", int64(1)}, - {"10", "USD", int64(10)}, - {"100", "USD", int64(100)}, - {"1000", "USD", int64(1000)}, - {"10000", "USD", int64(10000)}, - {"100000", "USD", int64(100000)}, + {"$100.00,00", "ARS", 1000000}, + {"$10,000,000", "JPY", 10000000}, } func TestPlainStringToInt(t *testing.T) { - for _, v := range TestPlainStringToIntData { - result, err := PlainStringToInt(v.Num, v.Alpha) + for _, v := range TestStringToIntData { + result, err := StringToInt(v.Num, v.Alpha) if err != nil { if err.Error() != v.Output { t.Error(err.Error()) From aff6b2d11b61acfcc77680d13b482b58d5f619e0 Mon Sep 17 00:00:00 2001 From: bvoelker Date: Fri, 10 May 2019 12:15:08 -0500 Subject: [PATCH 4/5] go - added mod file --- go.mod | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..ff618ef --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/fluidpay/dough + +go 1.12 From c03c35f8934e209738d32b909f6fff9bed001e2c Mon Sep 17 00:00:00 2001 From: bvoelker Date: Fri, 10 May 2019 12:17:50 -0500 Subject: [PATCH 5/5] test - minor value update --- currency_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/currency_test.go b/currency_test.go index 994fbd7..ff4ab3b 100644 --- a/currency_test.go +++ b/currency_test.go @@ -10,7 +10,7 @@ func TestCurrencyCount(t *testing.T) { t.Log("Currency Count: ", num) } -var TestFormattedStringToUintData = []struct { +var TestStringToIntData = []struct { Num string Alpha string Output interface{}