Skip to content

Commit

Permalink
Add regression test for coloring order (numeric cols)
Browse files Browse the repository at this point in the history
  • Loading branch information
barrettk committed Oct 4, 2024
1 parent 6d11e25 commit af33e7b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/testthat/test-model-tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ withr::with_options(list(bbr.bbi_exe_path = read_bbi_path()), {
c("#007319", rep("#EB003D", 4), "#C0C0C0")
)

# Test numeric/character color_by (gradient coloring)
# Test character color_by (gradient coloring)
tree_data <- make_tree_data(run_log(MODEL_DIR), add_summary = FALSE)
tree_data_run <- color_tree_by(tree_data, color_by = "run")
expect_equal(
Expand All @@ -370,6 +370,18 @@ withr::with_options(list(bbr.bbi_exe_path = read_bbi_path()), {
# Note: all gradient colors will shift if number of models change
c("#007319", "#FFFFFF", "#F4DBD3", "#ED9D84", "#E35B44", "#EB003D")
)

# Regression test: numeric color_by is sorted appropriately
log_df <- run_log(MODEL_DIR)
log_df$numeric_vals <- c(1534, 3892, 731, 2653, 3574)
pl_tree <- model_tree(
log_df, add_summary = FALSE, color_by = "numeric_vals",
include_info = "numeric_vals"
)
node_colors <- get_node_attribute(pl_tree$x$data$children, attr = "fill")
expected_colors <- c("#F4DBD3", "#EB003D", "#FFFFFF", "#ED9D84", "#E35B44")
# Can inspect with `scales::show_col(node_colors)`
expect_equal(node_colors, expected_colors)
})

it("size_tree_by()", {
Expand Down

0 comments on commit af33e7b

Please sign in to comment.