From 27435b0c7f8b9a2aa334a2eb84418a6f6cb638bc Mon Sep 17 00:00:00 2001 From: Uwe Hernandez Acosta Date: Wed, 27 Sep 2023 22:05:45 +0200 Subject: [PATCH] renamed _input_validation to _is_valid_input --- src/interfaces/setup_interface.jl | 12 ++++++------ test/interfaces/setup_interface.jl | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/interfaces/setup_interface.jl b/src/interfaces/setup_interface.jl index 20f1b63..bf1918e 100644 --- a/src/interfaces/setup_interface.jl +++ b/src/interfaces/setup_interface.jl @@ -27,10 +27,10 @@ quantity depends on is kept constant. Every subtype of `AbstractComputationSetup` should implement the interface function ```Julia - _input_validation(stp::AbstractComputationSetup, input) # default: true + _is_valid_input(stp::AbstractComputationSetup, input) # default: true ``` - which should return true iff the `input` is valid for the computation of the associated quantity (see [`_input_validation`](@ref) for more details). + which should return true iff the `input` is valid for the computation of the associated quantity (see [`_is_valid_input`](@ref) for more details). The default implementation always returns `true`. Provide a custom implementation if a different behavior is required. ## Actual computation @@ -75,7 +75,7 @@ This function is called to validate the input of [`compute`](@ref) before callin This behavior can be overwritten if actual validation is necessary. """ -@inline function _input_validation(stp::AbstractComputationSetup, input) +@inline function _is_valid_input(stp::AbstractComputationSetup, input) return true end @@ -103,7 +103,7 @@ Interface function that returns the value of the associated quantity evaluated o !!! note "unsafe implementation" - This function must be implemented for any subtype of [`AbstractComputationSetup`]. It should not do any input validation or post processing (see [`_input_validation`](@ref) and [`_post_computation`](@ref)), as those two are performed while calling + This function must be implemented for any subtype of [`AbstractComputationSetup`]. It should not do any input validation or post processing (see [`_is_valid_input`](@ref) and [`_post_computation`](@ref)), as those two are performed while calling the safe version of this function [`compute`](@ref). """ @@ -115,11 +115,11 @@ function _compute end Return the value of the quantity associated with `stp` for a given `input`. In addition to the actual call of the associated unsafe version [`_compute`](@ref), -input validation (using [`_input_validation`](@ref)) and post computation +input validation (using [`_is_valid_input`](@ref)) and post computation (using [`_post_computation`](@ref)) are wrapped around the calculation (see [`AbstractComputationSetup`](@ref) for details). """ function compute(stp::AbstractComputationSetup, input) - _input_validation(stp,input) || error("InvalidInputError: there is something wrong with the input!\n setup:$stp \n input:$input") + _is_valid_input(stp,input) || error("InvalidInputError: there is something wrong with the input!\n setup:$stp \n input:$input") raw_result = _compute(stp,input) return _post_computation(stp, input,raw_result) end diff --git a/test/interfaces/setup_interface.jl b/test/interfaces/setup_interface.jl index f705d8b..f6f6fa3 100644 --- a/test/interfaces/setup_interface.jl +++ b/test/interfaces/setup_interface.jl @@ -21,7 +21,7 @@ struct TestSetupDefault <: AbstractTestSetup end # setup with custom input validation struct TestSetupCustomValidation <: AbstractTestSetup end -QEDprocesses._input_validation(::TestSetupCustomValidation, x) = _groundthruth_input_validation(x) +QEDprocesses._is_valid_input(::TestSetupCustomValidation, x) = _groundthruth_input_validation(x) # setup with custom post computation struct TestSetupCustomPostComputation <: AbstractTestSetup end @@ -29,7 +29,7 @@ QEDprocesses._post_computation(::TestSetupCustomPostComputation,x,y) = _groundtr # setup with custom input validation and post computation struct TestSetupCustom <: AbstractTestSetup end -QEDprocesses._input_validation(::TestSetupCustom, x) = _groundthruth_input_validation(x) +QEDprocesses._is_valid_input(::TestSetupCustom, x) = _groundthruth_input_validation(x) QEDprocesses._post_computation(::TestSetupCustom,x,y) = _groundtruth_post_computation(x,y) # setup which fail on computation with default implementations @@ -37,7 +37,7 @@ struct TestSetupFAIL <: AbstractComputationSetup end # setup which fail on computation with custom input validation struct TestSetupCustomValidationFAIL <: AbstractComputationSetup end -QEDprocesses._input_validation(::TestSetupCustomValidationFAIL, x) = _groundthruth_input_validation(x) +QEDprocesses._is_valid_input(::TestSetupCustomValidationFAIL, x) = _groundthruth_input_validation(x) # setup which fail on computation with custom post computation struct TestSetupCustomPostComputationFAIL <: AbstractComputationSetup end @@ -62,7 +62,7 @@ QEDprocesses._post_computation(::TestSetupCustomPostComputationFAIL,x,y) = _grou rnd_input = rand(RNG) rnd_output = rand(RNG) - @test QEDprocesses._input_validation(stp,rnd_input) + @test QEDprocesses._is_valid_input(stp,rnd_input) @test QEDprocesses._post_computation(stp,rnd_input,rnd_output) == rnd_output @test isapprox(QEDprocesses._compute(stp, rnd_input), _groundthruth_compute(rnd_input), atol=ATOL,rtol=RTOL) @test isapprox(compute(stp, rnd_input), _groundthruth_compute(rnd_input), atol=ATOL,rtol=RTOL) @@ -71,8 +71,8 @@ QEDprocesses._post_computation(::TestSetupCustomPostComputationFAIL,x,y) = _grou @testset "custom input validation" begin stp = TestSetupCustomValidation() rnd_input = rand(RNG) - @test QEDprocesses._input_validation(stp, _groundthruth_input_validation(rnd_input)) - @test !QEDprocesses._input_validation(stp, !_groundthruth_input_validation(rnd_input)) + @test QEDprocesses._is_valid_input(stp, _groundthruth_input_validation(rnd_input)) + @test !QEDprocesses._is_valid_input(stp, !_groundthruth_input_validation(rnd_input)) @test isapprox(compute(stp, rnd_input), _groundthruth_compute(rnd_input), atol=ATOL,rtol=RTOL) @test_throws ErrorException compute(stp, _transform_to_invalid(rnd_input)) end @@ -90,8 +90,8 @@ QEDprocesses._post_computation(::TestSetupCustomPostComputationFAIL,x,y) = _grou rnd_input = rand(RNG) rnd_output = rand(RNG) - @test QEDprocesses._input_validation(stp, _groundthruth_input_validation(rnd_input)) - @test !QEDprocesses._input_validation(stp, !_groundthruth_input_validation(rnd_input)) + @test QEDprocesses._is_valid_input(stp, _groundthruth_input_validation(rnd_input)) + @test !QEDprocesses._is_valid_input(stp, !_groundthruth_input_validation(rnd_input)) @test_throws ErrorException compute(stp, _transform_to_invalid(rnd_input)) @test isapprox(QEDprocesses._post_computation(stp,rnd_input,rnd_output), _groundtruth_post_computation(rnd_input,rnd_output)) @test isapprox(compute(stp,rnd_input), _groundtruth_post_computation(rnd_input,_groundthruth_compute(rnd_input)))