Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 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 com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | |
Sho SHIMIZU | 2908d9e | 2015-05-08 16:40:06 -0700 | [diff] [blame] | 21 | import static org.hamcrest.Matchers.greaterThan; |
| 22 | import static org.hamcrest.Matchers.is; |
| 23 | import static org.hamcrest.Matchers.lessThan; |
| 24 | import static org.junit.Assert.assertThat; |
| 25 | |
Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Unit tests for Bandwidth. |
| 28 | */ |
| 29 | public class BandwidthTest { |
Sho SHIMIZU | 2908d9e | 2015-05-08 16:40:06 -0700 | [diff] [blame] | 30 | |
| 31 | private final Bandwidth small = Bandwidth.kbps(100.0); |
| 32 | private final Bandwidth large = Bandwidth.mbps(1.0); |
| 33 | |
Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Tests equality of Bandwidth instances. |
| 36 | */ |
| 37 | @Test |
| 38 | public void testEquality() { |
| 39 | new EqualsTester() |
| 40 | .addEqualityGroup(Bandwidth.kbps(1000.0), Bandwidth.kbps(1000.0), Bandwidth.mbps(1.0)) |
| 41 | .addEqualityGroup(Bandwidth.gbps(1.0)) |
| 42 | .testEquals(); |
| 43 | } |
| 44 | |
Sho SHIMIZU | 2908d9e | 2015-05-08 16:40:06 -0700 | [diff] [blame] | 45 | /** |
Sho SHIMIZU | 5c73fd9 | 2015-05-08 17:11:46 -0700 | [diff] [blame] | 46 | * Tests add operation of two Bandwidths. |
| 47 | */ |
| 48 | @Test |
| 49 | public void testAdd() { |
| 50 | Bandwidth expected = Bandwidth.kbps(1100.0); |
| 51 | |
| 52 | assertThat(small.add(large), is(expected)); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Tests subtract operation of two Bandwidths. |
| 57 | */ |
| 58 | @Test |
| 59 | public void testSubtract() { |
| 60 | Bandwidth expected = Bandwidth.kbps(900.0); |
| 61 | |
| 62 | assertThat(large.subtract(small), is(expected)); |
| 63 | } |
| 64 | |
| 65 | /** |
Sho SHIMIZU | 2908d9e | 2015-05-08 16:40:06 -0700 | [diff] [blame] | 66 | * Tests if the first object is less than the second object. |
| 67 | */ |
| 68 | @Test |
| 69 | public void testLessThan() { |
| 70 | assertThat(small, is(lessThan(large))); |
| 71 | assertThat(small.isLessThan(large), is(true)); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Tests if the first object is greater than the second object. |
| 76 | */ |
| 77 | @Test |
| 78 | public void testGreaterThan() { |
| 79 | assertThat(large, is(greaterThan(small))); |
| 80 | assertThat(large.isGreaterThan(small), is(true)); |
| 81 | } |
Sho SHIMIZU | 8169779 | 2015-05-08 11:09:38 -0700 | [diff] [blame] | 82 | } |