File tree Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Expand file tree Collapse file tree 2 files changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import (
13
13
// Helper function to validate if the string is a valid currency format (with 2 decimal places)
14
14
func IsValidCurrencyFormat (amount string ) bool {
15
15
// Regex pattern to match valid decimal with exactly two decimal places
16
- validCurrency := regexp .MustCompile (`^\d+(\.\d{2})$` )
16
+ validCurrency := regexp .MustCompile (`^-? \d+(\.\d{2})$` )
17
17
return validCurrency .MatchString (amount )
18
18
}
19
19
Original file line number Diff line number Diff line change @@ -46,27 +46,27 @@ func TestCheckCurrency(t *testing.T) {
46
46
47
47
// Test an invalid currency
48
48
if IsValidCurrencyFormat ("abc" ) {
49
- t .Fatalf ("Expected currency 100 to be invalid" )
49
+ t .Fatalf ("Expected currency abc to be invalid" )
50
50
}
51
51
52
52
// Test an invalid currency
53
53
if IsValidCurrencyFormat ("abc.fg" ) {
54
- t .Fatalf ("Expected currency 100 to be invalid" )
54
+ t .Fatalf ("Expected currency abc.fg to be invalid" )
55
55
}
56
56
57
57
// Test an invalid currency
58
58
if IsValidCurrencyFormat ("abc.23" ) {
59
- t .Fatalf ("Expected currency 100 to be invalid" )
59
+ t .Fatalf ("Expected currency abc.23 to be invalid" )
60
60
}
61
61
62
62
// Test an invalid currency
63
63
if IsValidCurrencyFormat ("100.ab" ) {
64
- t .Fatalf ("Expected currency 100 to be invalid" )
64
+ t .Fatalf ("Expected currency 100.ab to be invalid" )
65
65
}
66
66
67
67
// Test negative currency
68
- if IsValidCurrencyFormat ("-100.00" ) {
69
- t .Fatalf ("Expected currency 100 to be invalid " )
68
+ if ! IsValidCurrencyFormat ("-100.00" ) {
69
+ t .Fatalf ("Expected currency - 100.00 to be valid " )
70
70
}
71
71
72
72
//Test zero
You can’t perform that action at this time.
0 commit comments