-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ConvertNumeric now handles bools (#1336)
## Which problem is this PR solving? - Closes #1335 ## Short description of the changes - Add bool case to ConvertNumeric - Add test for ConvertNumeric function
- Loading branch information
1 parent
51f5941
commit e09d23b
Showing
2 changed files
with
39 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,35 @@ | ||
package metrics | ||
|
||
import "testing" | ||
|
||
func TestConvertNumeric(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
val interface{} | ||
want float64 | ||
}{ | ||
// TODO: Add test cases. | ||
{"int", 17, 17}, | ||
{"uint", uint(17), 17}, | ||
{"int64", int64(17), 17}, | ||
{"uint64", uint64(17), 17}, | ||
{"int32", int32(17), 17}, | ||
{"uint32", uint32(17), 17}, | ||
{"int16", int16(17), 17}, | ||
{"uint16", uint16(17), 17}, | ||
{"int8", int8(17), 17}, | ||
{"uint8", uint8(17), 17}, | ||
{"float64", float64(17), 17}, | ||
{"float32", float32(17), 17}, | ||
{"bool", true, 1}, | ||
{"bool", false, 0}, | ||
{"string", "17", 0}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := ConvertNumeric(tt.val); got != tt.want { | ||
t.Errorf("ConvertNumeric() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |