fix #22
[storage-units.git] / storage-units / src / test / java / de / xn__ho_hia / storage_unit / StorageUnitsBigBinaryTest.java
blob9de7c5075764449e0054651d667e0744ceb80fd8
1 /*
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
5 * in the LICENSE file.
6 */
7 package de.xn__ho_hia.storage_unit;
9 import static de.xn__ho_hia.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;
26 /**
30 @RunWith(Theories.class)
31 @SuppressWarnings(CompilerWarnings.STATIC_METHOD)
32 public class StorageUnitsBigBinaryTest {
34 private static final BigInteger MULTIPLIER = Nullsafe.asBigInteger(1024);
36 /**
37 * @return inputs and expected result types.
39 @DataPoints("inputs")
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, Kibibyte.class));
45 inputs.add(new Tuple2<>(MULTIPLIER.pow(2), Mebibyte.class));
46 inputs.add(new Tuple2<>(MULTIPLIER.pow(3), Gibibyte.class));
47 inputs.add(new Tuple2<>(MULTIPLIER.pow(4), Tebibyte.class));
48 inputs.add(new Tuple2<>(MULTIPLIER.pow(5), Pebibyte.class));
49 inputs.add(new Tuple2<>(MULTIPLIER.pow(6), Exbibyte.class));
50 inputs.add(new Tuple2<>(MULTIPLIER.pow(7), Zebibyte.class));
51 inputs.add(new Tuple2<>(MULTIPLIER.pow(8), Yobibyte.class));
52 inputs.add(new Tuple2<>(MULTIPLIER.pow(9), Yobibyte.class));
54 return inputs;
57 /**
58 * @param input
59 * The number of bytes to wrap + the expected return class.
61 @Theory
62 public void shouldCreateCorrectBinaryUnit(
63 @FromDataPoints("inputs") final Tuple2<BigInteger, Class<? extends StorageUnit<?>>> input) {
64 // given
65 final BigInteger bytes = input.v1;
66 final Class<? extends StorageUnit<?>> expectedClass = input.v2;
68 // when
69 final StorageUnit<?> unit = StorageUnits.binaryValueOf(Nullsafe.nonNull(bytes));
70 final Class<?> unitClass = unit.getClass();
72 // then
73 Assert.assertEquals(logIncorrectCreation(bytes, expectedClass, unitClass), expectedClass, unitClass);
76 /**
77 * @param input
78 * The number of bytes to wrap + the expected return class.
80 @Theory
81 public void shouldCreateCorrectBinaryUnitNegated(
82 @FromDataPoints("inputs") final Tuple2<BigInteger, Class<? extends StorageUnit<?>>> input) {
83 // given
84 final BigInteger bytes = input.v1;
85 final Class<? extends StorageUnit<?>> expectedClass = input.v2;
87 // when
88 final StorageUnit<?> unit = StorageUnits.binaryValueOf(Nullsafe.nonNull(bytes.negate()));
89 final Class<?> unitClass = unit.getClass();
91 // then
92 Assert.assertEquals(logIncorrectCreation(bytes, expectedClass, unitClass), expectedClass, unitClass);