Fix geo double compare
This commit is contained in:
parent
5e877bc05f
commit
79bd7e8739
18
cts.json
18
cts.json
|
@ -5528,7 +5528,8 @@
|
||||||
null
|
null
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"since": "3.2.0"
|
"since": "3.2.0",
|
||||||
|
"float_result": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "georadius command",
|
"name": "georadius command",
|
||||||
|
@ -5601,7 +5602,8 @@
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"since": "3.2.0"
|
"since": "3.2.0",
|
||||||
|
"float_result": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "georadius with COUNT",
|
"name": "georadius with COUNT",
|
||||||
|
@ -5766,7 +5768,8 @@
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"since": "3.2.0"
|
"since": "3.2.0",
|
||||||
|
"float_result": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "georadius_ro with COUNT",
|
"name": "georadius_ro with COUNT",
|
||||||
|
@ -5896,7 +5899,8 @@
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"since": "3.2.0"
|
"since": "3.2.0",
|
||||||
|
"float_result": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "georadiusbymember with COUNT",
|
"name": "georadiusbymember with COUNT",
|
||||||
|
@ -6083,7 +6087,8 @@
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"since": "3.2.10"
|
"since": "3.2.10",
|
||||||
|
"float_result": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "georadiusbymember_ro with COUNT",
|
"name": "georadiusbymember_ro with COUNT",
|
||||||
|
@ -6310,7 +6315,8 @@
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"since": "6.2.0"
|
"since": "6.2.0",
|
||||||
|
"float_result": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "geosearch with support for uppercase unit names",
|
"name": "geosearch with support for uppercase unit names",
|
||||||
|
|
|
@ -156,6 +156,43 @@ def sort_nested_list(result):
|
||||||
return sorted(result)
|
return sorted(result)
|
||||||
|
|
||||||
|
|
||||||
|
def compare_nested_lists_with_float_tolerance(list1, list2, tolerance=0.01):
|
||||||
|
"""
|
||||||
|
Compare two nested lists with float tolerance.
|
||||||
|
For each string that can be converted to float, compare as float with tolerance.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
list1: First list to compare
|
||||||
|
list2: Second list to compare
|
||||||
|
tolerance: Float tolerance for comparison (default 0.01)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if lists are equal within tolerance, False otherwise
|
||||||
|
"""
|
||||||
|
if type(list1) != type(list2):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if isinstance(list1, list):
|
||||||
|
if len(list1) != len(list2):
|
||||||
|
return False
|
||||||
|
for i in range(len(list1)):
|
||||||
|
if not compare_nested_lists_with_float_tolerance(list1[i], list2[i], tolerance):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
elif isinstance(list1, str):
|
||||||
|
# Try to convert both strings to float for comparison
|
||||||
|
try:
|
||||||
|
float1 = float(list1)
|
||||||
|
float2 = float(list2)
|
||||||
|
return abs(float1 - float2) < tolerance
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
# If conversion fails, compare as strings
|
||||||
|
return list1 == list2
|
||||||
|
else:
|
||||||
|
# For other types (int, bool, etc.), use direct comparison
|
||||||
|
return list1 == list2
|
||||||
|
|
||||||
|
|
||||||
def run_test(test):
|
def run_test(test):
|
||||||
name = test['name']
|
name = test['name']
|
||||||
print(f"test: {name}", end=" ", file=logfile)
|
print(f"test: {name}", end=" ", file=logfile)
|
||||||
|
@ -194,7 +231,11 @@ def run_test(test):
|
||||||
if 'sort_result' in test and isinstance(result[idx], list):
|
if 'sort_result' in test and isinstance(result[idx], list):
|
||||||
ret = sort_nested_list(ret)
|
ret = sort_nested_list(ret)
|
||||||
result[idx] = sort_nested_list(result[idx])
|
result[idx] = sort_nested_list(result[idx])
|
||||||
if result[idx] != ret:
|
if 'float_result' in test and isinstance(result[idx], list):
|
||||||
|
if not compare_nested_lists_with_float_tolerance(result[idx], ret):
|
||||||
|
test_failed(g_results[since], name, f"expected: {result[idx]}, result: {ret}")
|
||||||
|
return
|
||||||
|
elif result[idx] != ret:
|
||||||
test_failed(g_results[since], name, f"expected: {result[idx]}, result: {ret}")
|
test_failed(g_results[since], name, f"expected: {result[idx]}, result: {ret}")
|
||||||
return
|
return
|
||||||
test_passed(g_results[since])
|
test_passed(g_results[since])
|
||||||
|
|
Loading…
Reference in New Issue