Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Type: Package
Title: A Simple and Flexible Switch-Case Construct for the 'R' Language
Version: 0.1.1
Authors@R: person("Joachim", "Zuckarelli", role = c("aut", "cre"), email = "joachim@zuckarelli.de", comment = c(ORCID = "0000-0002-9280-3016"))
Author: Joachim Zuckarelli [aut, cre]
Maintainer: Joachim Zuckarelli <joachim@zuckarelli.de>
Description: Provides a switch-case construct for 'R', as it is known from other programming languages. It allows to test multiple, similar conditions in an efficient, easy-to-read manner, so nested if-else constructs can be avoided. The switch-case construct is designed as an 'R' function that allows to return values depending on which condition is met and lets the programmer flexibly decide whether or not to leave the switch-case construct after a case block has been executed.
License: GPL-3
Expand All @@ -11,3 +12,4 @@ URL: https://github.com/jsugarelli/switchcase/, https://youtu.be/3ybF8u_PE7w
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.0
Suggests: testthat
1 change: 1 addition & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
testthat::test_check("switchcase")
25 changes: 25 additions & 0 deletions tests/testthat/test-switchcase.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
library(testthat)
library(switchcase)

test_that("numeric comparison works", {
res <- switchCase(5,
alt(..expr < 5, NULL, "less"),
alt(..expr == 5, NULL, "equal"),
alt(..expr > 5, NULL, "greater"))
expect_equal(res, "equal")
})

test_that("character comparison works", {
res <- switchCase("b",
alt(..expr == "a", NULL, "A"),
alt(..expr == "b", NULL, "B"))
expect_equal(res, "B")
})

test_that("default case works", {
res <- switchCase(3,
alt(..expr == 1, NULL, "one"),
alt(..expr == 2, NULL, "two"),
alt(NULL, NULL, "default"))
expect_equal(res, "default")
})