-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement numeric comparison modifiers (>, >=, <, <=) (#32)
* Add type coercion helper * Add testcase * Refactor, add remaining comparators * Move test up one layer of implementation detail
- Loading branch information
1 parent
9c8e97b
commit 47169b1
Showing
4 changed files
with
212 additions
and
24 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,46 @@ | ||
package evaluator | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func Test_compareNumeric(t *testing.T) { | ||
tests := []struct { | ||
left interface{} | ||
right interface{} | ||
wantGt bool | ||
wantGte bool | ||
wantLt bool | ||
wantLte bool | ||
}{ | ||
{1, 2, false, false, true, true}, | ||
{1.1, 1.2, false, false, true, true}, | ||
{1, 1.2, false, false, true, true}, | ||
{1.1, 2, false, false, true, true}, | ||
{1, "2", false, false, true, true}, | ||
{"1.1", 1.2, false, false, true, true}, | ||
{"1.1", 1.1, false, true, false, true}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(fmt.Sprintf("%s_%s", tt.left, tt.right), func(t *testing.T) { | ||
gotGt, gotGte, gotLt, gotLte, err := compareNumeric(tt.left, tt.right) | ||
if err != nil { | ||
t.Errorf("compareNumeric() error = %v", err) | ||
return | ||
} | ||
if gotGt != tt.wantGt { | ||
t.Errorf("compareNumeric() gotGt = %v, want %v", gotGt, tt.wantGt) | ||
} | ||
if gotGte != tt.wantGte { | ||
t.Errorf("compareNumeric() gotGte = %v, want %v", gotGte, tt.wantGte) | ||
} | ||
if gotLt != tt.wantLt { | ||
t.Errorf("compareNumeric() gotLt = %v, want %v", gotLt, tt.wantLt) | ||
} | ||
if gotLte != tt.wantLte { | ||
t.Errorf("compareNumeric() gotLte = %v, want %v", gotLte, tt.wantLte) | ||
} | ||
}) | ||
} | ||
} |