File: test_toRangeStr.R

package info (click to toggle)
r-cran-bbmisc 1.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,256 kB
  • sloc: ansic: 176; sh: 9; makefile: 5
file content (31 lines) | stat: -rw-r--r-- 652 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
context("toRangeStr")

expect_range = function(x, str, ...) {
  expect_equal(toRangeStr(x, ...), str)
  expect_equal(toRangeStr(sample(x), ...), str)
  expect_equal(toRangeStr(sample(c(x, x)), ...), str)
  expect_equal(toRangeStr(sample(c(x, x)), ...), str)
}

test_that("continuous ranges", {
  x = c(1, 2, 3, 4, 5, 6)
  expect_range(x, "1 - 6")
  expect_range(x, "1_6", range.sep="_")
})

test_that("single number", {
  x = 1
  expect_range(x, "1")
})

test_that("negative numbers", {
  x = -2:4
  expect_range(x, "-2 - 4")
})

test_that("noncontinuous ranges", {
  x = c(-5, -4, -2, 0, 2, 3, 4, 7)
  expect_range(x, "-5 - -4, -2, 0, 2 - 4, 7")
})