Fix package, ok for R CMD check - ongoing debug for main function
[epclust.git] / epclust / tests / testthat / test.de_serialize.R
index 27e6d59..a2fae5e 100644 (file)
@@ -1,17 +1,17 @@
 context("de_serialize")
 
-data_bin_file <<- "/tmp/epclust_test.bin"
-unlink(data_bin_file)
-
 test_that("serialization + getDataInFile retrieve original data / from matrix",
 {
+       data_bin_file = "/tmp/epclust_test_m.bin"
+       unlink(data_bin_file)
+
        #dataset 200 lignes / 30 columns
        data_ascii = matrix(runif(200*30,-10,10),ncol=30)
        nbytes = 4 #lead to a precision of 1e-7 / 1e-8
        endian = "little"
 
        #Simulate serialization in one single call
-       serialize(data_ascii, data_bin_file, 500, ",", nbytes, endian)
+       binarize(data_ascii, data_bin_file, 500, ",", nbytes, endian)
        expect_equal(file.info(data_bin_file)$size, length(data_ascii)*nbytes+8)
        for (indices in list(c(1,3,5), 3:13, c(5,20,50), c(75,130:135), 196:200))
        {
@@ -22,7 +22,7 @@ test_that("serialization + getDataInFile retrieve original data / from matrix",
 
        #...in several calls (last call complete, next call NULL)
        for (i in 1:20)
-               serialize(data_ascii[((i-1)*10+1):(i*10),], data_bin_file, 20, ",", nbytes, endian)
+               binarize(data_ascii[((i-1)*10+1):(i*10),], data_bin_file, 20, ",", nbytes, endian)
        expect_equal(file.info(data_bin_file)$size, length(data_ascii)*nbytes+8)
        for (indices in list(c(1,3,5), 3:13, c(5,20,50), c(75,130:135), 196:200))
        {
@@ -34,14 +34,17 @@ test_that("serialization + getDataInFile retrieve original data / from matrix",
 
 test_that("serialization + getDataInFile retrieve original data / from connection",
 {
+       data_bin_file = "/tmp/epclust_test_c.bin"
+       unlink(data_bin_file)
+
        #dataset 300 lignes / 50 columns
        data_csv = system.file("testdata","de_serialize.csv",package="epclust")
        nbytes = 8
        endian = "big"
-       data_ascii = as.matrix(read.csv(test_series, sep=";", header=FALSE)) #for ref
+       data_ascii = as.matrix(read.csv(data_csv, sep=";", header=FALSE)) #for ref
 
        #Simulate serialization in one single call
-       serialize(data_csv, data_bin_file, 350, ";", nbytes, endian)
+       binarize(data_csv, data_bin_file, 350, ";", nbytes, endian)
        expect_equal(file.info(data_bin_file)$size, 300*50*8+8)
        for (indices in list(c(1,3,5), 3:13, c(5,20,50), c(75,130:135), 196:200))
        {
@@ -53,7 +56,7 @@ test_that("serialization + getDataInFile retrieve original data / from connectio
 
        #...in several calls / chunks of 29 --> 29*10 + 10, incomplete last
        data_con = file(data_csv, "r")
-       serialize(data_con, data_bin_file, 29, ";", nbytes, endian)
+       binarize(data_con, data_bin_file, 29, ";", nbytes, endian)
        expect_equal(file.info(data_bin_file)$size, 300*50*8+8)
        for (indices in list(c(1,3,5), 3:13, c(5,20,50), c(75,130:135), 196:200))
        {
@@ -61,5 +64,5 @@ test_that("serialization + getDataInFile retrieve original data / from connectio
                expect_equal(data_lines, data_ascii[indices,])
        }
        unlink(data_bin_file)
-       #close(data_con) --> done in serialize()
+       #close(data_con) --> done in binarize()
 })