-
Notifications
You must be signed in to change notification settings - Fork 0
/
rippleAdder_test.java
72 lines (69 loc) · 3.34 KB
/
rippleAdder_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
package ComputerArchitecture;
/*
Jan Karl Galia
Comp. Architecture ******************NOTE TO USERS: TESTS ARE AUTOMATED, VALUES(BINARY BIT ARRAYS AND INTEGERS) ARE RANDOMLY GENERATED************
*************TO CONVERT TO T,F RATHER THAN 1,0, REPLACE toStringConvert() to toString()**********
HW 3: Ripple Adder
*/
public class rippleAdder_test {
public static void main(String[] args) {
runTests();
}
public static void runTests() {
testLongwordAdd();
testLongwordSub();
}
public static void testLongwordAdd() {
Longword otherInput = new Longword();
//Random BitArray Generator for Automatic testing---------------------------------------
Longword randomInput = new Longword();
Bit randomBit = new Bit();
Bit bitTrue = new Bit();
bitTrue.set(true);
boolean randomBool = false;
for (int i = 0; i < 32; i++) {//Creates Random binary string and sets it to randomInput bitArray
randomBool = randomBit.randomBool();
if (randomBool) {
randomInput.setBit(i, bitTrue);
}
}
for (int i = 0; i < 32; i++) {//Creates Random binary string and sets it to randomInput bitArray
randomBool = randomBit.randomBool();
if (randomBool) {
otherInput.setBit(i, bitTrue);
}
}
//--------------------------------------------------------------------------------------------
System.out.println("-------------------------------------------");
System.out.println("ADDING 2s Complement(Inputs and Outputs)");
System.out.println("TestFirstInput:" + randomInput.toStringConvert());
System.out.println("TestOtherInput:" + otherInput.toStringConvert());
System.out.println("TestAdder(32-Bits):" + rippleAdder.add(randomInput, otherInput).toStringConvert());
}
public static void testLongwordSub() {
Longword otherInput = new Longword();
//Random BitArray Generator for Automatic testing---------------------------------------
Longword randomInput = new Longword();
Bit randomBit = new Bit();
Bit bitTrue = new Bit(1);
boolean randomBool = false;
for (int i = 0; i < 32; i++) {//Creates Random binary string and sets it to randomInput bitArray
randomBool = randomBit.randomBool();
if (randomBool) {
randomInput.setBit(i, bitTrue);
}
}
for (int i = 0; i < 32; i++) {//Creates Random binary string and sets it to randomInput bitArray
randomBool = randomBit.randomBool();
if (randomBool) {
otherInput.setBit(i, bitTrue);
}
}
//--------------------------------------------------------------------------------------------
System.out.println("-------------------------------------------");
System.out.println("SUBTRACTING 2s Complement(Inputs and Outputs)");
System.out.println("TestFirstInput:" + randomInput.toStringConvert());
System.out.println("TestOtherInput:" + otherInput.toStringConvert());
System.out.println("TestSubtract(32-Bits):" + rippleAdder.sub(randomInput, otherInput).toStringConvert());
}
}