Sha256: 42038552e3e940d4c8b6dc43a3dde51bde2e1f51fc498972c7a63072d8be0eb5

Contents?: true

Size: 1.61 KB

Versions: 53

Compression:

Stored size: 1.61 KB

Contents

source("./luhn.R")
library(testthat)

context("luhn")

test_that("single digit strings can not be valid", {
  input <- "1"
  expect_equal(is_valid(input), FALSE)
})

test_that("A single zero is invalid", {
  input <- "0"
  expect_equal(is_valid(input), FALSE)
})

test_that("a simple valid SIN that remains valid if reversed", {
  input <- "059"
  expect_equal(is_valid(input), TRUE)
})

test_that("a simple valid SIN that becomes invalid if reversed", {
  input <- "59"
  expect_equal(is_valid(input), TRUE)
})

test_that("valid Canadian SIN", {
  input <- "046 454 286"
  expect_equal(is_valid(input), TRUE)
})

test_that("invalid Canadian SIN", {
  input <- "046 454 287"
  expect_equal(is_valid(input), FALSE)
})

test_that("invalid credit card", {
  input <- "8273 1232 7352 0569"
  expect_equal(is_valid(input), FALSE)
})

test_that("valid strings with a non-digit added become invalid", {
  input <- "055a 444 285"
  expect_equal(is_valid(input), FALSE)
})

test_that("punctuation is not allowed", {
  input <- "055-444-285"
  expect_equal(is_valid(input), FALSE)
})

test_that("symbols are not allowed", {
  input <- "055£ 444$ 285"
  expect_equal(is_valid(input), FALSE)
})

test_that("single zero with space is invalid", {
  input <- " 0"
  expect_equal(is_valid(input), FALSE)
})

test_that("more than a single zero is valid", {
  input <- "0000 0"
  expect_equal(is_valid(input), TRUE)
})

test_that("another valid sin", {
  input <- "055 444 285"
  expect_equal(is_valid(input), TRUE)
})

test_that("nine doubled is nine", {
  input <- "091"
  expect_equal(is_valid(input), TRUE)
})

message("All tests passed for exercise: luhn")

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.158 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.157 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.156 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.155 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.154 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.153 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.152 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.151 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.150 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.149 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.148 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.147 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.146 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.145 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.144 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.143 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.142 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.141 tracks/r/exercises/luhn/test_luhn.R
trackler-2.2.1.140 tracks/r/exercises/luhn/test_luhn.R