@@ -84,3 +84,55 @@ three_halves_pi = 3*big_pi/2
84
84
85
85
end
86
86
end
87
+
88
+ @testset " Testing slope newton1d" begin
89
+
90
+ f (x) = exp (x^ 2 ) - cos (x) # double root
91
+ f1 (x) = x^ 4 - 10 x^ 3 + 35 x^ 2 - 50 x + 24 # four unique roots
92
+ f2 (x) = 4567 x^ 2 - 9134 x + 4567 # double root
93
+ f3 (x) = (x^ 2 - 2 )^ 2 # two double roots
94
+ f4 (x) = sin (x) - x # triple root at 0
95
+ f5 (x) = (x^ 2 - 1 )^ 4 * (x^ 2 - 2 )^ 4 # two quadruple roots
96
+
97
+ rts1 = slope_newton1d (sin, - 5 .. 5 )
98
+ rts2 = slope_newton1d (f, - ∞.. ∞)
99
+ rts3 = slope_newton1d (f1, - 10 .. 10 )
100
+ rts4 = slope_newton1d (f2, - 10 .. 11 )
101
+ rts5 = slope_newton1d (f3, - 10 .. 10 )
102
+ rts6 = slope_newton1d (f4, - 10 .. 10 )
103
+ rts7 = slope_newton1d (f5, - 10 .. 10 )
104
+
105
+ @test length (rts1) == 3
106
+ L = [ - pi_interval (Float64), 0 .. 0 , pi_interval (Float64)]
107
+ for i = 1 : length (rts1)
108
+ @test L[i] in rts1[i]. interval && :unique == rts1[i]. status
109
+ end
110
+
111
+ @test length (rts2) == 1
112
+ @test (0 .. 0 ) == rts2[1 ]. interval && :unknown == rts2[1 ]. status
113
+
114
+ @test length (rts3) == 4
115
+ L = [1 , 2 , 3 , 4 ]
116
+ for i = 1 : length (rts3)
117
+ @test L[i] in rts3[i]. interval && :unique == rts3[i]. status
118
+ end
119
+
120
+ @test length (rts4) == 1
121
+ @test 1 in rts4[1 ]. interval && :unknown == rts4[1 ]. status
122
+
123
+ L1 = [- sqrt (2 ), sqrt (2 )]
124
+ for i = 1 : length (rts5)
125
+ @test L1[i] in rts5[i]. interval && :unknown == rts5[i]. status
126
+ end
127
+
128
+
129
+ @test length (rts6) == 1
130
+ @test 0 in rts6[1 ]. interval && :unknown == rts6[1 ]. status
131
+
132
+ @test length (rts7) == 4
133
+ L = [- sqrt (2 ), - 1 , 1 , sqrt (2 )]
134
+ for i = 1 : length (rts7)
135
+ @test L[i] in rts7[i]. interval && :unknown == rts7[i]. status
136
+ end
137
+
138
+ end
0 commit comments