@@ -10,6 +10,10 @@ cols_mod <- cols
1010cols_lch <- convert_colour(cols , ' rgb' ,' lch' )
1111cols_lch_mod <- cols_lch
1212
13+ codes_native <- encode_native(codes )
14+ codes_native_alpha <- encode_native(codes_alpha )
15+
16+
1317test_that(" setting channel works" , {
1418 cols_mod [, ' g' ] <- 1 : 10
1519 expect_equal(set_channel(codes , ' g' , 1 : 10 ), encode_colour(cols_mod ))
@@ -60,3 +64,57 @@ test_that("capping channel works", {
6064
6165 expect_equal(cap_channel(codes_alpha , ' alpha' , 0.5 ), encode_colour(cols , alpha = ifelse(alpha > 0.5 , 0.5 , alpha )))
6266})
67+
68+ # # Native variants:
69+
70+ test_that(" setting channel native works" , {
71+ cols_mod [, ' g' ] <- 1 : 10
72+ expect_equal(set_channel_native(codes_native , ' g' , 1 : 10 ), encode_native(cols_mod ))
73+
74+ cols_lch_mod [, ' l' ] <- 1 : 10
75+ expect_equal(set_channel_native(codes_native , ' l' , 1 : 10 , ' lch' ), encode_native(cols_lch_mod , from = ' lch' ))
76+
77+ expect_equal(set_channel_native(codes_native , ' alpha' , (1 : 10 )/ 10 ), encode_native(cols , alpha = (1 : 10 )/ 10 ))
78+ })
79+
80+ test_that(" adding channel works" , {
81+ cols_mod [, ' r' ] <- cols_mod [, ' r' ] + 1 : 10
82+ expect_equal(add_to_channel_native(codes_native , ' r' , 1 : 10 ), encode_native(cols_mod ))
83+
84+ cols_lch_mod [, ' c' ] <- cols_lch_mod [, ' c' ] + 1 : 10
85+ expect_equal(add_to_channel_native(codes_native , ' c' , 1 : 10 , ' lch' ), encode_native(cols_lch_mod , from = ' lch' ))
86+
87+ skip_on_os(' linux' ) # Rounding difference on someones aarch64/ppc64le processor
88+ expect_equal(add_to_channel_native(codes_native_alpha , ' alpha' , (1 : 10 )/ 10 ), encode_native(cols , alpha = alpha + (1 : 10 )/ 10 ))
89+ })
90+
91+
92+ test_that(" multiply channel works" , {
93+ cols_mod [, ' b' ] <- cols_mod [, ' b' ] * 1 : 10
94+ expect_equal(multiply_channel_native(codes_native , ' b' , 1 : 10 ), encode_native(cols_mod ))
95+
96+ cols_lch_mod [, ' h' ] <- cols_lch_mod [, ' h' ] * 1 : 10
97+ expect_equal(multiply_channel_native(codes_native , ' h' , 1 : 10 , ' lch' ), encode_native(cols_lch_mod , from = ' lch' ))
98+
99+ expect_equal(multiply_channel_native(codes_native_alpha , ' alpha' , 1 : 10 ), encode_native(cols , alpha = alpha * 1 : 10 ))
100+ })
101+
102+ test_that(" raising channel works" , {
103+ cols_mod [, ' g' ] <- ifelse(cols_mod [, ' g' ] < 200 , 200 , cols_mod [, ' g' ])
104+ expect_equal(raise_channel_native(codes_native , ' g' , 200 ), encode_native(cols_mod ))
105+
106+ cols_lch_mod [, ' l' ] <- ifelse(cols_lch_mod [, ' l' ] < 50 , 50 , cols_lch_mod [, ' l' ])
107+ expect_equal(raise_channel_native(codes_native , ' l' , 50 , ' lch' ), encode_native(cols_lch_mod , from = ' lch' ))
108+
109+ expect_equal(raise_channel_native(codes_native_alpha , ' alpha' , 0.5 ), encode_native(cols , alpha = ifelse(alpha < 0.5 , 0.5 , alpha )))
110+ })
111+
112+ test_that(" capping channel works" , {
113+ cols_mod [, ' g' ] <- ifelse(cols_mod [, ' g' ] > 200 , 200 , cols_mod [, ' g' ])
114+ expect_equal(cap_channel_native(codes_native , ' g' , 200 ), encode_native(cols_mod ))
115+
116+ cols_lch_mod [, ' l' ] <- ifelse(cols_lch_mod [, ' l' ] > 50 , 50 , cols_lch_mod [, ' l' ])
117+ expect_equal(cap_channel_native(codes_native , ' l' , 50 , ' lch' ), encode_native(cols_lch_mod , from = ' lch' ))
118+
119+ expect_equal(cap_channel_native(codes_native_alpha , ' alpha' , 0.5 ), encode_native(cols , alpha = ifelse(alpha > 0.5 , 0.5 , alpha )))
120+ })
0 commit comments