fix(compare): support int64

resolves #3309
This commit is contained in:
Jan De Dobbeleer 2023-01-05 20:53:25 +01:00 committed by Jan De Dobbeleer
parent c1bf3a16fe
commit b5bb060641
3 changed files with 12 additions and 3 deletions

4
.vscode/launch.json vendored
View file

@ -12,7 +12,9 @@
"print",
"primary",
"--shell=pwsh",
"--terminal-width=200"
"--terminal-width=200",
"--execution-time=600",
"--config=/Users/jan/.posh.omp.json"
]
},
{

View file

@ -7,6 +7,9 @@ func interFaceToInt(e interface{}) int {
if val, OK := e.(float64); OK {
return int(val)
}
if val, OK := e.(int64); OK {
return int(val)
}
return 0
}
@ -17,6 +20,9 @@ func interfaceToFloat64(e interface{}) float64 {
if val, OK := e.(int); OK {
return float64(val)
}
if val, OK := e.(int64); OK {
return float64(val)
}
return 0
}
@ -31,5 +37,5 @@ func gt(e1, e2 interface{}) bool {
}
func lt(e1, e2 interface{}) bool {
return !gt(e1, e2)
return gt(e2, e1)
}

View file

@ -16,6 +16,7 @@ func TestGt(t *testing.T) {
{Case: "Float vs int", Expected: false, E1: float64(3), E2: 4},
{Case: "Int vs float", Expected: false, E1: 3, E2: float64(4)},
{Case: "Int vs Int", Expected: false, E1: 3, E2: 4},
{Case: "Int64 vs Int", Expected: false, E1: int64(3), E2: 4},
{Case: "Float vs Float", Expected: false, E1: float64(3), E2: float64(4)},
{Case: "Float vs String", Expected: true, E1: float64(3), E2: "test"},
{Case: "Int vs String", Expected: true, E1: 3, E2: "test"},
@ -40,7 +41,7 @@ func TestLt(t *testing.T) {
{Case: "Int vs Int", Expected: true, E1: 3, E2: 4},
{Case: "Float vs Float", Expected: true, E1: float64(3), E2: float64(4)},
{Case: "Float vs String", Expected: false, E1: float64(3), E2: "test"},
{Case: "String vs String", Expected: true, E1: "test", E2: "test"},
{Case: "String vs String", Expected: false, E1: "test", E2: "test"},
}
for _, tc := range cases {