From c4060516af7ab2129c23dee0356fa77068ac4e6a Mon Sep 17 00:00:00 2001 From: Konrad Siek Date: Mon, 22 Jun 2020 15:26:51 +0200 Subject: [PATCH] Bits and ends. --- ufovectors/DESCRIPTION | 4 ++-- ufovectors/src/ufo_csv.c | 6 +++++- ufovectors/src/ufo_vectors.c | 6 +++++- ufovectors/tests/testthat.R | 4 ++++ .../tests/testthat/test-file-backed-add-1.R | 18 ++++++++++++++++++ .../tests/testthat/test-file-backed-sum.R | 18 ++++++++++++++++++ 6 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 ufovectors/tests/testthat.R create mode 100644 ufovectors/tests/testthat/test-file-backed-add-1.R create mode 100644 ufovectors/tests/testthat/test-file-backed-sum.R diff --git a/ufovectors/DESCRIPTION b/ufovectors/DESCRIPTION index 40a3849..1cc4258 100644 --- a/ufovectors/DESCRIPTION +++ b/ufovectors/DESCRIPTION @@ -13,8 +13,8 @@ Maintainer: Konrad Siek License: GPL-2 | GPL-3 Encoding: UTF-8 LazyData: true -Depends: ufos -LinkingTo: ufos +Depends: ufos, viewports +LinkingTo: ufos, viewports NeedsCompilation: yes Suggests: knitr, diff --git a/ufovectors/src/ufo_csv.c b/ufovectors/src/ufo_csv.c index a297026..e9b09a7 100644 --- a/ufovectors/src/ufo_csv.c +++ b/ufovectors/src/ufo_csv.c @@ -7,6 +7,10 @@ #include #include +#define USE_RINTERNALS +#include +#include + #include "../include/ufos.h" #include "helpers.h" #include "debug.h" @@ -317,4 +321,4 @@ SEXP ufo_csv(SEXP/*STRSXP*/ path_sexp, SEXP/*INTSXP*/ min_load_count_sexp, SEXP/ UNPROTECT(1 + csv_metadata->columns + 2); return data_frame; -} \ No newline at end of file +} diff --git a/ufovectors/src/ufo_vectors.c b/ufovectors/src/ufo_vectors.c index a2c7878..f1f36f9 100644 --- a/ufovectors/src/ufo_vectors.c +++ b/ufovectors/src/ufo_vectors.c @@ -2,6 +2,10 @@ #include #include +#define USE_RINTERNALS +#include +#include + #include "../include/ufos.h" #include "ufo_vectors.h" #include "ufo_metadata.h" @@ -155,4 +159,4 @@ SEXP ufo_matrix_lglsxp_bin(SEXP/*STRSXP*/ path, SEXP/*INTSXP*/ rows, SEXP/*INTSX SEXP ufo_matrix_rawsxp_bin(SEXP/*STRSXP*/ path, SEXP/*INTSXP*/ rows, SEXP/*INTSXP*/ cols, SEXP/*INTSXP*/ min_load_count) { return __make_matrix(UFO_RAW, path, rows, cols, min_load_count); -} \ No newline at end of file +} diff --git a/ufovectors/tests/testthat.R b/ufovectors/tests/testthat.R new file mode 100644 index 0000000..d42458f --- /dev/null +++ b/ufovectors/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(ufovectors) + +test_check("ufovectors") diff --git a/ufovectors/tests/testthat/test-file-backed-add-1.R b/ufovectors/tests/testthat/test-file-backed-add-1.R new file mode 100644 index 0000000..9e58b0b --- /dev/null +++ b/ufovectors/tests/testthat/test-file-backed-add-1.R @@ -0,0 +1,18 @@ +context("Vector operations on file-backed integer vectors") + +dir <- "../../data" + +test_that("sum 1K ones", { + path <- paste(dir, "1K_ones_int.bin", sep="/") + expect_equal(sum(ufo_integer_bin(path) + 1), 2 * 1000) +}) + +test_that("sum 1M ones", { + path <- paste(dir, "1M_ones_int.bin", sep="/") + expect_equal(sum(ufo_integer_bin(path) + 1), 2 * 1000000) +}) + +test_that("sum 1G ones", { + path <- paste(dir, "1G_ones_int.bin", sep="/") + expect_equal(sum(ufo_integer_bin(path) + 1), 2 * 1000000000) +}) \ No newline at end of file diff --git a/ufovectors/tests/testthat/test-file-backed-sum.R b/ufovectors/tests/testthat/test-file-backed-sum.R new file mode 100644 index 0000000..3464d95 --- /dev/null +++ b/ufovectors/tests/testthat/test-file-backed-sum.R @@ -0,0 +1,18 @@ +context("Sum on file-backed integer vectors") + +dir <- "../../data" + +test_that("sum 1K ones", { + path <- paste(dir, "1K_ones_int.bin", sep="/") + expect_equal(sum(ufo_integer_bin(path)), 1000) +}) + +test_that("sum 1M ones", { + path <- paste(dir, "1M_ones_int.bin", sep="/") + expect_equal(sum(ufo_integer_bin(path)), 1000000) +}) + +test_that("sum 1G ones", { + path <- paste(dir, "1G_ones_int.bin", sep="/") + expect_equal(sum(ufo_integer_bin(path)), 1000000000) +}) \ No newline at end of file