File: test_Data.R

package info (click to toggle)
r-cran-rsdmx 0.5.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 940 kB
  • sloc: makefile: 2
file content (54 lines) | stat: -rw-r--r-- 2,263 bytes parent folder | download
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
53
54
# test_Data.R
# Author: Emmanuel Blondel <emmanuel.blondel1@gmail.com>
#
# Description: Unit tests for SDMX Data methods
#=======================
require(rsdmx, quietly = TRUE)
require(testthat)
context("SDMXData")

test_that("DSD is properly associated to an SDMXData object",{
  data <- readSDMX(providerId = "UIS", resource = "data",
                        flowRef = "EDULIT_DS", key = list("OFST_1_CP", NULL),
                        start = "2000", end = "2015")
  dsd <- readSDMX(providerId = "UIS", resource = "datastructure",
                       resourceId = "EDULIT_DS")
  
  expect_equal(slot(data,"dsdRef"), "EDULIT_DS")
  expect_true(is.null(slot(data,"dsd")))
  
  data <- setDSD(data, dsd)
  expect_false(is.null(slot(data,"dsd")))
  expect_is(slot(data,"dsd"), "SDMXDataStructureDefinition")
  
})

test_that("DSD is properly fetched by readSDMX and associated to the dataset",{
  data <- readSDMX(providerId = "UIS", resource = "data",
                        flowRef = "EDULIT_DS", key = list("OFST_1_CP", NULL),
                        start = "2000", end = "2015",
                        dsd = TRUE)
  expect_false(is.null(slot(data,"dsd")))
  expect_is(slot(data,"dsd"), "SDMXDataStructureDefinition")
})

test_that("DSD is properly fetched by readSDMX when there is no dsdRef (using flowRef)",{
  data <- readSDMX(providerId = "KNOEMA", resource = "data",
                   flowRef = "SADG2015", dsd = TRUE)
  expect_false(is.null(slot(data,"dsd")))
  expect_is(slot(data,"dsd"), "SDMXDataStructureDefinition")
})

test_that("Dataset is correctly enriched with labels using the DSD",{
  sdmx.data <- readSDMX(providerId = "UIS", resource = "data",
                        flowRef = "CAI_DS", dsd = TRUE)
  data <- as.data.frame(sdmx.data)
  data.enriched <- as.data.frame(sdmx.data, labels = TRUE)
  expect_true(ncol(data.enriched) > ncol(data))
  expect_true(all(data["CAI_IND"] == data.enriched["CAI_IND"]))
  expect_true(all(data["LOCATION"] == data.enriched["LOCATION"]))
  expect_true(all(data["TIME_FORMAT"] == data.enriched["TIME_FORMAT"]))
  expect_true(all(data["obsTime"] == data.enriched["obsTime"]))
  expect_true(all(data["obsValue"] == data.enriched["obsValue"]))

})