# write tests for that R function, in tests/testthat/test-LMLogisticLossIterations:
# (1) for valid inputs your function returns an output of the expected type/dimension
# (2) for an invalid input, your function stops with an informative error message.
library(codingProject2)
library(testthat)
context("test-LMLogisticLossIterations")
test_that("LMLogisticLossIterations computes the right demensions", {
data(spam, package = "ElemStatLearn")
X.mat<-spam[1:10,-58]
y.vec<-spam[1:10, 58]
penalty.vec <- c(0.05, 0.1, 0.2, 0.3, 0.4, 0.5)
res <- LMLogisticLossIterations(X.mat, y.vec, penalty.vec)
# n_features+1 x max.iterations
expect_equal(nrow(res), 2)
expect_equal(ncol(res), max.iterations)
})
test_that("LMLogisticLossIterations throws errors", {
data(spam, package = "ElemStatLearn")
X.mat<-spam[1:10,-58]
y.vec<-spam[1:10, 58]
penalty.vec <- c(0.05, 0.1, 0.2, 0.3, 0.4, 0.5)
expect_error(LMLogisticLossIterations(X.mat, y.vec, penalty.vec), "Add error")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.