Sha256: d385f4767a98f6aaafb01f2a0fa01e512475b903332bb7d52943dcb49da2902f

Contents?: true

Size: 1.41 KB

Versions: 38

Compression:

Stored size: 1.41 KB

Contents

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

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("simple valid sin", {
  input <- " 5 9 "
  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 <- "046a 454 286"
  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("lots of zeros are valid", {
  input <- " 00000"
  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)
})

print("All tests passed!")

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
trackler-2.1.0.19 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.18 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.17 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.16 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.15 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.14 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.13 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.12 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.11 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.10 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.9 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.8 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.7 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.6 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.5 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.4 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.3 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.2 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.1 tracks/r/exercises/luhn/test_luhn.R
trackler-2.1.0.0 tracks/r/exercises/luhn/test_luhn.R