Sha256: 9f5917d6383cade23391c9bfdb51368dbf05619fbdeeb4c0e526ce76fe812e1a

Contents?: true

Size: 1.48 KB

Versions: 119

Compression:

Stored size: 1.48 KB

Contents

source("./nucleotide-count.R")
library(testthat)

# When comparing lists, all.equal expects the objects to be in the same order
# This expectation instead checks that a) the set of names are the same and
# b) each named object is equal
expect_equal_pairs <- function(object, expected) {
  expect_equal(sort(names(object)),
               sort(names(expected)),
               info = "names in lists differ")
  for (name in names(expected)) {
    expect_equal(object[name], expected[name], info = "list element missing")
  }
}

test_that("all zeros for empty strand", {
  expect_equal_pairs(nucleotide_count(""),
                     list(
                       A = 0,
                       C = 0,
                       G = 0,
                       T = 0
                     ))
})

test_that("3 zeros & 1 count for strand with a single repeated nucleotide", {
  expect_equal_pairs(nucleotide_count("GGGGGGG"),
                     list(
                       A = 0,
                       C = 0,
                       G = 7,
                       T = 0
                     ))
})

test_that("correct counts for strand with multiple nucleotides", {
  expect_equal_pairs(nucleotide_count(
    "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"),
    list(
      A = 20,
      C = 12,
      G = 17,
      T = 21
    ))
})

test_that("error for strand with invalid nucleotides", {
  expect_error(nucleotide_count("AGXXACT"))
})

message("All tests passed for exercise: nucleotide-count")

Version data entries

119 entries across 119 versions & 1 rubygems

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