@@ -8,6 +8,7 @@ using Cairo
88using  GraphPlot. Colors
99using  GraphPlot. Compose
1010using  Random
11+ using  StableRNGs:  StableRNG
1112using  Test
1213using  VisualRegressionTests
1314using  ImageMagick
@@ -125,13 +126,34 @@ end
125126
126127@testset  " Spring Layout"   begin 
127128    g1 =  path_digraph (3 )
128-     x1, y1 =  spring_layout (g1, 0 ; C =  1 )
129-     #  TODO  spring_layout uses random values which have changed on higher Julia versions
130-     #    we should therefore use StableRNGs.jl for these layouts
131-     @static  if  VERSION  <  v " 1.7" 
132-         @test  all (isapprox .(x1, [1.0 , - 0.014799825222963192 , - 1.0 ]))
133-         @test  all (isapprox .(y1, [- 1.0 , 0.014799825222963303 , 1.0 ]))
134-     end 
129+     g2 =  smallgraph (:house )
130+ 
131+     #  Neither seed nor initial locations provided
132+     x1, y1 =  spring_layout (g1; MAXITER= 10 )
133+     @test  length (x1) ==  nv (g1)
134+     @test  length (y1) ==  nv (g1)
135+ 
136+     #  Using a seed
137+     x2, y2 =  spring_layout (g1, 0 ; C =  1 )
138+     @test  length (x2) ==  nv (g1)
139+     @test  length (y2) ==  nv (g1)
140+ 
141+     #  Using a rng
142+     rng =  StableRNG (123 )
143+     x3, y3 =  spring_layout (g2, rng; INITTEMP =  7.5 )
144+     @test  x3 ≈  [0.6417685918857294 , - 1.0 , 1.0 , - 0.5032029640625139 , 0.585415479582793 ]
145+     @test  y3 ≈  [- 1.0 , - 0.7760280912987298 , 0.06519424728464562 , 0.2702599482349506 , 1.0 ]
146+ 
147+     #  Using initial locations
148+     locs_x_in =  1 : 5 
149+     locs_y_in =  [- 1.0 , 2.0 , 0.3 , 0.4 , - 0.5 ]
150+     x4, y4 =  spring_layout (g2, locs_x_in, locs_y_in)
151+     @test  x4 ≈  [- 1.0 , - 0.4030585026962391 , - 0.050263101475789274 , 0.5149349966578818 , 1.0 ]
152+     @test  y4 ≈  [- 0.03307638042475203 , 1.0 , - 0.8197758901868164 , 0.15834883764718155 , - 1.0 ]
153+ 
154+     #  Providing initial locations with the wrong lengths should throw an ArgumentError
155+     @test_throws  ArgumentError (" The length of locs_x_in does not equal the number of vertices"  ) spring_layout (g1, 1 : 5 , [1 ,2 ,3 ])
156+     @test_throws  ArgumentError (" The length of locs_y_in does not equal the number of vertices"  ) spring_layout (g2, 1 : 5 , [1 ,2 ,3 ])
135157end 
136158
137159@testset  " Circular Layout"   begin 
0 commit comments