-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFourBitTwoTest.java
More file actions
72 lines (61 loc) · 2.41 KB
/
FourBitTwoTest.java
File metadata and controls
72 lines (61 loc) · 2.41 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Tests for FourBitTwoDisclosureDeviceUnlocker
*/
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.containsString;
public class FourBitTwoTest {
static final boolean USEDEVDEVICE = false;
static Device buildDevice(boolean[] init, int bits) {
if (USEDEVDEVICE) {
return new DevDevice(init, bits);
} else {
return new Device(init, bits);
}
}
static Device buildDevice() {
if (USEDEVDEVICE) {
return new DevDevice();
} else {
return new Device();
}
}
@Test public void testItUnlocksTheDeviceWithAllTrue() {
boolean[] init = {true, true, true, true};
Device d = FourBitTwoTest.buildDevice(init, 2);
assertTrue(FourBitTwoDisclosureDeviceUnlocker.unlock(d));
String trace = FourBitTwoDisclosureDeviceUnlocker.showTrace();
assertThat(trace, containsString("true"));
// System.out.println("TRACE:\n" + trace);
}
@Test public void testItUnlocksTheDeviceWithAllFalse() {
boolean[] init = {false, false, false, false};
Device d = FourBitTwoTest.buildDevice(init, 2);
assertTrue(FourBitTwoDisclosureDeviceUnlocker.unlock(d));
String trace = FourBitTwoDisclosureDeviceUnlocker.showTrace();
assertThat(trace, containsString("true"));
//System.out.println("TRACE:\n" + trace);
}
@Test public void testItUnlocksTheDeviceWhenSetRandomBits() {
Device d = FourBitTwoTest.buildDevice();
assertTrue(FourBitTwoDisclosureDeviceUnlocker.unlock(d));
String trace = FourBitTwoDisclosureDeviceUnlocker.showTrace();
assertThat(trace, containsString("true"));
System.out.println("TRACE:\n" + trace);
}
@Test public void testItFailsToUnlockWhenItsUnfair() {
UnfairTestDevice d = new UnfairTestDevice();
assertFalse(FourBitTwoDisclosureDeviceUnlocker.unlock(d));
String trace = FourBitTwoDisclosureDeviceUnlocker.showTrace();
assertThat(trace, containsString("false"));
//System.out.println("TRACE:\n" + trace);
}
@Test public void testItFailsWithFiveTwo(){
boolean[] init = {false, true, false, true, false};
Device d = FourBitTwoTest.buildDevice(init, 2);
assertFalse(FourBitTwoDisclosureDeviceUnlocker.unlock(d));
String trace = FourBitTwoDisclosureDeviceUnlocker.showTrace();
assertThat(trace, containsString("false"));
// System.out.println("TRACE:\n" + trace);
}
}