Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onlab.util; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | |
| 20 | import static org.hamcrest.Matchers.is; |
| 21 | import static org.junit.Assert.assertThat; |
| 22 | |
| 23 | /** |
| 24 | * Unit tests for ByteOperator. |
| 25 | */ |
| 26 | public class ByteOperatorTest { |
| 27 | |
| 28 | @Test |
| 29 | public void testGetBit() { |
Jian Li | 0a439d2 | 2017-02-06 01:05:41 +0900 | [diff] [blame] | 30 | final byte[] number = new byte[] {1, 2, 4, 8, 16, 32, 64, -128}; |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 31 | |
Jian Li | 0a439d2 | 2017-02-06 01:05:41 +0900 | [diff] [blame] | 32 | for (int i = 0; i < number.length; i++) { |
| 33 | for (int j = 0; j < 8; j++) { |
| 34 | assertThat(ByteOperator.getBit(number[i], j), is(i == j)); |
| 35 | } |
| 36 | } |
Jian Li | 4767190 | 2016-08-11 01:18:18 +0900 | [diff] [blame] | 37 | } |
| 38 | } |