source: mainline/uspace/lib/c/test/imath.c@ d7f7a4a

Last change on this file since d7f7a4a was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Replace some license headers with SPDX identifier

Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[88e7dc5]1/*
[d7f7a4a]2 * SPDX-FileCopyrightText: 2019 Matthieu Riolo
[88e7dc5]3 *
[d7f7a4a]4 * SPDX-License-Identifier: BSD-3-Clause
[88e7dc5]5 */
6
7#include <pcut/pcut.h>
8#include <imath.h>
9
10static uint64_t MAX_NUM = 10000000000000000000U;
11static unsigned MAX_EXP = 19;
12
13PCUT_INIT;
14
15PCUT_TEST_SUITE(imath);
16
17PCUT_TEST(ipow10_u64_zero)
18{
19 errno_t ret;
20 uint64_t result;
21 ret = ipow10_u64(0, &result);
22
23 PCUT_ASSERT_ERRNO_VAL(EOK, ret);
24 PCUT_ASSERT_INT_EQUALS(1, result);
25}
26
27PCUT_TEST(ipow10_u64_one)
28{
29 errno_t ret;
30 uint64_t result;
31 ret = ipow10_u64(1, &result);
32
33 PCUT_ASSERT_ERRNO_VAL(EOK, ret);
34 PCUT_ASSERT_INT_EQUALS(10, result);
35}
36
37PCUT_TEST(ipow10_u64_max)
38{
39 errno_t ret;
40 uint64_t result;
41 ret = ipow10_u64(MAX_EXP, &result);
42
43 PCUT_ASSERT_ERRNO_VAL(EOK, ret);
44 PCUT_ASSERT_INT_EQUALS(MAX_NUM, result);
45}
46
47PCUT_TEST(ipow10_u64_too_large)
48{
49 errno_t ret;
50 uint64_t result;
51 ret = ipow10_u64(MAX_EXP + 1, &result);
52
53 PCUT_ASSERT_ERRNO_VAL(ERANGE, ret);
54}
55
56PCUT_TEST(ilog10_u64_zero)
57{
58 unsigned ret = ilog10_u64(0);
59 PCUT_ASSERT_INT_EQUALS(0, ret);
60}
61
62PCUT_TEST(ilog10_u64_one)
63{
64 unsigned ret = ilog10_u64(1);
65 PCUT_ASSERT_INT_EQUALS(0, ret);
66}
67
68PCUT_TEST(ilog10_u64_max)
69{
70 unsigned ret = ilog10_u64(MAX_NUM);
71 PCUT_ASSERT_INT_EQUALS(MAX_EXP, ret);
72}
73
74PCUT_EXPORT(imath);
Note: See TracBrowser for help on using the repository browser.