tests/testthat/test-day-04.R

# Load external packages
pckgs <- c("here", "tidyverse", "magrittr")
adventofcode2017::ipak(pckgs)

# Data directory
DATA_DIR <- file.path(here::here(), "tests/testthat/data")

context("test-day-04-solution.R")

#-------------------------------------------------------------------------------
# Day 04-01
#-------------------------------------------------------------------------------

inp_test_day_04_01 <- file.path(DATA_DIR, "test-day-04-01.txt")

test_that("Unit Tests Day 04 - Part 01", {
    check_val <- inp_test_day_04_01 %>%
                    adventofcode2017::parse_txtfile(txt_file = .
                                                    , sep = " "
                                                    , map_fun =
                                                        as.character) %>%
                    purrr::map(adventofcode2017::check_isunique) %>%
                    base::unlist() %>%
                    base::sum()

    testthat::expect_equal(check_val, 2)
})

#-------------------------------------------------------------------------------
# Day 04-02
#-------------------------------------------------------------------------------

inp_test_day_04_02 <- file.path(DATA_DIR, "test-day-04-02.txt")

test_that("Unit Tests Day 04 - Part 02", {
    check_val <- inp_test_day_04_02 %>%
                    adventofcode2017::parse_txtfile(txt_file = .
                                                    , sep = " "
                                                    , map_fun =
                                                        as.character) %>%
                    purrr::map(.x = .
                               , .f = adventofcode2017::sort_ind_str) %>%
                    purrr::map(adventofcode2017::check_isunique) %>%
                    unlist() %>%
                    sum()

    testthat::expect_equal(check_val, 1)
})
shamindras/adventofcode2017 documentation built on May 14, 2019, 7:37 a.m.