tests/testthat/test-day24.R

context("test-day24.R")

test_that("finding bridges", {
  pieces <- c("0/2", "2/2", "2/3",  "3/4", "3/5",  "0/1", "10/1", "9/10")

  possible_bridges <- c("0/1--10/1--9/10", "0/2--2/3--3/4", "0/2--2/3--3/5",
                        "0/2--2/2--2/3--3/4", "0/2--2/2--2/3--3/5")

  bridges <- connect_free_pieces("", 0, pieces)

  expect_equal(sort(bridges), sort(possible_bridges))

  bridges %>%
    find_strongest_bridge() %>%
    expect_equal("0/1--10/1--9/10") %>%
    compute_bridge_strength() %>%
    expect_equal(31)

  bridges %>%
    find_longest_bridge() %>%
    expect_equal(c("0/2--2/2--2/3--3/4", "0/2--2/2--2/3--3/5")) %>%
    find_strongest_bridge() %>%
    expect_equal("0/2--2/2--2/3--3/5") %>%
    compute_bridge_strength() %>%
    expect_equal(19)
})
tjmahr/adventofcode17 documentation built on May 30, 2019, 2:29 p.m.