blob: 21dffbefd9efdd05410e45f3e0c08d4e21b94978 [file] [log] [blame]
Jian Li47671902016-08-11 01:18:18 +09001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onlab.util;
17
18import org.junit.Test;
19
20import static org.hamcrest.Matchers.is;
21import static org.junit.Assert.assertThat;
22
23/**
24 * Unit tests for ByteOperator.
25 */
26public class ByteOperatorTest {
27
28 @Test
29 public void testGetBit() {
30 byte eight = 0x08;
31 assertThat(ByteOperator.getBit(eight, 0), is(false));
32 assertThat(ByteOperator.getBit(eight, 1), is(false));
33 assertThat(ByteOperator.getBit(eight, 2), is(false));
34 assertThat(ByteOperator.getBit(eight, 3), is(true));
35 assertThat(ByteOperator.getBit(eight, 4), is(false));
36 assertThat(ByteOperator.getBit(eight, 5), is(false));
37 assertThat(ByteOperator.getBit(eight, 6), is(false));
38 assertThat(ByteOperator.getBit(eight, 7), is(false));
39
40 byte one = 0x01;
41 assertThat(ByteOperator.getBit(one, 0), is(true));
42 assertThat(ByteOperator.getBit(one, 1), is(false));
43 assertThat(ByteOperator.getBit(one, 2), is(false));
44 assertThat(ByteOperator.getBit(one, 3), is(false));
45 assertThat(ByteOperator.getBit(one, 4), is(false));
46 assertThat(ByteOperator.getBit(one, 5), is(false));
47 assertThat(ByteOperator.getBit(one, 6), is(false));
48 assertThat(ByteOperator.getBit(one, 7), is(false));
49 }
50}