Skip to content

Commit

Permalink
✅carefully reintroduce tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pierucci committed Nov 7, 2016
1 parent 97526ce commit 894a8d2
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 18 deletions.
4 changes: 4 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library(testthat)
library(rgho)

test_check("rgho")
102 changes: 102 additions & 0 deletions tests/testthat/test-build_gho.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
context("build_gho")

test_that("normal inputs work", {
no_attr <- rgho:::build_gho(
x = LETTERS[1:5],
labels = letters[1:5]
)

expect_identical(
no_attr,
structure(
c("A", "B", "C", "D", "E"),
labels = c("a", "b", "c", "d", "e"),
class = "gho"
)
)

a <- tibble::tibble(
x = rev(letters[1:5]),
y = rev(letters[1:5])
)
with_attr <- rgho:::build_gho(
x = LETTERS[1:5],
labels = letters[1:5],
attrs = a
)

expect_identical(
with_attr,
structure(
c("A", "B", "C", "D", "E"),
labels = c("a", "b", "c", "d", "e"),
attrs = structure(list(
x = c("e", "d", "c", "b", "a"),
y = c("e", "d", "c", "b", "a")),
.Names = c("x", "y"),
class = c("tbl_df", "tbl", "data.frame"),
row.names = c(NA, -5L)), class = "gho")
)

expect_identical(
no_attr,
rgho:::build_gho(
x = setNames(LETTERS[1:5], LETTERS[1:5]),
labels = setNames(letters[1:5], letters[1:5])
)
)
})

test_that("wrong input fails", {
expect_error(
rgho:::build_gho(
x = matrix(1:4, nrow = 2),
labels = LETTERS[1:4]
)
)
expect_error(
rgho:::build_gho(
x = LETTERS[1:4],
labels = matrix(1:4, nrow = 2)
)
)
expect_error(
rgho:::build_gho(
x = LETTERS[1:4],
labels = letters[1:5]
)
)
expect_error(
rgho:::build_gho(
x = 1:5,
labels = letters[1:5]
)
)
expect_error(
rgho:::build_gho(
x = LETTERS[1:5],
labels =
1:5
)
)
expect_error(
rgho:::build_gho(
x = LETTERS[1:5],
labels = letters[1:5],
attrs = 1:5
)
)
b <- tibble::tibble(
x = 1:4
)
expect_error(
rgho:::build_gho(
x = LETTERS[1:5],
labels = letters[1:5],
attrs = b
)
)
expect_error(
rgho:::get_gho(url = "http://google.com/doesntexist", retry = 0)
)
})
100 changes: 100 additions & 0 deletions tests/testthat/test-build_url.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
context("build_url")

test_that("normal inputs works", {
expect_identical(
rgho:::build_gho_url(),
"http://apps.who.int/gho/athena/api/GHO"
)
expect_identical(
rgho:::build_gho_url(dimension = "COUNTRY"),
"http://apps.who.int/gho/athena/api/COUNTRY"
)
expect_identical(
rgho:::build_gho_url(dimension = NULL),
"http://apps.who.int/gho/athena/api/"
)
expect_identical(
rgho:::build_gho_url(base_url = "http://google.com"),
"http://google.com/GHO"
)
expect_identical(
rgho:::build_gho_url(code = "xxx"),
"http://apps.who.int/gho/athena/api/GHO/xxx"
)
expect_identical(
rgho:::build_gho_url(dimension = "COUNTRY", code = "yyy"),
"http://apps.who.int/gho/athena/api/COUNTRY/yyy"
)
expect_identical(
rgho:::build_gho_url(dimension = "COUNTRY", code = "yyy",
filter = list(a = 1, b = 2)),
"http://apps.who.int/gho/athena/api/COUNTRY/yyy?filter=a%3A1%3Bb%3A2"
)
expect_identical(
rgho:::build_gho_url(dimension = NULL, x=1, y=2),
"http://apps.who.int/gho/athena/api/?x=1&y=2"
)
expect_identical(
rgho:::build_gho_url(dimension = "COUNTRY", x=1, y=2),
"http://apps.who.int/gho/athena/api/COUNTRY?x=1&y=2"
)
expect_identical(
rgho:::build_gho_url(dimension = "COUNTRY", code = "xxx",
x=1, y=2),
"http://apps.who.int/gho/athena/api/COUNTRY/xxx?x=1&y=2"
)
expect_identical(
rgho:::build_gho_url(dimension = "COUNTRY", code = "yyy",
filter = list(a = 1, b = 2),
x=1, y=2),
"http://apps.who.int/gho/athena/api/COUNTRY/yyy?filter=a%3A1%3Bb%3A2&x=1&y=2"
)
})

test_that("wrong input fails", {
expect_error(
rgho:::build_gho_url(dimension = 1:2)
)
expect_error(
rgho:::build_gho_url(dimension = NULL, code = "xxx")
)
expect_error(
rgho:::build_gho_url(code = NULL, filter = list(a = 1))
)
expect_error(
rgho:::build_gho_url(code = "xxx", filter = list(1))
)
expect_error(
rgho:::build_gho_url(code = "xxx", filter = c(a = 1))
)
expect_error(
rgho:::build_gho_url(code = "xxx", filter = list(a = 1:2))
)
expect_error(
rgho:::build_gho_url(code = "xxx", filter = list())
)
expect_error(
rgho:::build_gho_url(
base_url = "http://google.com",
dimension = "GHO",
code = "xxx", filter = list(a = 1),
2, 3
)
)
expect_error(
rgho:::build_gho_url(
base_url = "http://google.com",
dimension = "GHO",
code = "xxx", filter = list(a = 1),
x = 2, y = 3:4
)
)
expect_error(
rgho:::build_gho_url(
base_url = "http://google.com",
dimension = "GHO",
code = "xxx", filter = list(a = 1),
x = 2, y = NULL
)
)
})
18 changes: 0 additions & 18 deletions tests/testthat/test-verbose.R

This file was deleted.

0 comments on commit 894a8d2

Please sign in to comment.