@@ -219,6 +219,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
219219
220220 # Predicates #
221221 # ------------#
222+ @testset " Predicates" begin
222223
223224 @test ForwardDiff. isconstant (zero (FDNUM))
224225 @test ForwardDiff. isconstant (one (FDNUM))
@@ -231,10 +232,13 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
231232 @test isequal (FDNUM, Dual {TestTag()} (PRIMAL, PARTIALS2)) == (N == 0 )
232233 @test isequal (PRIMAL, PRIMAL2) == isequal (FDNUM, FDNUM2)
233234
234- @test isequal (NESTED_FDNUM, Dual {TestTag()} (Dual {TestTag()} (PRIMAL, M_PARTIALS2), NESTED_PARTIALS2)) == (N == M == 0 )
235- # @test isequal(PRIMAL, PRIMAL2) == isequal(NESTED_FDNUM, NESTED_FDNUM2)
235+ # Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
236+ # and FDNUM2 has everything with a 2, and all random numbers nonzero.
237+ # M is the length of M_PARTIALS, which affects:
238+ # NESTED_FDNUM = Dual{TestTag()}(Dual{TestTag()}(PRIMAL, M_PARTIALS), NESTED_PARTIALS)
236239
237- @info " Predicates" N M V PRIMAL PRIMAL2 NESTED_FDNUM NESTED_FDNUM2
240+ @test isequal (NESTED_FDNUM, Dual {TestTag()} (Dual {TestTag()} (PRIMAL, M_PARTIALS2), NESTED_PARTIALS2)) == (N == M == 0 )
241+ @test isequal (NESTED_FDNUM, NESTED_FDNUM2) == isequal (PRIMAL, PRIMAL2) && (N == M == 0 )
238242
239243 @test (FDNUM == Dual {TestTag()} (PRIMAL, PARTIALS2)) == (N == 0 )
240244 @test (PRIMAL == PRIMAL2) == (FDNUM == FDNUM2)
@@ -319,6 +323,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
319323 @test isodd (Dual {TestTag()} (Dual {TestTag()} (1 )))
320324 @test ! (isodd (Dual {TestTag()} (Dual {TestTag()} (2 ))))
321325
326+ end
322327 # #######################
323328 # Promotion/Conversion #
324329 # #######################
@@ -392,8 +397,11 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
392397
393398 # Division #
394399 # ----------#
400+ @testset " Division" begin
395401
396402 if M > 0 && N > 0
403+ # Recall that FDNUM = Dual{TestTag()}(PRIMAL, PARTIALS) has N partials,
404+ # all random numbers nonzero, and FDNUM2 another draw. M only affects NESTED_FDNUM.
397405 @test Dual {1} (FDNUM) / Dual {1} (PRIMAL) === Dual {1} (FDNUM / PRIMAL)
398406 @test Dual {1} (PRIMAL) / Dual {1} (FDNUM) === Dual {1} (PRIMAL / FDNUM)
399407 @test_broken Dual {1} (FDNUM) / FDNUM2 === Dual {1} (FDNUM / FDNUM2)
@@ -410,8 +418,12 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
410418 @test dual_isapprox (NESTED_FDNUM / PRIMAL, Dual {TestTag()} (value (NESTED_FDNUM) / PRIMAL, partials (NESTED_FDNUM) / PRIMAL))
411419 @test dual_isapprox (PRIMAL / NESTED_FDNUM, Dual {TestTag()} (PRIMAL / value (NESTED_FDNUM), (- (PRIMAL) / value (NESTED_FDNUM)^ 2 ) * partials (NESTED_FDNUM)))
412420
421+ end
422+
413423 # Exponentiation #
414424 # ----------------#
425+ @testset " Exponentiation" begin
426+
415427 # If V == Int, the LHS terms are Int's. Large inputs cause integer overflow
416428 # within the generic fallback of `isapprox`, resulting in a DomainError.
417429 # Promote to Float64 to avoid issues.
@@ -425,6 +437,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
425437
426438 @test partials (NaNMath. pow (Dual {TestTag()} (- 2.0 , 1.0 ), Dual {TestTag()} (2.0 , 0.0 )), 1 ) == - 4.0
427439
440+ end
428441 # ##################################
429442 # General Mathematical Operations #
430443 # ##################################
@@ -517,6 +530,7 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
517530
518531 # Special Cases #
519532 # ---------------#
533+ @testset " Special Cases" begin
520534
521535 @test_broken dual_isapprox (hypot (FDNUM, FDNUM2, FDNUM), sqrt (2 * (FDNUM^ 2 ) + FDNUM2^ 2 ))
522536 @test_broken dual_isapprox (hypot (FDNUM, FDNUM2, FDNUM3), sqrt (FDNUM^ 2 + FDNUM2^ 2 + FDNUM3^ 2 ))
@@ -541,8 +555,14 @@ ForwardDiff.:≺(::Int, ::Type{TestTag()}) = false
541555 @test dual_isapprox (f (FDNUM, PRIMAL2, PRIMAL3), Dual {TestTag()} (f (PRIMAL, PRIMAL2, PRIMAL3), PRIMAL2* PARTIALS))
542556 @test dual_isapprox (f (PRIMAL, PRIMAL2, FDNUM3), Dual {TestTag()} (f (PRIMAL, PRIMAL2, PRIMAL3), PARTIALS3))
543557 end
558+
559+ end # testset
544560end
545561
562+ # ############
563+ # bug fixes #
564+ # ############
565+
546566@testset " Exponentiation of zero" begin
547567 x0 = 0.0
548568 x1 = Dual {:t1} (x0, 1.0 )
0 commit comments