2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.transport.modbus.test;
15 import static org.hamcrest.CoreMatchers.*;
16 import static org.junit.Assert.assertThat;
18 import org.junit.Test;
19 import org.openhab.io.transport.modbus.BitArray;
22 * @author Sami Salonen - Initial contribution
24 public class BasicBitArrayTest {
27 public void testGetBitAndSetBit() {
28 BitArray data1 = new BitArray(true, false, true);
29 assertThat(data1.size(), is(equalTo(3)));
30 assertThat(data1.getBit(0), is(equalTo(true)));
31 assertThat(data1.getBit(1), is(equalTo(false)));
32 assertThat(data1.getBit(2), is(equalTo(true)));
34 data1.setBit(1, true);
35 data1.setBit(2, false);
36 assertThat(data1.size(), is(equalTo(3)));
37 assertThat(data1.getBit(0), is(equalTo(true)));
38 assertThat(data1.getBit(1), is(equalTo(true)));
39 assertThat(data1.getBit(2), is(equalTo(false)));
43 public void testGetBitAndSetBit2() {
44 BitArray data1 = new BitArray(3);
45 assertThat(data1.size(), is(equalTo(3)));
46 assertThat(data1.getBit(0), is(equalTo(false)));
47 assertThat(data1.getBit(1), is(equalTo(false)));
48 assertThat(data1.getBit(2), is(equalTo(false)));
50 data1.setBit(1, true);
51 assertThat(data1.size(), is(equalTo(3)));
52 assertThat(data1.getBit(0), is(equalTo(false)));
53 assertThat(data1.getBit(1), is(equalTo(true)));
54 assertThat(data1.getBit(2), is(equalTo(false)));
56 data1.setBit(1, false);
57 assertThat(data1.size(), is(equalTo(3)));
58 assertThat(data1.getBit(0), is(equalTo(false)));
59 assertThat(data1.getBit(1), is(equalTo(false)));
60 assertThat(data1.getBit(2), is(equalTo(false)));
63 @Test(expected = IndexOutOfBoundsException.class)
64 public void testOutOfBounds() {
65 BitArray data1 = new BitArray(true, false, true);
69 @Test(expected = IndexOutOfBoundsException.class)
70 public void testOutOfBounds2() {
71 BitArray data1 = new BitArray(true, false, true);
75 @Test(expected = IndexOutOfBoundsException.class)
76 public void testOutOfBounds3() {
77 BitArray data1 = new BitArray(3);
81 @Test(expected = IndexOutOfBoundsException.class)
82 public void testOutOfBounds4() {
83 BitArray data1 = new BitArray(3);