package main import "testing" func TestCanInt(t *testing.T) { if !CanInt("12345") { t.Errorf("Expected valid int conversion of '12345'") } if CanInt("9.81") { t.Errorf("Unexpected int conversion of '9.81', this should return true on CanFloat (not CanInt)") } if !CanInt("-42") { t.Errorf("Expected valid int conversion of '-42'") } if CanInt("-24-88") { t.Errorf("Unexpected int conversion of '-24-88', this should not be allowed as we have 2 '-'") } if !CanInt("-1234567890") { t.Errorf("Expected valid int conversion of '-1234567890'") } if CanInt("123abc") { t.Errorf("Unexpected int conversion of '123abc', contains letters 'abc' which are not numerics") } } func TestCanFloat(t *testing.T) { if !CanFloat("9.81") { t.Errorf("Expected valid float conversion of '9.81'") } if CanFloat("198.164.255.0") { t.Errorf("Unexpected float conversion of '198.164.255.0', this is a IP, not a floating value") } if !CanFloat("-42.0") { t.Errorf("Expected valid float conversion of '-42.0'") } if !CanFloat("1234567890.1234567890") { t.Errorf("Expected valid float conversion of '1234567890.1234567890'") } if CanFloat("-123.-1234") { t.Errorf("Unexpected float conversion of '-123.-1234', contains 2 '-'") } if !CanFloat("0.15") { t.Errorf("Expected valid float conversion of '0.15'") } if !CanFloat(".15") { t.Errorf("Expected valid float conversion of '.15'") } if CanFloat("-123.abc") { t.Errorf("Unexpected float conversion of '-123.abc', contains 'abc' which are not numerics") } } func TestFormatCredits(t *testing.T) { if FormatCredit(1000) != "1,000" { t.Errorf("Expected '1,000' from 1000, got '%s'", FormatCredit(1000)) } if FormatCredit(10000) != "10,000" { t.Errorf("Expected '10,000' from 10000, got '%s'", FormatCredit(10000)) } if FormatCredit(1000000) != "1,000,000" { t.Errorf("Expected '1,000,000' from 1000000, got '%s'", FormatCredit(1000000)) } if FormatCredit(-4000) != "-4,000" { t.Errorf("Expected '-4,000' from -4000, got '%s'", FormatCredit(-4000)) } }