File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 7373
7474#define ISPOW2 (n ) ( (n)>0 && ((((n) & ((n)-1)) == 0)) )
7575
76+ #define ABS (n ) ( (n<0) ? (-n) : (n) )
77+
7678
7779/*
7880 In contrast to the standard C modulus operator (%), this gives
Original file line number Diff line number Diff line change @@ -191,6 +191,15 @@ static void test_ISPOW2(void)
191191 assert_false (ISPOW2 (0xFFFFFFFF ));
192192}
193193
194+ static void test_ABS (void )
195+ {
196+ assert_int_equal (ABS (-2 ), 2 );
197+ assert_int_equal (ABS (-1 ), 1 );
198+ assert_int_equal (ABS ( 0 ), 0 );
199+ assert_int_equal (ABS ( 1 ), 1 );
200+ assert_int_equal (ABS ( 2 ), 2 );
201+ }
202+
194203static void test_putenv_wrapper (void )
195204{
196205 assert_true (getenv ("UNIT_TEST_VAR" ) == NULL );
@@ -238,6 +247,7 @@ int main()
238247 unit_test (test_upper_power_of_two ),
239248 unit_test (test_rand_ISPOW2 ),
240249 unit_test (test_ISPOW2 ),
250+ unit_test (test_ABS ),
241251 unit_test (test_putenv_wrapper ),
242252 unit_test (test_setenv_wrapper ),
243253 };
You can’t perform that action at this time.
0 commit comments