View Javadoc
1   /*
2    * Copyright © 2016 Greg Chabala
3    *
4    * This file is part of brick-control-lab.
5    *
6    * brick-control-lab is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Lesser General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   *
11   * brick-control-lab is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Lesser General Public License for more details.
15   *
16   * You should have received a copy of the GNU Lesser General Public License
17   * along with brick-control-lab.  If not, see http://www.gnu.org/licenses/.
18   */
19  package org.chabala.brick.controllab;
20  
21  import org.junit.Test;
22  
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  import static org.hamcrest.Matchers.arrayWithSize;
27  import static org.hamcrest.Matchers.hasSize;
28  import static org.hamcrest.Matchers.is;
29  import static org.junit.Assert.*;
30  
31  /**
32   * Testing {@link PowerLevel}.
33   */
34  public class PowerLevelTest {
35  
36      @Test
37      public void testPowerLevelZeroHasCorrectCode() throws Exception {
38          assertThat(PowerLevel.P0.getCode(), is((byte) 0b10010010));
39      }
40  
41      @Test
42      public void testPowerLevelOneHasCorrectCode() throws Exception {
43          assertThat(PowerLevel.P1.getCode(), is((byte) 0b10110000));
44      }
45  
46      @Test
47      public void testPowerLevelEightHasCorrectCode() throws Exception {
48          assertThat(PowerLevel.P8.getCode(), is((byte) 0b10110111));
49      }
50  
51      @Test
52      public void testThereAreNinePowerLevels() throws Exception {
53          assertThat(PowerLevel.values(), arrayWithSize(9));
54      }
55  
56      @Test
57      public void testEveryPowerLevelHasAUniqueCode() throws Exception {
58          Set<Byte> codes = new HashSet<>();
59          for (PowerLevel p : PowerLevel.values()) {
60              codes.add(p.getCode());
61          }
62          assertThat(codes, hasSize(PowerLevel.values().length));
63      }
64  }