#library(testthat)
context("rbolaget")
data <- rget()
test_that("rget works", {
# All columns included
expect_identical(colnames(data), c("ProductNameBold", "ProductNumber", "ProductNumberShort",
"Category", "SubCategory", "Type", "Style", "Price", "AlcoholPercentage",
"Volume", "BottleTextShort", "RecycleFee", "Country", "ProducerName",
"IsKosher", "IsOrganic", "IsEthical", "SellStartDate", "Taste", "Usage", "APK"))
# Super-key test
expect_equal(nrow(data), length(unique(data$ProductNumber)))
# Data frame
expect_true(is.data.frame(data))
# Return correct classes
expect_true(all(class(data) == c("rbolaget", "data.frame")))
# Faulty API option
expect_error(rget(API = "hej"))
expect_identical(vapply(unname(data), typeof, character(1)),
c("character", "character", "character", "character", "character",
"character", "character", "double", "double", "double",
"character", "double", "character", "character", "logical",
"logical", "logical", "double", "character", "character", "double"))
})
test_that("rsort works", {
# Category works
expect_true(all(rsort(data, Category = "Öl")$Category %in% "Öl"))
# Sort by min value
expect_true(all(rsort(data, AlcoholPercentage = list(min = 5))$AlcoholPercentage >= 5))
# Sort by min and max value
expect_true(all(range(rsort(data, Price = list(min = 15, max = 25))$Price) == c(15, 25)))
# Stop and error message
expect_error(rsort(data[,-1]))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.