tests/testthat/test_add_inventory.r

context("add_inventory")

test_that("Add inventory modifies state", {
    create_time <- lubridate::parse_date_time("2016-01-01", "ymd")
    tag_percent <- .05


    state <- inialize_state()
    state <- add_inventory(state, 1, 1, create_time, tag_percent)

    expect_equal(state[["movement"]]$datetime[1], create_time)

    state <- add_inventory(state, 1, 199, create_time, tag_percent)

    expect_equal(nrow(state[["population"]]), 200)
    expect_equal(nrow(state[["movement"]]), 200)

    state <- add_inventory(state, 2, 200, create_time, tag_percent)

    expect_equal(nrow(state[["population"]]), 400)
    expect_equal(nrow(state[["movement"]]), 400)

    expect_true(all(state[[c("movement", "clean")]]))

    pieces <- state[[c("population", "piece")]]
    expect_equal(length(pieces), length(unique(pieces)))
})
milumtextiles/itemsim documentation built on May 22, 2019, 11:54 p.m.