File: test-dataframe.R

package info (click to toggle)
r-cran-rpf 1.0.14%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,484 kB
  • sloc: cpp: 5,364; sh: 114; ansic: 41; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 777 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
library(testthat)
library(rpf)

context("dataframe")

test_that("df basics", {
	df <- as.data.frame(matrix(sample.int(2, 5 * 100, replace=TRUE), 100, 5))
	cdf <- compressDataFrame(df)
	expect_true(nrow(cdf) < nrow(df))
	expect_equal(sum(cdf$freq), nrow(df))
	df2 <- expandDataFrame(cdf, "freq")
	expect_equal(nrow(df2), 100)
	expect_true(all(df2 == df[orderCompletely(df),]))
})

df <- as.data.frame(matrix(as.numeric(sample(2, 5 * 100, replace=TRUE)), 100, 5))
mask <- matrix(runif(5*100) < .1, ncol=5)
df[mask] <- NA
cdf <- compressDataFrame(df)
expect_equal(sum(cdf$freq), nrow(df))
df2 <- expandDataFrame(cdf, "freq")
expect_equal(nrow(df2), 100)
expect_true(all(df2 == df[orderCompletely(df),], na.rm=TRUE))
expect_true(all(is.na(df2) == is.na(df[orderCompletely(df),])))