context("Testing `distinct_countries()`")
pkg_data <-
system.file("extdata", "virtual-pollinators-flow.qs", package = "vbpflow")
df <-
qread(pkg_data)
# xpectr::gxs_selection("distinct_countries(df)")
## Testing 'distinct_countries(df)' ####
## Initially generated by xpectr
xpectr::set_test_seed(42)
# Assigning output
output_19148 <- distinct_countries(df)
# Testing class
expect_equal(
class(output_19148),
c("tbl_df", "tbl", "data.frame"),
fixed = TRUE
)
# Testing column values
expect_equal(
xpectr::smpl(output_19148[["reporter_countries"]], n = 30),
c(
"United Kingdom", "Spain", "Pakistan", "Argentina", "Ukraine",
"Costa Rica", "India", "Thailand", "Burkina Faso", "Peru", "Uganda",
"Romania", "Luxembourg", "Indonesia", "Denmark", "Morocco",
"Thailand", "Armenia", "Madagascar", "France", "Ukraine", "Yemen",
"Australia", "France", "Brazil", "Russia", "New Zealand", "New Zealand",
"Bulgaria", "France"
),
fixed = TRUE
)
expect_equal(
xpectr::smpl(output_19148[["partner_countries"]], n = 30),
c(
"Romania", "Albania", "Belarus", "Kyrgyzstan", "Seychelles", "Argentina",
"Djibouti", "Poland", "Syria", "Czech Republic", "Eritrea",
"Finland", "Netherlands", "Senegal", "Philippines", "Lithuania",
"Japan", "Georgia", "India", "United Arab Emirates", "Estonia",
"Saudi Arabia", "Malaysia", "Saudi Arabia", "Slovakia", "Italy",
"Hong Kong S.A.R.", "Italy", "Turkey", "United Kingdom"
),
fixed = TRUE
)
expect_equal(
xpectr::smpl(output_19148[["reporter_long"]], n = 30),
c(
-2.86563, -3.64755, 69.33958, -65.17981, 31.38326, -84.19209,
79.61198, 101.00288, -1.75457, -74.38243, 32.36908, 24.97293,
6.07182, 117.24011, 10.02801, -8.45616, 101.00288, 44.92993,
46.70474, -2.76173, 31.38326, 47.58676, 134.491, -2.76173, -53.09783,
96.68656, 171.48492, 171.48492, 25.21553, -2.76173
),
tolerance = 1e-4
)
expect_equal(
xpectr::smpl(output_19148[["reporter_lat"]], n = 30),
c(
54.12387, 40.24449, 29.94975, -35.38135, 48.99657, 9.97634, 22.88578,
15.11816, 12.26954, -9.1528, 1.27469, 45.85243, 49.76725, -2.21505,
55.98125, 29.83763, 15.11816, 40.28953, -19.3719, 42.17344,
48.99657, 15.90928, -25.73289, 42.17344, -10.78778, 61.98052,
-41.81114, -41.81114, 42.7689, 42.17344
),
tolerance = 1e-4
)
expect_equal(
xpectr::smpl(output_19148[["reporter_hdi"]], n = 30),
c(
0.89533, 0.85567, 0.511, 0.7978, 0.72333, 0.74753, 0.5626, 0.70667,
0.35313, 0.7118, 0.4632, 0.77413, 0.8826, 0.65033, 0.90793,
0.60167, 0.70667, 0.7112, 0.49093, 0.87527, 0.72333, 0.48307,
0.91773, 0.87527, 0.71827, 0.7706, 0.89507, 0.89507, 0.76613,
0.87527
),
tolerance = 1e-4
)
expect_equal(
xpectr::smpl(output_19148[["partner_long"]], n = 30),
c(
24.97293, 20.04983, 28.03209, 74.54166, 55.47603, -65.17981, 42.56068,
19.39013, 38.50788, 15.3124, 38.84617, 26.27467, 5.28145, -14.47349,
122.88393, 23.88719, 138.0309, 43.5078, 79.61198, 54.30017,
25.54249, 44.53686, 109.69762, 44.53686, 19.47905, 12.07001,
114.1138, 12.07001, 35.16895, -2.86563
),
tolerance = 1e-4
)
expect_equal(
xpectr::smpl(output_19148[["partner_lat"]], n = 30),
c(
45.85243, 41.14245, 53.53131, 41.46222, -4.66099, -35.38135, 11.74872,
52.1276, 35.02547, 49.73341, 15.36187, 64.49885, 52.10079, 14.36624,
11.77537, 55.32611, 37.5923, 42.16856, 22.88578, 23.90528, 58.67193,
24.12246, 3.78987, 24.12246, 48.70548, 42.79663, 22.39828, 42.79663,
39.0616, 54.12387
),
tolerance = 1e-4
)
expect_equal(
xpectr::smpl(output_19148[["partner_hdi"]], n = 30),
c(
0.77413, 0.72727, 0.75967, 0.63167, 0.74327, 0.7978, 0.42793,
0.82307, 0.6152, 0.8488, 0.41745, 0.8966, 0.90367, 0.4436, 0.66013,
0.81747, 0.88153, 0.72627, 0.5626, 0.83293, 0.8356, 0.79653,
0.7572, 0.79653, 0.81347, 0.86293, 0.88707, 0.86293, 0.72027,
0.89533
),
tolerance = 1e-4
)
expect_equal(
xpectr::smpl(output_19148[["year"]], n = 30),
c(
2006, 2012, 2010, 2012, 2015, 2006, 2006, 2005, 2015, 2013, 2004,
2009, 2013, 2009, 2007, 2008, 2013, 2006, 2006, 2004, 2015,
2007, 2013, 2002, 2006, 2010, 2010, 2007, 2005, 2011
),
tolerance = 1e-4
)
expect_equal(
xpectr::smpl(output_19148[["vp_flow"]], n = 30),
c(
0.57317, 1.06474, 1.4264, 1.51527, 6.70853, 9.33908, 25.32324,
42.68805, 47.06484, 49.02937, 55.71717, 81.65817, 85.76057,
125.66247, 278.49957, 322.54075, 537.76924, 632.82146, 774.34631,
2445.51424, 2626.04619, 7419.20272, 7602.32548, 8983.99049,
13535.30658, 14348.984, 15222.46193, 17980.22781, 49567.35629,
102742.04511
),
tolerance = 1e-4
)
# Testing column names
expect_equal(
names(output_19148),
c(
"reporter_countries", "partner_countries", "reporter_long", "reporter_lat",
"reporter_hdi", "partner_long", "partner_lat", "partner_hdi",
"year", "vp_flow"
),
fixed = TRUE
)
# Testing column classes
expect_equal(
xpectr::element_classes(output_19148),
c(
"character", "character", "numeric", "numeric", "numeric", "numeric",
"numeric", "numeric", "numeric", "numeric"
),
fixed = TRUE
)
# Testing column types
expect_equal(
xpectr::element_types(output_19148),
c(
"character", "character", "double", "double", "double", "double",
"double", "double", "double", "double"
),
fixed = TRUE
)
# Testing dimensions
expect_equal(
dim(output_19148),
c(87621L, 10L)
)
# Testing group keys
expect_equal(
colnames(dplyr::group_keys(output_19148)),
character(0),
fixed = TRUE
)
## Finished testing 'distinct_countries(df)' ####
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.