@@ -11,9 +11,9 @@ import LinearAlgebra
1111import MathOptInterface as MOI
1212import SparseArrays
1313
14- const Nonlinear = MOI . Nonlinear
15- const ReverseAD = Nonlinear. ReverseAD
16- const Coloring = ReverseAD. Coloring
14+ import MathOptInterface . Nonlinear
15+ import MathOptInterface . Nonlinear. ReverseAD
16+ import MathOptInterface . Nonlinear . ReverseAD. Coloring
1717
1818function runtests ()
1919 for name in names (@__MODULE__ ; all = true )
@@ -1421,6 +1421,33 @@ function test_hessian_reinterpret_unsafe()
14211421 return
14221422end
14231423
1424+ function test_IntDisjointSet ()
1425+ for case in [
1426+ [(1 , 2 ) => [1 , 1 , 3 ], (1 , 3 ) => [1 , 1 , 1 ]],
1427+ [(1 , 2 ) => [1 , 1 , 3 ], (3 , 1 ) => [1 , 1 , 1 ]],
1428+ [(2 , 1 ) => [2 , 2 , 3 ], (1 , 3 ) => [2 , 2 , 2 ]],
1429+ [(2 , 1 ) => [2 , 2 , 3 ], (3 , 1 ) => [3 , 2 , 3 ]],
1430+ [(1 , 3 ) => [1 , 2 , 1 ], (2 , 3 ) => [1 , 2 , 2 ]],
1431+ [(1 , 3 ) => [1 , 2 , 1 ], (3 , 2 ) => [1 , 1 , 1 ]],
1432+ [(3 , 1 ) => [3 , 2 , 3 ], (2 , 3 ) => [3 , 3 , 3 ]],
1433+ [(3 , 1 ) => [3 , 2 , 3 ], (3 , 2 ) => [3 , 3 , 3 ]],
1434+ [(2 , 3 ) => [1 , 2 , 2 ], (1 , 3 ) => [1 , 2 , 1 ]],
1435+ [(2 , 3 ) => [1 , 2 , 2 ], (3 , 1 ) => [2 , 2 , 2 ]],
1436+ [(3 , 2 ) => [1 , 3 , 3 ], (1 , 3 ) => [3 , 3 , 3 ]],
1437+ [(3 , 2 ) => [1 , 3 , 3 ], (3 , 1 ) => [3 , 3 , 3 ]],
1438+ ]
1439+ S = Coloring. _IntDisjointSet (3 )
1440+ @test Coloring. _find_root! .((S,), [1 , 2 , 3 ]) == [1 , 2 , 3 ]
1441+ @test S. number_of_trees == 3
1442+ for (i, (union, result)) in enumerate (case)
1443+ Coloring. _root_union! (S, union[1 ], union[2 ])
1444+ @test Coloring. _find_root! .((S,), [1 , 2 , 3 ]) == result
1445+ @test S. number_of_trees == 3 - i
1446+ end
1447+ end
1448+ return
1449+ end
1450+
14241451end # module
14251452
14261453TestReverseAD. runtests ()
0 commit comments