File: CommonBitsTest.cpp

package info (click to toggle)
geos 3.14.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,212 kB
  • sloc: cpp: 199,103; xml: 56,065; ansic: 6,162; sh: 287; makefile: 26
file content (80 lines) | stat: -rw-r--r-- 2,262 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Test Suite for geos::precision::CommonBits class.

// tut
#include <tut/tut.hpp>
// geos
#include <geos/constants.h>
#include <geos/precision/CommonBits.h>
// std

using geos::precision::CommonBits;

namespace tut {
// Common data used by tests
struct test_commonbits_data {};

typedef test_group<test_commonbits_data> group;
typedef group::object object;

group test_commonbits_group("geos::precision::CommonBits");

// getBit from zero.
template<>
template<>
void object::test<1>
()
{
    constexpr int64_t val = 0ull;
    for(int i = 0; i < 64; i++) {
        ensure_equals(CommonBits::getBit(val, i), 0);
    }
}

// getBit from all ones.
template<>
template<>
void object::test<2>
()
{
    constexpr int64_t val = static_cast<int64_t>(0xffffffffffffffffull);
    for(int i = 0; i < 64; i++) {
        ensure_equals(CommonBits::getBit(val, i), 1);
    }
}

// getBit check high versus low bits.
template<>
template<>
void object::test<3>
()
{
    constexpr int64_t val = static_cast<int64_t>(0xffffffff00000000ull);
    ensure_equals(CommonBits::getBit(val, 0), 0);
    ensure_equals(CommonBits::getBit(val, 63), 1);
}

// zeroLowerBits.
template<>
template<>
void object::test<4>()
{
    constexpr int64_t val = static_cast<int64_t>(0xffffffffffffffffull);
    ensure_equals(sizeof(val), 8u);

    ensure_equals(CommonBits::zeroLowerBits(val, -1), 0);
    ensure_equals(CommonBits::zeroLowerBits(val, 0), -1);
    ensure_equals(CommonBits::zeroLowerBits(val, 1), -2);
    ensure_equals(CommonBits::zeroLowerBits(val, 2), -4);
    ensure_equals(CommonBits::zeroLowerBits(val, 16), -65536);
    ensure_equals(CommonBits::zeroLowerBits(val, 31), -2147483648ll);
    ensure_equals(CommonBits::zeroLowerBits(val, 32), -4294967296ll);
    ensure_equals(CommonBits::zeroLowerBits(val, 62), -4611686018427387904ll);
    ensure_equals(static_cast<uint64_t>(CommonBits::zeroLowerBits(val, 62)), 0xc000000000000000ull);
    ensure_equals(static_cast<uint64_t>(CommonBits::zeroLowerBits(val, 63)), 9223372036854775808ull);
    ensure_equals(static_cast<uint64_t>(CommonBits::zeroLowerBits(val, 63)), 0x8000000000000000ull);
    ensure_equals(CommonBits::zeroLowerBits(val, 64), 0);
    ensure_equals(CommonBits::zeroLowerBits(val, 10000), 0);
}


} // namespace tut