2 * This file is part of storage-units. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of storage-units,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
7 package de
.xn__ho_hia
.utils
.storage_unit
;
9 import static de
.xn__ho_hia
.utils
.storage_unit
.TestUtils
.logIncorrectCreation
;
11 import java
.math
.BigInteger
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
15 import org
.jooq
.lambda
.tuple
.Tuple2
;
16 import org
.junit
.Assert
;
17 import org
.junit
.experimental
.theories
.DataPoints
;
18 import org
.junit
.experimental
.theories
.FromDataPoints
;
19 import org
.junit
.experimental
.theories
.Theories
;
20 import org
.junit
.experimental
.theories
.Theory
;
21 import org
.junit
.runner
.RunWith
;
23 import de
.xn__ho_hia
.quality
.null_analysis
.Nullsafe
;
24 import de
.xn__ho_hia
.quality
.suppression
.CompilerWarnings
;
30 @RunWith(Theories
.class)
31 @SuppressWarnings(CompilerWarnings
.STATIC_METHOD
)
32 public class StorageUnitsBigMetricTest
{
34 private static final BigInteger MULTIPLIER
= Nullsafe
.asBigInteger(1000);
37 * @return inputs and expected result types.
40 public static List
<Tuple2
<BigInteger
, Class
<?
extends StorageUnit
<?
>>>> inputs() {
41 final List
<Tuple2
<BigInteger
, Class
<?
extends StorageUnit
<?
>>>> inputs
= new ArrayList
<>();
43 inputs
.add(new Tuple2
<>(BigInteger
.ONE
, Byte
.class));
44 inputs
.add(new Tuple2
<>(MULTIPLIER
, Kilobyte
.class));
45 inputs
.add(new Tuple2
<>(MULTIPLIER
.pow(2), Megabyte
.class));
46 inputs
.add(new Tuple2
<>(MULTIPLIER
.pow(3), Gigabyte
.class));
47 inputs
.add(new Tuple2
<>(MULTIPLIER
.pow(4), Terabyte
.class));
48 inputs
.add(new Tuple2
<>(MULTIPLIER
.pow(5), Petabyte
.class));
49 inputs
.add(new Tuple2
<>(MULTIPLIER
.pow(6), Exabyte
.class));
50 inputs
.add(new Tuple2
<>(MULTIPLIER
.pow(7), Zettabyte
.class));
51 inputs
.add(new Tuple2
<>(MULTIPLIER
.pow(8), Yottabyte
.class));
52 inputs
.add(new Tuple2
<>(MULTIPLIER
.pow(9), Yottabyte
.class));
59 * The number of bytes to wrap + the expected return class.
62 public void shouldCreateCorrectBinaryUnit(
63 @FromDataPoints("inputs") final Tuple2
<BigInteger
, Class
<?
extends StorageUnit
<?
>>> input
) {
65 final BigInteger bytes
= input
.v1
;
66 final Class
<?
extends StorageUnit
<?
>> expectedClass
= input
.v2
;
69 final StorageUnit
<?
> unit
= StorageUnits
.metricValueOf(Nullsafe
.nonNull(bytes
));
70 final Class
<?
> unitClass
= unit
.getClass();
73 Assert
.assertEquals(logIncorrectCreation(bytes
, expectedClass
, unitClass
), expectedClass
, unitClass
);
78 * The number of bytes to wrap + the expected return class.
81 public void shouldCreateCorrectBinaryUnitNegated(
82 @FromDataPoints("inputs") final Tuple2
<BigInteger
, Class
<?
extends StorageUnit
<?
>>> input
) {
84 final BigInteger bytes
= input
.v1
;
85 final Class
<?
extends StorageUnit
<?
>> expectedClass
= input
.v2
;
88 final StorageUnit
<?
> unit
= StorageUnits
.metricValueOf(Nullsafe
.nonNull(bytes
.negate()));
89 final Class
<?
> unitClass
= unit
.getClass();
92 Assert
.assertEquals(logIncorrectCreation(bytes
, expectedClass
, unitClass
), expectedClass
, unitClass
);