-
Notifications
You must be signed in to change notification settings - Fork 0
/
bit_test.java
225 lines (156 loc) · 7.24 KB
/
bit_test.java
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
public class bit_test
{
public static void main(String[] args) throws Exception
{
runTests();
}
public static void runTests() throws Exception
{
System.out.println("UNIT TEST START ----------------------------------------------------------------------------");
System.out.println("Running Tests:");
testGetValue();
testToString();
testToggle();
testSet();
testClear();
testAnd();
testOr();
testXor();
testNot();
System.out.println("ALL UNIT TESTING HAS PASSED!");
}
public static void testGetValue() throws Exception
{
bit bit1 = new bit();
bit bit2 = new bit(true);
if(bit1.getValue() != false) throw new Exception("getValue of false has failed.");
if(bit2.getValue() != true) throw new Exception("getValue of true has failed.");
System.out.println("\tgetValue testing has passed.");
}
public static void testToString() throws Exception
{
bit bit1 = new bit();
bit bit2 = new bit(true);
if(bit1.toString().equals("f") != true) throw new Exception("toString of false has failed.");
if(bit2.toString().equals("t") != true) throw new Exception("toString of true has failed.");
System.out.println("\ttoString testing has passed.");
}
public static void testToggle() throws Exception
{
bit bit1 = new bit(); //false
bit bit2 = new bit(true); //true
bit1.toggle();
bit2.toggle();
if(bit1.getValue() != true) throw new Exception("Toggle false to true has failed.");
if(bit2.getValue() != false) throw new Exception("Toggle true to false has failed");
System.out.println("\tToggle Testing has passed.");
}
public static void testSet() throws Exception
{
bit bit1 = new bit(); //false
bit bit2 = new bit(true); //true
bit1.set();
bit2.set();
if(bit1.getValue() != true) throw new Exception("Setting false to true has failed.");
if(bit2.getValue() != true) throw new Exception("Setting true to true has failed");
bit bit3 = new bit(); //false
bit bit4 = new bit(true); //true
bit3.set(true);
bit4.set(false);
if(bit3.getValue() != true) throw new Exception("Parameterized setting false to true has failed.");
if(bit4.getValue() != false) throw new Exception("Parameterized setting true to false has failed");
System.out.println("\tSetting Testing has passed.");
}
public static void testClear() throws Exception
{
bit bit1 = new bit(); //false
bit bit2 = new bit(true); //true
bit1.clear();
bit2.clear();
if(bit1.getValue() != false) throw new Exception("Clearing false to false has failed.");
if(bit2.getValue() != false) throw new Exception("Clearing true to false has failed");
System.out.println("\tClear Testing has passed.");
}
public static void testAnd() throws Exception
{
bit bit1 = new bit(true);
bit bit2 = new bit(true);
bit outputTT = bit1.and(bit2);
if(outputTT.getValue() != true) throw new Exception("True & True has failed.");
//System.out.println("\ttrue & true (expected: true): "+outputTT);
bit bit3 = new bit(true);
bit bit4 = new bit(false);
bit outputTF = bit3.and(bit4);
if(outputTF.getValue() != false) throw new Exception("True & False has failed.");
//System.out.println("\ttrue & false (expected: false): "+outputTF);
bit bit5 = new bit(false);
bit bit6 = new bit(true);
bit outputFT = bit5.and(bit6);
if(outputFT.getValue() != false) throw new Exception("False & True has failed.");
//System.out.println("\tfalse & true (expected: false): "+outputFT);
bit bit7 = new bit(false);
bit bit8 = new bit(false);
bit outputFF = bit7.and(bit8);
if(outputFF.getValue() != false) throw new Exception("False & False has failed.");
//System.out.println("\tfalse & false (expected: false): "+outputFF);
System.out.println("\tAnd testing passed.");
}
public static void testOr() throws Exception
{
bit bit1 = new bit(true);
bit bit2 = new bit(true);
bit outputTT = bit1.or(bit2);
if(outputTT.getValue() != true) throw new Exception("True | True has failed.");
//System.out.println("\ttrue | true (expected: true): "+outputTT);
bit bit3 = new bit(true);
bit bit4 = new bit(false);
bit outputTF = bit3.or(bit4);
if(outputTF.getValue() != true) throw new Exception("True | False has failed.");
//System.out.println("\ttrue | false (expected: true): "+outputTF);
bit bit5 = new bit(false);
bit bit6 = new bit(true);
bit outputFT = bit5.or(bit6);
if(outputFT.getValue() != true) throw new Exception("False | True has failed.");
//System.out.println("\tfalse | true (expected: true): "+outputFT);
bit bit7 = new bit(false);
bit bit8 = new bit(false);
bit outputFF = bit7.or(bit8);
if(outputFF.getValue() != false) throw new Exception("False | False has failed.");
//System.out.println("\tfalse | false (expected: false): "+outputFF);
System.out.println("\tOr Testing has passed.");
}
public static void testXor() throws Exception
{
bit bit1 = new bit(true);
bit bit2 = new bit(true);
bit outputTT = bit1.xor(bit2);
if(outputTT.getValue() != false) throw new Exception("True ^ True has failed.");
//System.out.println("\ttrue ^ true (expected: false): "+outputTT);
bit bit3 = new bit(true);
bit bit4 = new bit(false);
bit outputTF = bit3.xor(bit4);
if(outputTF.getValue() != true) throw new Exception("True ^ False has failed.");
//System.out.println("\ttrue ^ false (expected: true): "+outputTF);
bit bit5 = new bit(false);
bit bit6 = new bit(true);
bit outputFT = bit5.xor(bit6);
if(outputFT.getValue() != true) throw new Exception("False ^ True has failed.");
//System.out.println("\tfalse ^ true (expected: true): "+outputFT);
bit bit7 = new bit(false);
bit bit8 = new bit(false);
bit outputFF = bit7.xor(bit8);
if(outputFF.getValue() != false) throw new Exception("False ^ False has failed.");
//System.out.println("\tfalse ^ false (expected: false): "+outputFF);
System.out.println("\tXor Testing has passed.");
}
public static void testNot() throws Exception
{
bit notTest = new bit(); //false
bit notTest2 = new bit(true); //true
bit notTestOutput = notTest.not();
bit notTest2Output = notTest2.not();
if(notTestOutput.getValue() != true) throw new Exception("!false has failed.");
if(notTest2Output.getValue() != false) throw new Exception("!true has failed.");
System.out.println("\tNot Testing has passed.");
}
}