package convert import ( "testing" "time" ) func TestFloatFromString(t *testing.T) { t.Parallel() testString := "1.41421356237" expectedOutput := float64(1.41421356237) actualOutput, err := FloatFromString(testString) if actualOutput != expectedOutput || err != nil { t.Errorf("Test failed. Common FloatFromString. Expected '%v'. Actual '%v'. Error: %s", expectedOutput, actualOutput, err) } var testByte []byte _, err = FloatFromString(testByte) if err == nil { t.Error("Test failed. Common FloatFromString. Converted non-string.") } testString = " something unconvertible " _, err = FloatFromString(testString) if err == nil { t.Error("Test failed. Common FloatFromString. Converted invalid syntax.") } } func TestIntFromString(t *testing.T) { t.Parallel() testString := "1337" expectedOutput := 1337 actualOutput, err := IntFromString(testString) if actualOutput != expectedOutput || err != nil { t.Errorf("Test failed. Common IntFromString. Expected '%v'. Actual '%v'. Error: %s", expectedOutput, actualOutput, err) } var testByte []byte _, err = IntFromString(testByte) if err == nil { t.Error("Test failed. Common IntFromString. Converted non-string.") } testString = "1.41421356237" _, err = IntFromString(testString) if err == nil { t.Error("Test failed. Common IntFromString. Converted invalid syntax.") } } func TestInt64FromString(t *testing.T) { t.Parallel() testString := "4398046511104" expectedOutput := int64(1 << 42) actualOutput, err := Int64FromString(testString) if actualOutput != expectedOutput || err != nil { t.Errorf("Test failed. Common Int64FromString. Expected '%v'. Actual '%v'. Error: %s", expectedOutput, actualOutput, err) } var testByte []byte _, err = Int64FromString(testByte) if err == nil { t.Error("Test failed. Common Int64FromString. Converted non-string.") } testString = "1.41421356237" _, err = Int64FromString(testString) if err == nil { t.Error("Test failed. Common Int64FromString. Converted invalid syntax.") } } func TestTimeFromUnixTimestampFloat(t *testing.T) { t.Parallel() testTimestamp := float64(1414456320000) expectedOutput := time.Date(2014, time.October, 28, 0, 32, 0, 0, time.UTC) actualOutput, err := TimeFromUnixTimestampFloat(testTimestamp) if actualOutput.UTC().String() != expectedOutput.UTC().String() || err != nil { t.Errorf("Test failed. Common TimeFromUnixTimestampFloat. Expected '%v'. Actual '%v'. Error: %s", expectedOutput, actualOutput, err) } testString := "Time" _, err = TimeFromUnixTimestampFloat(testString) if err == nil { t.Error("Test failed. Common TimeFromUnixTimestampFloat. Converted invalid syntax.") } }