Sho SHIMIZU
Committed by Thomas Vachuska

Implement add() and subtract() methos in Bandwidth

Change-Id: I93a382cff1a441fb9c9929fc4fab82c956ccdd0e
......@@ -90,6 +90,26 @@ public final class Bandwidth implements RichComparable<Bandwidth> {
return bps;
}
/**
* Returns a Bandwidth whose value is (this + value).
*
* @param value value to be added to this Frequency
* @return this + value
*/
public Bandwidth add(Bandwidth value) {
return bps(this.bps + value.bps);
}
/**
* Returns a Bandwidth whose value is (this - value).
*
* @param value value to be added to this Frequency
* @return this - value
*/
public Bandwidth subtract(Bandwidth value) {
return bps(this.bps - value.bps);
}
@Override
public int compareTo(Bandwidth other) {
return ComparisonChain.start()
......
......@@ -43,6 +43,26 @@ public class BandwidthTest {
}
/**
* Tests add operation of two Bandwidths.
*/
@Test
public void testAdd() {
Bandwidth expected = Bandwidth.kbps(1100.0);
assertThat(small.add(large), is(expected));
}
/**
* Tests subtract operation of two Bandwidths.
*/
@Test
public void testSubtract() {
Bandwidth expected = Bandwidth.kbps(900.0);
assertThat(large.subtract(small), is(expected));
}
/**
* Tests if the first object is less than the second object.
*/
@Test
......