-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #343 from atlassian/jdu/coerce-non-numeric-values
Coerce non-numeric values to numeric in the datadog backend
- Loading branch information
Showing
4 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package datadog | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
) | ||
|
||
func TestCoerceToNumeric(t *testing.T) { | ||
t.Parallel() | ||
tests := []struct { | ||
name string | ||
arg float64 | ||
want float64 | ||
}{ | ||
{"NaN should return 0", math.NaN(), -1}, | ||
{"+Inf should return maximum float value", math.Inf(+1), math.MaxFloat64}, | ||
{"-Inf should return minimum float value", math.Inf(-1), -math.MaxFloat64}, | ||
{"Numeric value should return unchanged", 0, 0}, | ||
{"Numeric value should return unchanged", 12_345, 12_345}, | ||
{"Numeric value should return unchanged", -12_345, -12_345}, | ||
{"Numeric value should return unchanged", math.MaxFloat64, math.MaxFloat64}, | ||
{"-Inf should return minimum float value", -math.MaxFloat64, -math.MaxFloat64}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := coerceToNumeric(tt.arg); got != tt.want { | ||
t.Errorf("coerceToNumeric() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |