-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShifterTest.java
More file actions
36 lines (32 loc) · 1.2 KB
/
ShifterTest.java
File metadata and controls
36 lines (32 loc) · 1.2 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
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ShifterTest {
int[] numbers = new int[] {17,44,129,0,53,12, 83,830,725,1033};
int[] factors = new int[] {1,2,3,4,5,6,7,8,9};
@Test
void leftShift() {
for (var number : numbers) {
for (var factor : factors) {
Word32 word = new Word32();
Word32 result = new Word32();
TestConverter.fromInt(number, word);
Shifter.LeftShift(word, factor, result);
int expected = number * ((int) Math.pow(2, factor ));
assertEquals(expected, TestConverter.toInt(result));
}
}
}
@Test
void rightShift() {
for (var number : numbers) {
for (var factor : factors) {
Word32 word = new Word32();
Word32 result = new Word32();
TestConverter.fromInt(number, word);
Shifter.RightShift(word, factor, result);
int expected = number / ((int) Math.pow(2, factor ));
assertEquals( expected,TestConverter.toInt(result));
}
}
}
}