-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignedAdditionTest.java
More file actions
50 lines (40 loc) · 1.26 KB
/
SignedAdditionTest.java
File metadata and controls
50 lines (40 loc) · 1.26 KB
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
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class SignedAdditionTest {
@Rule
public Timeout globalTimeout = Timeout.seconds(10);
@Parameters
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {
{"0001", "0010", 4, "000011"},
{"0001", "1001", 4, "000000"},
{"1001", "0001", 4, "010000"},
{"00111", "01001", 4, "100000"},
{"10111", "11001", 4, "110000"},
{"1100", "1011", 8, "0100000111"},
});
}
private ALU alu = new ALU();
private String operand1;
private String operand2;
private int length;
private String expected;
public SignedAdditionTest(String operand1, String operand2, int length, String expected) {
this.operand1 = operand1;
this.operand2 = operand2;
this.length = length;
this.expected = expected;
}
@Test
public void test() {
assertEquals(expected, alu.signedAddition(operand1, operand2, length));
}
}