1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.chabala.brick.controllab;
20
21 import org.junit.Test;
22
23 import java.util.EnumSet;
24
25 import static org.hamcrest.Matchers.arrayWithSize;
26 import static org.hamcrest.Matchers.is;
27 import static org.junit.Assert.*;
28
29
30
31
32 public class OutputIdTest {
33
34 @Test
35 public void testAllOutputSetEncodesByteWithAllBitsSet() throws Exception {
36 assertThat(OutputId.encodeSetToByte(OutputId.ALL), is((byte) 0b11111111));
37 }
38
39 @Test
40 public void testOutputAEncodesByteWithLowBitSet() throws Exception {
41 assertThat(OutputId.encodeSetToByte(EnumSet.of(OutputId.A)), is((byte) 0b00000001));
42 }
43
44 @Test
45 public void testOutputHEncodesByteWithHighBitSet() throws Exception {
46 assertThat(OutputId.encodeSetToByte(EnumSet.of(OutputId.H)), is((byte) 0b10000000));
47 }
48
49 @Test
50 public void testByteWithAllBitsSetDecodesToAllOutputs() throws Exception {
51 assertThat(OutputId.decodeByteToSet((byte) 0b11111111), is(OutputId.ALL));
52 }
53
54 @Test
55 public void testByteWithLowBitSetDecodesToOutputA() throws Exception {
56 assertThat(OutputId.decodeByteToSet((byte) 0b00000001), is(EnumSet.of(OutputId.A)));
57 }
58
59 @Test
60 public void testByteWithEvenBitsSetDecodesToOutputsBDFH() throws Exception {
61 assertThat(OutputId.decodeByteToSet((byte) 0b10101010), is(EnumSet.of(OutputId.B, OutputId.D, OutputId.F, OutputId.H)));
62 }
63
64 @Test
65 public void testByteWithHighBitSetDecodesToOutputH() throws Exception {
66 assertThat(OutputId.decodeByteToSet((byte) 0b10000000), is(EnumSet.of(OutputId.H)));
67 }
68
69 @Test
70 public void testThereAreEightOutputs() throws Exception {
71 assertThat(OutputId.values(), arrayWithSize(8));
72 }
73 }