|
| 1 | +using Test |
| 2 | +@testset "Simple Vector Function" begin |
| 3 | + func(x) = [0.5*sqrt(abs(x[1] + x[2])), 1.5*x[1] + 0.5*x[2]] |
| 4 | + Inputs = [0.3,900.0] |
| 5 | + fp_simple = fixed_point(func, Inputs; Algorithm = :Simple) |
| 6 | + @test fp_simple.Convergence_ < 1e-10 |
| 7 | + fp_anderson = fixed_point(func, Inputs; Algorithm = :Anderson) |
| 8 | + @test fp_anderson.Convergence_ < 1e-10 |
| 9 | + fp_aitken = fixed_point(func, Inputs; Algorithm = :Aitken) |
| 10 | + @test fp_aitken.Convergence_ < 1e-10 |
| 11 | + fp_newton = fixed_point(func, Inputs; Algorithm = :Newton) |
| 12 | + @test fp_newton.Convergence_ < 1e-10 |
| 13 | + fp_VEA = fixed_point(func, Inputs; Algorithm = :VEA) |
| 14 | + @test fp_VEA.Convergence_ < 1e-10 |
| 15 | + fp_SEA = fixed_point(func, Inputs; Algorithm = :SEA) |
| 16 | + @test fp_SEA.Convergence_ < 1e-10 |
| 17 | + fp_MPE = fixed_point(func, Inputs; Algorithm = :MPE) |
| 18 | + @test fp_MPE.Convergence_ < 1e-10 |
| 19 | + fp_RRE = fixed_point(func, Inputs; Algorithm = :RRE) |
| 20 | + @test fp_RRE.Convergence_ < 1e-10 |
| 21 | + |
| 22 | + # Now trying a function with a typeswitch from Int to Float |
| 23 | + Inputs = [1,4] |
| 24 | + fp_simple = fixed_point(func, Inputs; Algorithm = :Simple) |
| 25 | + @test fp_simple.Convergence_ < 1e-10 |
| 26 | + fp_anderson = fixed_point(func, Inputs; Algorithm = :Anderson) |
| 27 | + @test fp_anderson.Convergence_ < 1e-10 |
| 28 | + |
| 29 | + # And finally printing a couple of them to test printing. |
| 30 | + fp_anderson2 = fixed_point(func, Inputs; Algorithm = :Anderson, PrintReports = true) |
| 31 | + @test fp_anderson2.Convergence_ < 1e-10 |
| 32 | + fp_simple2 = fixed_point(func, Inputs; Algorithm = :Simple, PrintReports = true) |
| 33 | + @test fp_simple2.Convergence_ < 1e-10 |
| 34 | + |
| 35 | + # Testing function that returns a missing |
| 36 | + f(x) = [missing, missing] |
| 37 | + fp_simple3 = fixed_point(f, Inputs; Algorithm = :Simple, PrintReports = true) |
| 38 | + @test fp_simple3.TerminationCondition_ == :InvalidInputOrOutputOfIteration |
| 39 | + f(x) = [1, missing] |
| 40 | + fp_simple4 = fixed_point(f, Inputs; Algorithm = :Simple, PrintReports = true) |
| 41 | + @test fp_simple4.TerminationCondition_ == :InvalidInputOrOutputOfIteration |
| 42 | + |
| 43 | + # Testing the outputting of a tuple |
| 44 | + f(x) = (a = [1.0, 1.0], b = :goodProgressInFunction) |
| 45 | + @test_throws ErrorException("This function returned a NamedTuple{(:a, :b),Tuple{Array{Float64,1},Symbol}}. The Fixedpoint function can only return a vector or a tuple of which the first entry is the vector for which a fixedpoint is sought and the second is a namedtuple (the contents of which are output for the user but are not used in fixed point acceleration).") fixed_point(f, Inputs; Algorithm = :Simple, PrintReports = true) |
| 46 | + # And doing side effects properly. |
| 47 | + f(x) = ([1.0, 1.0], (b = :goodProgressInFunction,)) |
| 48 | + fp_simple5 = fixed_point(f, Inputs; Algorithm = :Simple, PrintReports = true) |
| 49 | + @test fp_simple5.Convergence_ < 1e-10 |
| 50 | +end |
0 commit comments