11context(" utils.R" )
22
3- test_that(" projection() should be working correctly " , {
3+ test_that(" projection()" , {
44 expect_equal(projection(1 , 10 , 20 ), 15 )
55 expect_equal(projection(c(0 , 0 , 0 ), 10 , 20 ), 15 )
66 # expect_equal(projection(NULL, 10, 20), 15)
77 # expect_equal(projection(NA, 10, 20), 15)
88 expect_equal(projection(c(1 , 2 ), 10 , 20 ), c(10 , 20 ))
99 expect_equal(projection(c(0 , 5 , 10 ), 10 , 20 ), c(10 , 15 , 20 ))
10- })
10+ })
11+
12+ test_that(" get_palette()" , {
13+ expect_equal(length(get_palette(1 )), 1 )
14+ expect_equal(length(get_palette(5 )), 5 )
15+ expect_equal(length(get_palette(19 )), 19 )
16+ # only can get 19 colors, no more
17+ expect_equal(length(get_palette(50 )), 19 )
18+
19+ expect_equal(names(get_palette(4 )), c(" blue" , " red" , " green" , " yellow" ))
20+ expect_equal(
21+ get_palette(4 ),
22+ c(
23+ blue = " #0C46A0FF" ,
24+ red = " #B71B1BFF" ,
25+ green = " #1A5E1FFF" ,
26+ yellow = " #F47F17FF"
27+ )
28+ )
29+ })
30+
31+ test_that(" get_color_variants()" , {
32+ expect_equal(get_color_variants(" #123456" ), c(" #1234564D" , " #12345680" , " #123456FF" ))
33+ })
34+
35+ test_that(" get_colors()" , {
36+ expect_equal(
37+ get_colors(c(" type1" )),
38+ list (type1 = c(" #0C46A04D" , " #0C46A080" , " #0C46A0FF" ))
39+ )
40+ expect_equal(
41+ get_colors(c(" a" , " b" , " c" )),
42+ list (
43+ a = c(" #0C46A04D" , " #0C46A080" , " #0C46A0FF" ),
44+ b = c(" #B71B1B4D" , " #B71B1B80" , " #B71B1BFF" ),
45+ c = c(" #1A5E1F4D" , " #1A5E1F80" , " #1A5E1FFF" )
46+ )
47+ )
48+
49+ # return empty list for invalid input
50+ expect_equal(get_colors(c()), list ())
51+ expect_equal(get_colors(NULL ), list ())
52+ })
0 commit comments