blob: 5c91bb12c8d0ab6d7a2b41e0e7faefdb5d115420 [file] [log] [blame]
Sho SHIMIZU81697792015-05-08 11:09:38 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Sho SHIMIZU81697792015-05-08 11:09:38 -07003 *
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 com.google.common.testing.EqualsTester;
19import org.junit.Test;
20
Sho SHIMIZU2908d9e2015-05-08 16:40:06 -070021import static org.hamcrest.Matchers.greaterThan;
22import static org.hamcrest.Matchers.is;
23import static org.hamcrest.Matchers.lessThan;
24import static org.junit.Assert.assertThat;
25
Sho SHIMIZU81697792015-05-08 11:09:38 -070026/**
27 * Unit tests for Bandwidth.
28 */
29public class BandwidthTest {
Sho SHIMIZU2908d9e2015-05-08 16:40:06 -070030
31 private final Bandwidth small = Bandwidth.kbps(100.0);
32 private final Bandwidth large = Bandwidth.mbps(1.0);
33
Sho SHIMIZU81697792015-05-08 11:09:38 -070034 /**
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 SHIMIZU2908d9e2015-05-08 16:40:06 -070045 /**
Sho SHIMIZU5c73fd92015-05-08 17:11:46 -070046 * 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 SHIMIZU2908d9e2015-05-08 16:40:06 -070066 * 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 SHIMIZU81697792015-05-08 11:09:38 -070082}