GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/unittests/utils/mathutils.cc Lines: 72 72 100.0 %
Date: 2021-03-17 Branches: 274 814 33.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2013-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
#include "unittests/unittests.h"
23
24
#include "utils/mathutils.h"
25
26
#include "debug.h"
27
28
✓✗
3
TEST_CASE("MathUtils powerOfTwo", "")
29
{
30
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(0) == 1);
31
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(1) == 1);
32
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(2) == 2);
33
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(3) == 4);
34
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(4) == 4);
35
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(5) == 8);
36
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(6) == 8);
37
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(7) == 8);
38
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(8) == 8);
39
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(9) == 16);
40
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(10) == 16);
41
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(11) == 16);
42
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(12) == 16);
43
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(13) == 16);
44
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(14) == 16);
45
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(15) == 16);
46
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(16) == 16);
47
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(17) == 32);
48
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(18) == 32);
49
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(19) == 32);
50
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(20) == 32);
51
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(21) == 32);
52
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(22) == 32);
53
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(23) == 32);
54
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(24) == 32);
55
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(25) == 32);
56
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(26) == 32);
57
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(27) == 32);
58
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(28) == 32);
59
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(29) == 32);
60
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(30) == 32);
61
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(31) == 32);
62
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(32) == 32);
63
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(33) == 64);
64
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(34) == 64);
65
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(35) == 64);
66
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(36) == 64);
67
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(37) == 64);
68
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(38) == 64);
69
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(39) == 64);
70
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(41) == 64);
71
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(42) == 64);
72
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(43) == 64);
73
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(44) == 64);
74
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(45) == 64);
75
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(46) == 64);
76
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(47) == 64);
77
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(48) == 64);
78
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(49) == 64);
79
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(50) == 64);
80
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(51) == 64);
81
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(52) == 64);
82
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(53) == 64);
83
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(54) == 64);
84
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(55) == 64);
85
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(56) == 64);
86
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(57) == 64);
87
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(58) == 64);
88
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(59) == 64);
89
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(60) == 64);
90
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(61) == 64);
91
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(62) == 64);
92
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(63) == 64);
93
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(64) == 64);
94
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(65) == 128);
95
96
✓✗✓✗
✓✗✓✗
✗✗✗✗
4
    REQUIRE(powerOfTwo(1000000) == 1048576);
97
1
}
98
99
✓✗
3
TEST_CASE("MathUtils tests fastSqrtInt", "")
100
{
101
✓✓
1006
    for (int f = 0; f < 1005; f ++)
102
✓✗✓✗
✓✗✓✗
✗✗✗✗
5025
        REQUIRE(fastSqrtInt(f) == CAST_S32(sqrt(f)));
103
✓✗✓✗
4
}