Committed by
Thomas Vachuska
Implement add() and subtract() methos in Bandwidth
Change-Id: I93a382cff1a441fb9c9929fc4fab82c956ccdd0e
Showing
2 changed files
with
40 additions
and
0 deletions
| ... | @@ -90,6 +90,26 @@ public final class Bandwidth implements RichComparable<Bandwidth> { | ... | @@ -90,6 +90,26 @@ public final class Bandwidth implements RichComparable<Bandwidth> { |
| 90 | return bps; | 90 | return bps; |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | + /** | ||
| 94 | + * Returns a Bandwidth whose value is (this + value). | ||
| 95 | + * | ||
| 96 | + * @param value value to be added to this Frequency | ||
| 97 | + * @return this + value | ||
| 98 | + */ | ||
| 99 | + public Bandwidth add(Bandwidth value) { | ||
| 100 | + return bps(this.bps + value.bps); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * Returns a Bandwidth whose value is (this - value). | ||
| 105 | + * | ||
| 106 | + * @param value value to be added to this Frequency | ||
| 107 | + * @return this - value | ||
| 108 | + */ | ||
| 109 | + public Bandwidth subtract(Bandwidth value) { | ||
| 110 | + return bps(this.bps - value.bps); | ||
| 111 | + } | ||
| 112 | + | ||
| 93 | @Override | 113 | @Override |
| 94 | public int compareTo(Bandwidth other) { | 114 | public int compareTo(Bandwidth other) { |
| 95 | return ComparisonChain.start() | 115 | return ComparisonChain.start() | ... | ... |
| ... | @@ -43,6 +43,26 @@ public class BandwidthTest { | ... | @@ -43,6 +43,26 @@ public class BandwidthTest { |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| 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 | + /** | ||
| 46 | * Tests if the first object is less than the second object. | 66 | * Tests if the first object is less than the second object. |
| 47 | */ | 67 | */ |
| 48 | @Test | 68 | @Test | ... | ... |
-
Please register or login to post a comment