@@ -392,9 +392,10 @@ test_that("caugi_graph preserves node order from nodes parameter", {
392392})
393393
394394# ──────────────────────────────────────────────────────────────────────────────
395- # ────────────────────────────────────── Errors ── ──────────────────────────────
395+ # ─────────────────────────── Errors and warnings ──────────────────────────────
396396# ──────────────────────────────────────────────────────────────────────────────
397397
398+
398399test_that(" caugi_graph errors with trailing commas" , {
399400 expect_error(
400401 caugi_graph(
@@ -404,3 +405,82 @@ test_that("caugi_graph errors with trailing commas", {
404405 " Argument 3 is missing"
405406 )
406407})
408+
409+ test_that(" caugi_graph warns when build = TRUE for empty graph" , {
410+ expect_warning(
411+ caugi_graph(build = TRUE ),
412+ " No edges or nodes provided; graph will not be built."
413+ )
414+ })
415+
416+ test_that(" caugi_graph with wrong node input errors" , {
417+ expect_error(
418+ caugi_graph(
419+ from = c(" A" , " B" ),
420+ edge = c(" -->" , " ---" ),
421+ to = c(" B" , " C" ),
422+ nodes = list (" D" , " E" )
423+ ),
424+ " `nodes` must be a character vector"
425+ )
426+ })
427+
428+ # ──────────────────────────────────────────────────────────────────────────────
429+ # ─────────────────────────── .view_to_caugi_graph ─────────────────────────────
430+ # ──────────────────────────────────────────────────────────────────────────────
431+
432+ test_that(" .view_to_caugi_graph works as expected" , {
433+ cg <- caugi_graph(
434+ A %-- > % B ,
435+ B %--- % C ,
436+ C %<- > % D
437+ )
438+
439+ cg2 <- .view_to_caugi_graph(cg @ ptr )
440+ expect_s7_class(cg2 , caugi_graph )
441+ expect_equal(cg , cg2 )
442+ })
443+
444+ test_that(" .view_to_caugi_graph fails on NULL ptr" , {
445+ expect_error(
446+ .view_to_caugi_graph(NULL ),
447+ " ptr is NULL"
448+ )
449+ })
450+
451+ test_that(" .view_to_caugi_graph fails on faulty node_names" , {
452+ cg <- caugi_graph(
453+ A %-- > % B
454+ )
455+ expect_error(
456+ .view_to_caugi_graph(cg @ ptr , node_names = c(" A" )),
457+ " length"
458+ )
459+ })
460+
461+ test_that(" .view_to_caugi_graph works for empty cg" , {
462+ cg <- caugi_graph(A , B , build = TRUE )
463+ expect_equal(cg , .view_to_caugi_graph(cg @ ptr ))
464+ })
465+
466+ # ──────────────────────────────────────────────────────────────────────────────
467+ # ───────────────────────── Freezing and unfreezing ────────────────────────────
468+ # ──────────────────────────────────────────────────────────────────────────────
469+
470+ test_that(" freeze / unfreeze works as expected" , {
471+ cg <- caugi_graph(
472+ A %-- > % B ,
473+ B %--- % C
474+ )
475+
476+ # test if built is TRUE
477+ expect_true(cg @ built )
478+ # currently frozen
479+ s <- cg @ .state
480+ expect_error(s $ built <- FALSE )
481+
482+ s <- caugi ::: .unfreeze_state(cg @ .state )
483+ s $ built <- FALSE
484+ expect_false(s $ built )
485+ expect_false(cg @ .state $ built )
486+ })
0 commit comments