1+ test_that(" break_string works properly" ,{
2+ expect_equal(break_str(" A dog is here" , 6 )," A dog\n is\n here" )
3+ })
4+
5+ test_that(" Abort and Warn work" ,{
6+ expect_error(Abort(" abort" ))
7+ expect_warning(Warn(" warn" ))
8+ })
9+
10+ test_that(" in_range works" ,{
11+ expect_equal(in_range(1 ,c(2 ,4 )),2 )
12+ expect_equal(in_range(3 ,c(2 ,4 )),3 )
13+ expect_equal(in_range(5 ,c(2 ,4 )),4 )
14+ })
15+
16+ test_that(" new summarizing functions work" ,{
17+ x <- c(3 ,4 ,5 ,9 ,NA )
18+ expect_equal(Min(x ),3 )
19+ expect_equal(Max(x ),9 )
20+ expect_equal(Sum(x ),21 )
21+ expect_equal(Mean(x ),5.25 )
22+ expect_equal(Median(x ),4.5 )
23+ })
24+
25+ test_that(" Other capital letter functions work" ,{
26+ x <- c(1 ,2 ,3 ,4 ,5 )
27+ expect_equal(Start(x ),1 )
28+ expect_equal(End(x ),5 )
29+ expect_equal(MiddleL(x ),2 ) # Questionable for odd length vectors
30+ expect_equal(MiddleR(x ),3 ) # Questionable for odd length vectors
31+ expect_equal(ExtendL(x ),c(1 ,1 ,2 ,3 ,4 ,5 ))
32+ expect_equal(ExtendR(x ),c(1 ,2 ,3 ,4 ,5 ,5 ))
33+ })
34+
35+ test_that(" guess_geo_type tests for different types of geo_value's" ,{
36+ # California, New York
37+ states <- c(" ca" ," ny" )
38+
39+ # Canada, USA, United Kingdom
40+ nations <- c(" ca" ," us" ," uk" )
41+
42+ # Note: These are just five-number names that may not necessarily be existent
43+ # counties
44+ counties <- c(" 12345" ," 67890" )
45+
46+ # HHS regions
47+ hhs <- c(1 : 3 )
48+
49+ # HRR regions
50+ hrr <- c(100 ,200 )
51+
52+ # Long numbers should be custom
53+ long_nums <- c(123456789 ,111222333 )
54+
55+ # Health regions in British Columbia
56+ bc <- c(" Vancouver Coastal" ," Interior" ," Fraser" ,
57+ " Northern" ," Vancouver Island" )
58+
59+ # Long numbers as strings should also be custom
60+ long_num_strings <- c(" 123456789" ," 111222333" )
61+
62+ expect_equal(guess_geo_type(states )," state" )
63+ expect_equal(guess_geo_type(nations )," nation" )
64+ expect_equal(guess_geo_type(counties )," county" )
65+ expect_equal(guess_geo_type(hhs )," hhs" )
66+ expect_equal(guess_geo_type(hrr )," hrr" )
67+ expect_equal(guess_geo_type(long_num_strings )," custom" )
68+ expect_equal(guess_geo_type(bc )," custom" )
69+ expect_equal(guess_geo_type(long_nums )," custom" )
70+ })
71+
72+ test_that(" guess_time_type works for different types" ,{
73+ days <- as.Date(" 2022-01-01" ) + 0 : 6
74+ weeks <- as.Date(" 2022-01-01" ) + 7 * 0 : 6
75+
76+ yearweeks <- tsibble :: yearweek(10 )
77+ yearmonths <- tsibble :: yearmonth(10 )
78+ yearquarters <- tsibble :: yearquarter(10 )
79+
80+ years <- c(1999 ,2000 )
81+
82+ # YYYY-MM-DD is the accepted format
83+ not_ymd1 <- " January 1, 2022"
84+ not_ymd2 <- " 1 January 2022"
85+ not_ymd3 <- " 1 Jan 2022"
86+
87+ not_a_date <- " asdf"
88+
89+ expect_equal(guess_time_type(days )," day" )
90+ expect_equal(guess_time_type(weeks )," week" )
91+
92+ expect_equal(guess_time_type(yearweeks )," yearweek" )
93+ expect_equal(guess_time_type(yearmonths )," yearmonth" )
94+ expect_equal(guess_time_type(yearquarters )," yearquarter" )
95+
96+ expect_equal(guess_time_type(years )," year" )
97+
98+ expect_equal(guess_time_type(not_ymd1 )," custom" )
99+ expect_equal(guess_time_type(not_ymd2 )," custom" )
100+ expect_equal(guess_time_type(not_ymd3 )," custom" )
101+ expect_equal(guess_time_type(not_a_date )," custom" )
102+ })
103+
104+ test_that(" enlist works" ,{
105+ my_list <- enlist(x = 1 ,y = 2 ,z = 3 )
106+ expect_equal(my_list $ x ,1 )
107+ expect_true(inherits(my_list ," list" ))
108+ })
0 commit comments