Skip to content

Commit

Permalink
Fix unit tests on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisYatunin committed Jun 15, 2023
1 parent f15ba20 commit c7ea45c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/MatrixFields/matrix_field_broadcasting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function test_func_against_array_reference(;
temp_values_arrays,
)

# Compute the maximum error as an integer multiple of epsilon.
# Compute the maximum error as an integer multiple of machine epsilon.
result_arrays = field2arrays(result)
maximum_error =
maximum(zip(result_arrays, ref_result_arrays)) do (array, ref_array)
Expand Down
16 changes: 11 additions & 5 deletions test/MatrixFields/rmul_with_projection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@ import ClimaCore: Geometry
import ClimaCore.MatrixFields:
rmul_with_projection, rmul_with_projection_return_type

import ClimaCore.RecursiveApply: rsub

function test_rmul_with_projection(x, y, lg, expected_result)
result = rmul_with_projection(x, y, lg)
result_type = rmul_with_projection_return_type(typeof(x), typeof(y))

# Compute the maximum error as an integer multiple of machine epsilon.
FT = Geometry.undertype(typeof(lg))
object2tuple(obj) =
reinterpret(NTuple{sizeof(obj) ÷ sizeof(FT), FT}, [obj])[1]
maximum_error = maximum(
((value, expected_value),) ->
Int(abs(value - expected_value) / eps(expected_value)),
zip(object2tuple(result), object2tuple(expected_result)),
)

# Check for correctness.
@info "$(result == expected_result)\n\t$result\n\t$expected_result\n\t\
$(rsub(result, expected_result))"
@test result == expected_result # TODO: Why doesn't this work on CI?
@test maximum_error <= 1
@test result_type == typeof(result)

# Check for inference failures.
Expand Down

0 comments on commit c7ea45c

Please sign in to comment.