File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ export find_solution, find_search_interval
33"""
44 (a, b) = find_search_interval(f)
55
6- Returns an interval such that ``f(a) × f(b) ≯ 0``.
6+ Returns an interval such that ``f(a) × f(b) ≤ 0``.
77It could be 0 for either endpoint, but it is not positive,
88ensuring that there is a root in `[a, b]`.
99"""
@@ -32,6 +32,7 @@ S(x) = \\frac{1}{|P|} \\sum_{p ∈ P:\\ p > 0} p^x.
3232If not possible, return either 0 or 1000, depending on what is most appropriate.
3333"""
3434function find_solution (P, μ)
35+ validate_profile (P)
3536 σ (P, x) = P > 0 ? P^ x : 0.0
3637 S (P, x) = mean (σ .(P, x))
3738 m = length (P)
@@ -46,3 +47,14 @@ function find_solution(P, μ)
4647 return 1000.0
4748 end
4849end
50+
51+ """
52+ validate_profile(P)
53+
54+ Validates if the values of profile P are within 0 and 1. If not, throws an error message and stops the calculation.
55+ """
56+ function validate_profile (P)
57+ if ! all (0 .≤ P .≤ 1 )
58+ error (" Profile values must be within 0 and 1. Calculation stopped." )
59+ end
60+ end
Original file line number Diff line number Diff line change @@ -25,8 +25,15 @@ function test_fit_profile()
2525 @test find_solution (profile_values, target_mean) ≈ expected_coefficient atol = 1e-3
2626end
2727
28+ function test_throws_error ()
29+ profile_values = [- 0.5 , 0.2 , 0.8 , 1.5 ]
30+ target_mean = 0.5
31+ @test_throws ErrorException find_solution (profile_values, target_mean)
32+ end
33+
2834@testset " TulipaProfileFitting" begin
2935 @testset " fit_profile" begin
3036 test_fit_profile ()
37+ test_throws_error ()
3138 end
3239end
You can’t perform that action at this time.
0 commit comments