summaryrefslogtreecommitdiff
path: root/test/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/utils.c')
-rw-r--r--test/utils.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/utils.c b/test/utils.c
index 82316a53cc..9402e92740 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -481,6 +481,30 @@ test_static int test_alignment_log2(void)
return EC_SUCCESS;
}
+test_static int test_binary_first_base3_from_bits(void)
+{
+ int n0[] = {0, 0, 0}; /* LSB first */
+ int n7[] = {1, 1, 1};
+ int n8[] = {2, 0, 0};
+ int n9[] = {2, 1, 0};
+ int n10[] = {0, 2, 0};
+ int n11[] = {1, 2, 0};
+ int n18[] = {0, 0, 2};
+ int n26[] = {2, 2, 2};
+ int n38[] = {1, 2, 0, 1};
+
+ TEST_EQ(binary_first_base3_from_bits(n0, ARRAY_SIZE(n0)), 0, "%d");
+ TEST_EQ(binary_first_base3_from_bits(n7, ARRAY_SIZE(n7)), 7, "%d");
+ TEST_EQ(binary_first_base3_from_bits(n8, ARRAY_SIZE(n8)), 8, "%d");
+ TEST_EQ(binary_first_base3_from_bits(n9, ARRAY_SIZE(n9)), 9, "%d");
+ TEST_EQ(binary_first_base3_from_bits(n10, ARRAY_SIZE(n10)), 10, "%d");
+ TEST_EQ(binary_first_base3_from_bits(n11, ARRAY_SIZE(n11)), 11, "%d");
+ TEST_EQ(binary_first_base3_from_bits(n18, ARRAY_SIZE(n18)), 18, "%d");
+ TEST_EQ(binary_first_base3_from_bits(n26, ARRAY_SIZE(n26)), 26, "%d");
+ TEST_EQ(binary_first_base3_from_bits(n38, ARRAY_SIZE(n38)), 38, "%d");
+ return EC_SUCCESS;
+}
+
void run_test(int argc, char **argv)
{
test_reset();
@@ -502,6 +526,7 @@ void run_test(int argc, char **argv)
RUN_TEST(test_is_aligned);
RUN_TEST(test_safe_memcmp);
RUN_TEST(test_alignment_log2);
+ RUN_TEST(test_binary_first_base3_from_bits);
test_print_result();
}