snaptol.compare.compare_intelligent#
- snaptol.compare.compare_intelligent(actual, expected, rtol=1e-05, atol=1e-08, equal_nan=False)[source]#
Intelligently compare two values of any type for equality. Returns
Trueif the values are considered equal, andFalseotherwise.This function handles various Python data types and performs appropriate comparisons:
Floats: Uses numpy’sisclosewith relative and absolute tolerancesIntegers: Exact equalityComplex: Exact equalityStrings: Exact equalityBooleans: Exact equalityBytes/Bytearray/Memoryview: Byte-wise equalityNone: Identity comparisonNumPy arrays: Uses numpy’s allclose
Mapping(dict-like): Deep comparison of keys and valuesIterable: Order-sensitive element-wise comparisonCollection: Length and element-wise comparisonSet: Order-insensitive comparison of string representationsOther types: Standard equality comparison
- Parameters:
actual (
Any) – The value to compareexpected (
Any) – The expected value to compare againstrtol (optional) – Relative tolerance for floating point comparisons, by default 1e-05
atol (optional) – Absolute tolerance for floating point comparisons, by default 1e-08
equal_nan (optional) – Whether to consider NaN values equal to each other, by default False
- Return type: