Sha256: f52f300d994b0c1121af929df065c7f8384eaf41d107e350fd9faf3809afb576

Contents?: true

Size: 1.65 KB

Versions: 105

Compression:

Stored size: 1.65 KB

Contents

source("./perfect-numbers.R")
library(testthat)

test_that("Smallest perfect number is classified correctly", {
  n <- 6
  expect_equal(number_type(n), "perfect")
})

test_that("Medium perfect number is classified correctly", {
  n <- 28
  expect_equal(number_type(n), "perfect")
})

test_that("Large perfect number is classified correctly", {
  n <- 33550336
  expect_equal(number_type(n), "perfect")
})



test_that("Smallest abundant number is classified correctly", {
  n <- 12
  expect_equal(number_type(n), "abundant")
})

test_that("Medium abundant number is classified correctly", {
  n <- 30
  expect_equal(number_type(n), "abundant")
})

test_that("Large abundant number is classified correctly", {
  n <- 33550335
  expect_equal(number_type(n), "abundant")
})



test_that("Smallest prime deficient number is classified correctly", {
  n <- 2
  expect_equal(number_type(n), "deficient")
})

test_that("Smallest non-prime deficient number is classified correctly", {
  n <- 4
  expect_equal(number_type(n), "deficient")
})

test_that("Medium deficient number is classified correctly", {
  n <- 32
  expect_equal(number_type(n), "deficient")
})

test_that("Large deficient number is classified correctly", {
  n <- 33550337
  expect_equal(number_type(n), "deficient")
})

test_that("Edge case (no factors other than itself) is classified correctly", {
  n <- 1
  expect_equal(number_type(n), "deficient")
})



test_that("Zero is rejected (not a natural number)", {
  n <- 0
  expect_error(number_type(n))
})

test_that("Negative integer is rejected (not a natural number)", {
  n <- -1
  expect_error(number_type(n))
})


message("All tests passed for exercise: perfect-numbers")

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
trackler-2.2.1.126 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.125 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.124 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.123 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.122 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.121 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.120 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.119 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.118 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.117 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.116 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.115 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.114 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.113 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.111 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.110 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.109 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.108 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.107 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R
trackler-2.2.1.106 tracks/r/exercises/perfect-numbers/test_perfect-numbers.R