blob: bd5d176095e20f160b3c89fb630e05f52f524765 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.binaryprefix;
import junit.framework.TestCase;
/**
* @author tonytv
*/
public class BinaryScaledAmountTestCase extends TestCase {
public void testConversion() {
BinaryScaledAmount oneMeg = new BinaryScaledAmount(1024, BinaryPrefix.kilo);
assertEquals(1, oneMeg.as(BinaryPrefix.mega));
assertEquals(1024, oneMeg.as(BinaryPrefix.kilo));
assertEquals(1024*1024, oneMeg.as(BinaryPrefix.unit));
assertEquals(1 << 20, oneMeg.hashCode());
Object v = this;
assertEquals(false, oneMeg.equals(v));
v = new BinaryScaledAmount(1, BinaryPrefix.mega);
assertEquals(true, oneMeg.equals(v));
}
public void testSymbols() {
BinaryScaledAmount oneMeg = new BinaryScaledAmount(1024, BinaryPrefix.kilo);
assertEquals(1, oneMeg.as(BinaryPrefix.fromSymbol('M')));
assertEquals(1024, oneMeg.as(BinaryPrefix.fromSymbol('K')));
boolean ex = false;
try {
BinaryPrefix invalid = BinaryPrefix.fromSymbol('q');
} catch (RuntimeException e) {
ex = true;
}
assertEquals(true, ex);
}
}
|