@@ -373,8 +373,26 @@ test_that("caugi_graph(vector mode) works with isolated nodes", {
373373 expect_equal(cg_vec_1 , cg_vec_2 )
374374})
375375
376+ test_that(" caugi_graph preserves node order from nodes parameter" , {
377+ # When nodes parameter is provided, its order should be preserved
378+ # even when edges reference nodes in different order
379+ cg <- caugi_graph(
380+ from = c(" V3" , " V7" , " V2" ),
381+ edge = c(" -->" , " -->" , " -->" ),
382+ to = c(" V1" , " V9" , " V5" ),
383+ nodes = paste0(" V" , 1 : 10 ),
384+ class = " DAG"
385+ )
386+
387+ # Node order should match the provided nodes parameter
388+ expect_equal(V(cg )$ name , paste0(" V" , 1 : 10 ))
389+
390+ # Edges should still be present and correct
391+ expect_equal(nrow(edges(cg )), 3 )
392+ })
393+
376394# ──────────────────────────────────────────────────────────────────────────────
377- # ────────────────────────────────── Errors ────────────────────────────────────
395+ # ────────────────────────────────────── Errors ────────────────────────────────
378396# ──────────────────────────────────────────────────────────────────────────────
379397
380398test_that(" caugi_graph errors with trailing commas" , {
0 commit comments