context("Tests stack")
test_that("Is empty", {
stack<-new.env()
testthat::expect_true(stack.is_empty(stack))
testthat::expect_equal(stack.length(stack),0)
rm(stack)
})
test_that("Is non-empty", {
stack<-new.env()
stack.push(stack, 1)
testthat::expect_equal(stack.length(stack),1)
testthat::expect_false(stack.is_empty(stack))
rm(stack)
})
test_that("push & pop", {
stack<-new.env()
stack.push(stack, 1)
testthat::expect_equal(stack.top(stack), 1)
testthat::expect_false(stack.is_empty(stack))
testthat::expect_equal(stack.pop(stack), 1)
testthat::expect_true(stack.is_empty(stack))
rm(stack)
})
test_that("push & pop & push & pop", {
stack<-new.env()
stack.push(stack, 1)
stack.pop(stack)
stack.push(stack, 2)
testthat::expect_equal(stack.pop(stack), 2)
testthat::expect_true(stack.is_empty(stack))
rm(stack)
})
test_that("push & push & pop & pop", {
stack<-new.env()
rectpartitions:::stack.push(stack, 1)
rectpartitions:::stack.push(stack, 2)
testthat::expect_equal(rectpartitions:::stack.length(stack),2)
stack.pop(stack)
testthat::expect_equal(stack.length(stack),1)
testthat::expect_false(stack.is_empty(stack))
testthat::expect_equal(stack.pop(stack), 1)
testthat::expect_true(stack.is_empty(stack))
testthat::expect_equal(stack.length(stack),0)
rm(stack)
})
test_that("push & push & push & pop & push & pop & pop & pop ", {
stack<-new.env()
rectpartitions:::stack.push(stack, 1)
rectpartitions:::stack.push(stack, 2)
rectpartitions:::stack.push(stack, 3)
testthat::expect_equal(rectpartitions:::stack.length(stack),3)
testthat::expect_equal(rectpartitions:::stack.top(stack), 3)
rectpartitions:::stack.pop(stack)
testthat::expect_equal(rectpartitions:::stack.top(stack), 2)
rectpartitions:::stack.push(stack, 4)
l<-unlist(rectpartitions:::stack.to_list(stack))
testthat::expect_equal(l, c(4,2,1))
testthat::expect_equal(stack.length(stack),3)
testthat::expect_equal(stack.top(stack), 4)
stack.pop(stack)
stack.pop(stack)
stack.pop(stack)
testthat::expect_true(stack.is_empty(stack))
rm(stack)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.