context("linreg")
data("iris")
test_that("lenreg rejects errounous input", {
expect_error(linreg(Petal.Length~Sepdsal.Width+Sepal.Length, data=iris))
expect_error(linreg(Petal.Length~Sepdsal.Width+Sepal.Length, data=irfsfdis))
})
test_that("class is correct", {
linreg_mod <- linreg(Petal.Length~Sepal.Width+Sepal.Length, data=iris)
expect_s3_class(linreg_mod,"linreg")
})
test_that("print() works", {
linreg_mod <- linreg(Petal.Length~Sepal.Width+Sepal.Length, data=iris)
expect_output(print(linreg_mod),"linreg\\(formula = Petal\\.Length ~ Sepal\\.Width \\+ Sepal\\.Length, data = iris\\)")
expect_output(print(linreg_mod),"( )*\\(Intercept\\)( )*Sepal\\.Width( )*Sepal\\.Length")
})
test_that("pred() works", {
linreg_mod <- linreg(Petal.Length~Sepal.Width+Sepal.Length, data=iris)
expect_equal(round(unname(pred(linreg_mod)[c(1,5,7)]),2), c(1.85, 1.53, 1.09))
})
test_that("resid() works", {
linreg_mod <- linreg(Petal.Length~Sepal.Width+Sepal.Length, data=iris)
expect_equal(round(unname(resid(linreg_mod)[c(7,13,27)]),2), c(0.31, -0.58, -0.20))
})
test_that("coef() works", {
linreg_mod <- linreg(Petal.Length~Sepal.Width+Sepal.Length, data=iris)
expect_true(all(round(unname(coef(linreg_mod)),2) %in% c(-2.52, -1.34, 1.78)))
})
test_that("summary() works", {
linreg_mod <- linreg(Petal.Length~Sepal.Width+Sepal.Length, data=iris)
expect_output(summary(linreg_mod), "Coefficients:\\n.*Estimate.*Std\\. Error.*t value.*Pr\\(>\\|t\\|\\).*\\(Intercept\\).*-2\\.525.*0\\.563.*-4\\.481.*0.*Sepal\\.Width.*-1\\.339.*0\\.122.*-10\\.940.*0\\nSepal\\.Length.*1\\.776.*0\\.064.*27\\.569.*0.*Residual standard error: 0\\.642 on 147 degrees of freedom")
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.