source: mainline/uspace/lib/c/test/imath.c@ 8f18f1e

Last change on this file since 8f18f1e was 8f18f1e, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

adding test cases for imath

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[8f18f1e]1/*
2 * Copyright (c) 2019 Matthieu Riolo
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <pcut/pcut.h>
30#include <imath.h>
31
32static uint64_t MAX_NUM = 10000000000000000000U;
33static unsigned MAX_EXP = 19;
34
35PCUT_INIT;
36
37PCUT_TEST_SUITE(imath);
38
39PCUT_TEST(ipow10_u64_zero)
40{
41 errno_t ret;
42 uint64_t result;
43 ret = ipow10_u64(0, &result);
44
45 PCUT_ASSERT_ERRNO_VAL(EOK, ret);
46 PCUT_ASSERT_INT_EQUALS(1, result);
47}
48
49PCUT_TEST(ipow10_u64_one)
50{
51 errno_t ret;
52 uint64_t result;
53 ret = ipow10_u64(1, &result);
54
55 PCUT_ASSERT_ERRNO_VAL(EOK, ret);
56 PCUT_ASSERT_INT_EQUALS(10, result);
57}
58
59PCUT_TEST(ipow10_u64_max)
60{
61 errno_t ret;
62 uint64_t result;
63 ret = ipow10_u64(MAX_EXP, &result);
64
65 PCUT_ASSERT_ERRNO_VAL(EOK, ret);
66 PCUT_ASSERT_INT_EQUALS(MAX_NUM, result);
67}
68
69PCUT_TEST(ipow10_u64_too_large)
70{
71 errno_t ret;
72 uint64_t result;
73 ret = ipow10_u64(MAX_EXP + 1, &result);
74
75 PCUT_ASSERT_ERRNO_VAL(ERANGE, ret);
76}
77
78PCUT_TEST(ilog10_u64_zero)
79{
80 unsigned ret = ilog10_u64(0);
81 PCUT_ASSERT_INT_EQUALS(0, ret);
82}
83
84PCUT_TEST(ilog10_u64_one)
85{
86 unsigned ret = ilog10_u64(1);
87 PCUT_ASSERT_INT_EQUALS(0, ret);
88}
89
90PCUT_TEST(ilog10_u64_max)
91{
92 unsigned ret = ilog10_u64(MAX_NUM);
93 PCUT_ASSERT_INT_EQUALS(MAX_EXP, ret);
94}
95
96PCUT_EXPORT(imath);
Note: See TracBrowser for help on using the repository browser.