1- # Tests for betydata datasets
1+ # Tests for betydata tables
22
3- context(" Dataset validation" )
4-
5- test_that(" traitsview dataset loads correctly" , {
3+ test_that(" traitsview loads correctly" , {
64 data(" traitsview" , package = " betydata" )
7-
5+
86 expect_s3_class(traitsview , " data.frame" )
97 expect_gt(nrow(traitsview ), 40000 )
10- expect_equal(ncol(traitsview ), 36 )
8+ expect_equal(ncol(traitsview ), 35 )
119})
1210
1311test_that(" traitsview has required columns" , {
1412 data(" traitsview" , package = " betydata" )
15-
13+
1614 expected_cols <- c(
17- " id" , " trait" , " mean" , " units" , " scientificname" ,
18- " sitename" , " author" , " checked" , " access_level "
15+ " id" , " trait" , " mean" , " units" , " scientificname" ,
16+ " sitename" , " author" , " checked"
1917 )
2018 expect_true(all(expected_cols %in% names(traitsview )))
2119})
2220
2321test_that(" traitsview excludes checked = -1 per data policy" , {
2422 data(" traitsview" , package = " betydata" )
25-
26- expect_false(any(traitsview $ checked == - 1 , na.rm = TRUE ))
27- })
2823
29- test_that(" traitsview contains only public data" , {
30- data(" traitsview" , package = " betydata" )
31-
32- expect_true(all(traitsview $ access_level > = 4 , na.rm = TRUE ))
24+ expect_false(any(traitsview $ checked == - 1 , na.rm = TRUE ))
3325})
3426
3527test_that(" traitsview coordinates are valid" , {
3628 data(" traitsview" , package = " betydata" )
37-
29+
3830 valid_lat <- traitsview $ lat [! is.na(traitsview $ lat )]
3931 valid_lon <- traitsview $ lon [! is.na(traitsview $ lon )]
40-
32+
4133 expect_true(all(valid_lat > = - 90 & valid_lat < = 90 ))
4234 expect_true(all(valid_lon > = - 180 & valid_lon < = 180 ))
4335})
4436
45- test_that(" species dataset loads correctly" , {
37+ test_that(" traitsview key columns are first" , {
38+ data(" traitsview" , package = " betydata" )
39+
40+ first_cols <- names(traitsview )[1 : 5 ]
41+ expect_equal(first_cols , c(" trait" , " mean" , " units" , " scientificname" , " genus" ))
42+ })
43+
44+ test_that(" species table loads correctly" , {
4645 data(" species" , package = " betydata" )
47-
46+
4847 expect_s3_class(species , " data.frame" )
4948 expect_true(" id" %in% names(species ))
5049 expect_gt(nrow(species ), 0 )
5150})
5251
53- test_that(" variables dataset loads correctly" , {
52+ test_that(" variables table loads correctly" , {
5453 data(" variables" , package = " betydata" )
55-
54+
5655 expect_s3_class(variables , " data.frame" )
5756 required_cols <- c(" id" , " name" , " units" )
5857 expect_true(all(required_cols %in% names(variables )))
5958})
6059
61- test_that(" pfts dataset loads correctly" , {
60+ test_that(" pfts table loads correctly" , {
6261 data(" pfts" , package = " betydata" )
63-
62+
6463 expect_s3_class(pfts , " data.frame" )
6564 expect_true(all(c(" id" , " name" ) %in% names(pfts )))
66- })
65+ })
0 commit comments