File: test_create.R

package info (click to toggle)
r-cran-bigmemory 4.6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 648 kB
  • sloc: cpp: 4,930; ansic: 131; sh: 13; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,676 bytes parent folder | download | duplicates (2)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
context("big.matrix creation")

z <- filebacked.big.matrix(3, 3, type='integer', init=123,
                           backingfile="example.bin",
                           descriptorfile="example.desc",
                           dimnames=list(c('a','b','c'), c('d', 'e', 'f')))

mat <- matrix(1:9, ncol = 3, nrow = 3, dimnames = list(letters[1:3],
                                                       LETTERS[1:3]))

bm <- as.big.matrix(mat)


test_that("filebacked matrix created successfully",{
    expect_true(file.exists("example.bin"))
    expect_true(file.exists("example.desc"))
    expect_true(all(z[,] == 123))
})

test_that("describe returns correct data", {
    desc <- describe(bm)
    expect_is(desc, "big.matrix.descriptor")
    expect_true(length(desc@description$rowOffset) == 2)
    expect_true(length(desc@description$colOffset) == 2)
    expect_true(typeof(bm) == desc@description$type)
})

test_that("attach methods successful",{
    zdescription <- describe(z)
    bmdescription <- describe(bm)
    expect_is(zdescription, "big.matrix.descriptor")
    expect_is(bmdescription, "big.matrix.descriptor")

    y <- attach.big.matrix(zdescription)
    expect_false(identical(z@address, y@address))
    expect_identical(z[,], y[,])

    x <- attach.big.matrix(bmdescription)
    expect_false(identical(z@address, y@address))
    expect_identical(bm[,], x[,])
})

test_that("We can prepare for writing a bigmatrix", {
    expect_warning(bigmemory:::to_int_checked(1.1))
    expect_silent(bigmemory:::to_int_checked(1.0))
    expect_equal(bigmemory:::to_int_checked(c(1.0,3.0)), c(1L,3L))
})

rm(z)
gc()
file.remove('example.bin')
file.remove('example.desc')