-
Notifications
You must be signed in to change notification settings - Fork 0
/
bit_test.hpp
118 lines (85 loc) · 1.9 KB
/
bit_test.hpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// bit_test.cpp
// fundamentals
//
// Created by Andreas Fragner on 7/14/12.
//
#include "test.h"
#include "bit.hpp"
#ifndef fundamentals_bit_test_hpp
#define fundamentals_bit_test_hpp
//bit test class inherited from test class
class BitTest : public Test {
public:
BitTest();
~BitTest(){ specs.clear(); results.clear(); };
protected:
//test functions
static bool test_GetBit();
static bool test_SetBit();
static bool test_SetBitTo();
static bool test_FlipBit();
static bool test_ClearBit();
static bool test_ClearBits();
static bool test_MostSignficantBit();
static bool test_LeastSignficantBit();
};
//constructor
BitTest::BitTest():Test("Bit Algorithms")
{
specs.push_back( test_GetBit );
specs.push_back( test_SetBit );
specs.push_back( test_SetBitTo );
specs.push_back( test_FlipBit );
specs.push_back( test_ClearBit );
specs.push_back( test_ClearBits );
specs.push_back( test_MostSignficantBit );
specs.push_back( test_LeastSignficantBit );
}
bool BitTest::test_GetBit()
{
return (GetBit(1,0) && !GetBit(2,0));
}
bool BitTest::test_SetBit()
{
int x = 0, y = 2;
SetBit(x,0);
SetBit(y,0);
return ( (x == 1) && (y == 3) );
}
bool BitTest::test_SetBitTo()
{
int x = 0, y = 3;
SetBitTo(x,0,true);
SetBitTo(y,0,false);
return ( (x == 1) && (y == 2) );
}
bool BitTest::test_FlipBit()
{
int x = 1, y = 0;
FlipBit(x,0);
FlipBit(y,0);
return ( (x == 0) && (y == 1) );
}
bool BitTest::test_ClearBit()
{
int x = 2, y = 4;
ClearBit(x,1);
ClearBit(y,1);
return ( (x==0) && (y==4) );
}
bool BitTest::test_ClearBits()
{
int x = 3, y = 5;
ClearBits(x,0,1);
ClearBits(y,1,2);
return (x == 0 & y == 1);
}
// TO BE COMPLETED
bool BitTest::test_MostSignficantBit()
{
}
bool BitTest::test_LeastSignficantBit()
{
}
#endif