Nothing
# Tests for MICMAC analysis
test_that("micmac_analysis returns correct structure", {
adj <- matrix(c(
0, 1, 0, 0,
0, 0, 1, 1,
0, 0, 0, 0,
0, 0, 0, 0
), nrow = 4, byrow = TRUE)
reach <- compute_reachability(adj)
result <- micmac_analysis(reach)
expect_s3_class(result, "micmac_result")
expect_s3_class(result, "data.frame")
# Check columns
expect_true(all(c("node", "label", "driving_power", "dependence_power", "cluster")
%in% names(result)))
})
test_that("micmac_analysis calculates powers correctly", {
# Simple matrix where powers are easy to verify
reach <- matrix(c(
1, 1, 1,
0, 1, 1,
0, 0, 1
), nrow = 3, byrow = TRUE)
result <- micmac_analysis(reach)
# Driving power = row sums
expect_equal(result$driving_power[1], 3) # Node 1 reaches all
expect_equal(result$driving_power[2], 2) # Node 2 reaches 2,3
expect_equal(result$driving_power[3], 1) # Node 3 reaches only itself
# Dependence power = column sums
expect_equal(result$dependence_power[1], 1) # Only 1 reaches 1
expect_equal(result$dependence_power[2], 2) # 1,2 reach 2
expect_equal(result$dependence_power[3], 3) # All reach 3
})
test_that("micmac_analysis classifies clusters correctly", {
# Create a matrix with known cluster assignments
# High driving, low dependence = Independent (IV)
# Low driving, high dependence = Dependent (II)
reach <- matrix(c(
1, 1, 1, 1, # High driving (4)
0, 1, 0, 0, # Low driving (1)
0, 1, 1, 0, # Medium (2)
0, 1, 1, 1 # Medium (3)
), nrow = 4, byrow = TRUE)
result <- micmac_analysis(reach)
# Check that all four cluster types can exist
expect_true(any(grepl("Independent|Dependent|Linkage|Autonomous",
result$cluster)))
})
test_that("micmac_analysis preserves labels", {
adj <- matrix(c(0, 1, 0, 0), nrow = 2, byrow = TRUE)
rownames(adj) <- colnames(adj) <- c("A", "B")
reach <- compute_reachability(adj)
result <- micmac_analysis(reach)
expect_equal(result$label, c("A", "B"))
})
test_that("print.micmac_result works", {
adj <- matrix(c(0, 1, 0, 0), nrow = 2, byrow = TRUE)
reach <- compute_reachability(adj)
result <- micmac_analysis(reach)
expect_output(print(result), "MICMAC Analysis Results")
expect_output(print(result), "Cluster Distribution")
})
test_that("plot_micmac creates plot without error", {
adj <- matrix(c(
0, 1, 0, 0,
0, 0, 1, 1,
0, 0, 0, 0,
0, 0, 0, 0
), nrow = 4, byrow = TRUE)
reach <- compute_reachability(adj)
result <- micmac_analysis(reach)
# Should not error
expect_no_error({
pdf(NULL)
plot_micmac(result)
dev.off()
})
})
test_that("plot_micmac validates input", {
expect_error(plot_micmac(data.frame(a = 1)),
"must be a micmac_result object")
})
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.