Sha256: 99dc933ac684fbb512c7911f2d214947e1712eb28a3cc7edb4b860770cb13eb9

Contents?: true

Size: 1.33 KB

Versions: 53

Compression:

Stored size: 1.33 KB

Contents

source("./phone-number.R")
library(testthat)

context("phone number")

test_that("cleans the number", {
  expect_equal(parse_phone_number("(223) 456-7890"), "2234567890")
})

test_that("cleans numbers with dots", {
  expect_equal(parse_phone_number("223.456.7890"), "2234567890")
})

test_that("cleans numbers with multiple spaces", {
  expect_equal(parse_phone_number("223 456   7890   "), "2234567890")
})

test_that("invalid when 9 digits", {
  expect_equal(parse_phone_number("123456789"), NULL)
})

test_that("invalid when 11 digits and not starting with a 1", {
  expect_equal(parse_phone_number("22234567890"), NULL)
})

test_that("valid when 11 digits and starting with 1", {
  expect_equal(parse_phone_number("12234567890"), "2234567890")
})

test_that("invalid when more than 11 digits", {
  expect_equal(parse_phone_number("321234567890"), NULL)
})

test_that("invalid with letters", {
  expect_equal(parse_phone_number("123-abc-7890"), NULL)
})

test_that("invalid with punctuations", {
  expect_equal(parse_phone_number("123-@:!-7890"), NULL)
})

test_that("invalid if area code does not start with 2-9", {
  expect_equal(parse_phone_number("(123) 456-7890"), NULL)
})

test_that("invalid if exchange code does not start with 2-9", {
  expect_equal(parse_phone_number("(223) 056-7890"), NULL)
})

message("All tests passed for exercise: phone-number")

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.179 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.178 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.177 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.176 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.175 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.174 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.173 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.172 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.171 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.170 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.169 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.167 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.166 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.165 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.164 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.163 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.162 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.161 tracks/r/exercises/phone-number/test_phone-number.R
trackler-2.2.1.160 tracks/r/exercises/phone-number/test_phone-number.R