Fixes #1256: Using new size logic to determine the abbreviation for a stack size
Removes the usage of the old methods, since they were pretty, but not applicable for our use case. The displayed strings are determined by the size of the to be rendered string. Now the algorithm tries to use as much width as possible before trying to trim it down. Added tests to reflect the changes and expected behaviour. Also using specific interfaces for the corresponding behaviour to shield from potential calls to the underlying enum singleton implementation.
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link appeng.util.ReadableNumberConverter}
|
||||
*
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public class LongReadableNumberConverterTest
|
||||
{
|
||||
private static final long NUMBER_LOW = 999L;
|
||||
private static final long NUMBER_NORMAL = 9999L;
|
||||
private static final long NUMBER_BORDER = 10000L;
|
||||
private static final long NUMBER_KILO = 155555L;
|
||||
private static final long NUMBER_KILO_BORDER = 9999999L;
|
||||
private static final long NUMBER_MEGA_STEP = 10000000;
|
||||
private static final long NUMBER_MEGA = 155555555L;
|
||||
private static final long NUMBER_GIGA = 155555555555L;
|
||||
private static final long NUMBER_TERA = 155555555555555L;
|
||||
private static final long NUMBER_PETA = 155555555555555555L;
|
||||
private static final long NUMBER_EXA = 1555555555555555555L;
|
||||
private static final long NUMBER_NEGATIVE_LOW = -999L;
|
||||
private static final long NUMBER_NEGATIVE_NORMAL = -9999L;
|
||||
private static final long NUMBER_NEGATIVE_GIGA = -155555555555L;
|
||||
|
||||
private static final String RESULT_LONG_LOW = "999";
|
||||
private static final String RESULT_LONG_NORMAL = "9999";
|
||||
private static final String RESULT_LONG_BORDER = "10K";
|
||||
private static final String RESULT_LONG_KILO = "155K";
|
||||
private static final String RESULT_LONG_KILO_BORDER = "9999K";
|
||||
private static final String RESULT_LONG_MEGA_STEP = "10M";
|
||||
private static final String RESULT_LONG_MEGA = "155M";
|
||||
private static final String RESULT_LONG_GIGA = "155G";
|
||||
private static final String RESULT_LONG_TERA = "155T";
|
||||
private static final String RESULT_LONG_PETA = "155P";
|
||||
private static final String RESULT_LONG_EXA = "1555P";
|
||||
private static final String RESULT_LONG_NEGATIVE_LOW = "-999";
|
||||
private static final String RESULT_LONG_NEGATIVE_NORMAL = "-9999";
|
||||
private static final String RESULT_LONG_NEGATIVE_GIGA = "-155G";
|
||||
|
||||
private final ReadableNumberConverter converter;
|
||||
|
||||
public LongReadableNumberConverterTest()
|
||||
{
|
||||
this.converter = ReadableNumberConverter.INSTANCE;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongNormal()
|
||||
{
|
||||
assertEquals( RESULT_LONG_NORMAL, this.converter.toLongHumanReadableForm( NUMBER_NORMAL ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongKiloBorder()
|
||||
{
|
||||
assertEquals( RESULT_LONG_KILO_BORDER, this.converter.toLongHumanReadableForm( NUMBER_KILO_BORDER ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongMegaStep()
|
||||
{
|
||||
assertEquals( RESULT_LONG_MEGA_STEP, this.converter.toLongHumanReadableForm( NUMBER_MEGA_STEP ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongLow()
|
||||
{
|
||||
assertEquals( RESULT_LONG_LOW, this.converter.toLongHumanReadableForm( NUMBER_LOW ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongBorder()
|
||||
{
|
||||
assertEquals( RESULT_LONG_BORDER, this.converter.toLongHumanReadableForm( NUMBER_BORDER ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongKilo()
|
||||
{
|
||||
assertEquals( RESULT_LONG_KILO, this.converter.toLongHumanReadableForm( NUMBER_KILO ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongMega()
|
||||
{
|
||||
assertEquals( RESULT_LONG_MEGA, this.converter.toLongHumanReadableForm( NUMBER_MEGA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongGiga()
|
||||
{
|
||||
assertEquals( RESULT_LONG_GIGA, this.converter.toLongHumanReadableForm( NUMBER_GIGA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongTera()
|
||||
{
|
||||
assertEquals( RESULT_LONG_TERA, this.converter.toLongHumanReadableForm( NUMBER_TERA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongPeta()
|
||||
{
|
||||
assertEquals( RESULT_LONG_PETA, this.converter.toLongHumanReadableForm( NUMBER_PETA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongExa()
|
||||
{
|
||||
assertEquals( RESULT_LONG_EXA, this.converter.toLongHumanReadableForm( NUMBER_EXA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongNegativeLow()
|
||||
{
|
||||
assertEquals( RESULT_LONG_NEGATIVE_LOW, this.converter.toLongHumanReadableForm( NUMBER_NEGATIVE_LOW ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongNegativeNormal()
|
||||
{
|
||||
assertEquals( RESULT_LONG_NEGATIVE_NORMAL, this.converter.toLongHumanReadableForm( NUMBER_NEGATIVE_NORMAL ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertLongNegativeGiga()
|
||||
{
|
||||
assertEquals( RESULT_LONG_NEGATIVE_GIGA, this.converter.toLongHumanReadableForm( NUMBER_NEGATIVE_GIGA ) );
|
||||
}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link appeng.util.ReadableNumberConverter}
|
||||
*
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public final class ReadableNumberConverterTest
|
||||
{
|
||||
private static final long NUMBER_NORMAL = 55L;
|
||||
private static final long NUMBER_KILO = 155555L;
|
||||
private static final long NUMBER_MEGA = 155555555L;
|
||||
private static final long NUMBER_GIGA = 155555555555L;
|
||||
private static final long NUMBER_TERA = 155555555555555L;
|
||||
private static final long NUMBER_PETA = 155555555555555555L;
|
||||
private static final long NUMBER_EXA = 1555555555555555555L;
|
||||
private static final long NUMBER_NEGATIVE_GIGA = -155555555555L;
|
||||
|
||||
private static final String RESULT_NORMAL = "55";
|
||||
private static final String RESULT_KILO = "155K";
|
||||
private static final String RESULT_MEGA = "155M";
|
||||
private static final String RESULT_GIGA = "155G";
|
||||
private static final String RESULT_TERA = "155T";
|
||||
private static final String RESULT_PETA = "155P";
|
||||
private static final String RESULT_EXA = "1E";
|
||||
private static final String RESULT_NEGATIVE_GIGA = "-155G";
|
||||
|
||||
private static final String RESULT_SHORT_NORMAL = "55";
|
||||
private static final String RESULT_SHORT_KILO = ".1M";
|
||||
private static final String RESULT_SHORT_MEGA = ".1G";
|
||||
private static final String RESULT_SHORT_GIGA = ".1T";
|
||||
private static final String RESULT_SHORT_TERA = ".1P";
|
||||
private static final String RESULT_SHORT_PETA = ".1E";
|
||||
private static final String RESULT_SHORT_EXA = "1E";
|
||||
private static final String RESULT_SHORT_NEGATIVE_GIGA = "-.1T";
|
||||
|
||||
private final ReadableNumberConverter converter;
|
||||
|
||||
public ReadableNumberConverterTest()
|
||||
{
|
||||
this.converter = ReadableNumberConverter.INSTANCE;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNormal()
|
||||
{
|
||||
assertEquals( RESULT_NORMAL, this.converter.toHumanReadableForm( NUMBER_NORMAL ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertKilo()
|
||||
{
|
||||
assertEquals( RESULT_KILO, this.converter.toHumanReadableForm( NUMBER_KILO ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertMega()
|
||||
{
|
||||
assertEquals( RESULT_MEGA, this.converter.toHumanReadableForm( NUMBER_MEGA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertGiga()
|
||||
{
|
||||
assertEquals( RESULT_GIGA, this.converter.toHumanReadableForm( NUMBER_GIGA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertTera()
|
||||
{
|
||||
assertEquals( RESULT_TERA, this.converter.toHumanReadableForm( NUMBER_TERA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertPeta()
|
||||
{
|
||||
assertEquals( RESULT_PETA, this.converter.toHumanReadableForm( NUMBER_PETA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertExa()
|
||||
{
|
||||
assertEquals( RESULT_EXA, this.converter.toHumanReadableForm( NUMBER_EXA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertNegativeGiga()
|
||||
{
|
||||
assertEquals( RESULT_NEGATIVE_GIGA, this.converter.toHumanReadableForm( NUMBER_NEGATIVE_GIGA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortNormal()
|
||||
{
|
||||
assertEquals( RESULT_SHORT_NORMAL, this.converter.toShortHumanReadableForm( NUMBER_NORMAL ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortKilo()
|
||||
{
|
||||
assertEquals( RESULT_SHORT_KILO, this.converter.toShortHumanReadableForm( NUMBER_KILO ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortMega()
|
||||
{
|
||||
assertEquals( RESULT_SHORT_MEGA, this.converter.toShortHumanReadableForm( NUMBER_MEGA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortGiga()
|
||||
{
|
||||
assertEquals( RESULT_SHORT_GIGA, this.converter.toShortHumanReadableForm( NUMBER_GIGA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortTera()
|
||||
{
|
||||
assertEquals( RESULT_SHORT_TERA, this.converter.toShortHumanReadableForm( NUMBER_TERA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortPeta()
|
||||
{
|
||||
assertEquals( RESULT_SHORT_PETA, this.converter.toShortHumanReadableForm( NUMBER_PETA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortExa()
|
||||
{
|
||||
assertEquals( RESULT_SHORT_EXA, this.converter.toShortHumanReadableForm( NUMBER_EXA ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertShortNegativeGiga()
|
||||
{
|
||||
assertEquals( RESULT_SHORT_NEGATIVE_GIGA, this.converter.toShortHumanReadableForm( NUMBER_NEGATIVE_GIGA ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Test for {@link ISlimReadableNumberConverter}
|
||||
*
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public final class SlimReadableNumberConverterTest
|
||||
{
|
||||
private static final long NUMBER_NEG_999999 = -999999L;
|
||||
private static final String RESULT_NEG_999999 = "-0M";
|
||||
|
||||
private static final long NUMBER_NEG_9999 = -9999L;
|
||||
private static final String RESULT_NEG_9999 = "-9K";
|
||||
|
||||
private static final long NUMBER_NEG_999 = -999L;
|
||||
private static final String RESULT_NEG_999 = "-0K";
|
||||
|
||||
private static final long NUMBER_0 = 0L;
|
||||
private static final String RESULT_0 = "0";
|
||||
|
||||
private static final long NUMBER_999 = 999L;
|
||||
private static final String RESULT_999 = "999";
|
||||
|
||||
private static final long NUMBER_9999 = 9999L;
|
||||
private static final String RESULT_9999 = "9K";
|
||||
|
||||
private static final long NUMBER_10000 = 10000L;
|
||||
private static final String RESULT_10000 = "10K";
|
||||
|
||||
private static final long NUMBER_10500 = 10500L;
|
||||
private static final String RESULT_10500 = "10K";
|
||||
|
||||
private static final long NUMBER_155555 = 155555L;
|
||||
private static final String RESULT_155555 = ".1M";
|
||||
|
||||
private static final long NUMBER_9999999 = 9999999L;
|
||||
private static final String RESULT_9999999 = "9M";
|
||||
|
||||
private static final long NUMBER_10000000 = 10000000L;
|
||||
private static final String RESULT_10000000 = "10M";
|
||||
|
||||
private static final long NUMBER_155555555 = 155555555L;
|
||||
private static final String RESULT_155555555 = ".1G";
|
||||
|
||||
private final ISlimReadableNumberConverter converter = ReadableNumberConverter.INSTANCE;
|
||||
|
||||
@Test( expected = AssertionError.class )
|
||||
public void testConvertNeg999999()
|
||||
{
|
||||
assertEquals( RESULT_NEG_999999, this.converter.toSlimReadableForm( NUMBER_NEG_999999 ) );
|
||||
}
|
||||
|
||||
@Test( expected = AssertionError.class )
|
||||
public void testConvertNeg9999()
|
||||
{
|
||||
assertEquals( RESULT_NEG_9999, this.converter.toSlimReadableForm( NUMBER_NEG_9999 ) );
|
||||
}
|
||||
|
||||
@Test( expected = AssertionError.class )
|
||||
public void testConvertNeg999()
|
||||
{
|
||||
assertEquals( RESULT_NEG_999, this.converter.toSlimReadableForm( NUMBER_NEG_999 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert0()
|
||||
{
|
||||
assertEquals( RESULT_0, this.converter.toSlimReadableForm( NUMBER_0 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert999()
|
||||
{
|
||||
assertEquals( RESULT_999, this.converter.toSlimReadableForm( NUMBER_999 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert9999()
|
||||
{
|
||||
assertEquals( RESULT_9999, this.converter.toSlimReadableForm( NUMBER_9999 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert10000()
|
||||
{
|
||||
assertEquals( RESULT_10000, this.converter.toSlimReadableForm( NUMBER_10000 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert10500()
|
||||
{
|
||||
assertEquals( RESULT_10500, this.converter.toSlimReadableForm( NUMBER_10500 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert155555()
|
||||
{
|
||||
assertEquals( RESULT_155555, this.converter.toSlimReadableForm( NUMBER_155555 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert9999999()
|
||||
{
|
||||
assertEquals( RESULT_9999999, this.converter.toSlimReadableForm( NUMBER_9999999 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert10000000()
|
||||
{
|
||||
assertEquals( RESULT_10000000, this.converter.toSlimReadableForm( NUMBER_10000000 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert155555555()
|
||||
{
|
||||
assertEquals( RESULT_155555555, this.converter.toSlimReadableForm( NUMBER_155555555 ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package appeng.util;
|
||||
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Test for {@link IWideReadableNumberConverter}
|
||||
*
|
||||
* @author thatsIch
|
||||
* @version rv2
|
||||
* @since rv2
|
||||
*/
|
||||
public final class WideReadableNumberConverterTest
|
||||
{
|
||||
private static final long NUMBER_NEG_999999 = -999999L;
|
||||
private static final String RESULT_NEG_999999 = "-0M";
|
||||
|
||||
private static final long NUMBER_NEG_9999 = -9999L;
|
||||
private static final String RESULT_NEG_9999 = "-9K";
|
||||
|
||||
private static final long NUMBER_NEG_999 = -999L;
|
||||
private static final String RESULT_NEG_999 = "-999";
|
||||
|
||||
private static final long NUMBER_0 = 0L;
|
||||
private static final String RESULT_0 = "0";
|
||||
|
||||
private static final long NUMBER_999 = 999L;
|
||||
private static final String RESULT_999 = "999";
|
||||
|
||||
private static final long NUMBER_9999 = 9999L;
|
||||
private static final String RESULT_9999 = "9999";
|
||||
|
||||
private static final long NUMBER_10000 = 10000L;
|
||||
private static final String RESULT_10000 = "10K";
|
||||
|
||||
private static final long NUMBER_10500 = 10500L;
|
||||
private static final String RESULT_10500 = "10K";
|
||||
|
||||
private static final long NUMBER_155555 = 155555L;
|
||||
private static final String RESULT_155555 = "155K";
|
||||
|
||||
private static final long NUMBER_9999999 = 9999999L;
|
||||
private static final String RESULT_9999999 = "9.9M";
|
||||
|
||||
private static final long NUMBER_10000000 = 10000000L;
|
||||
private static final String RESULT_10000000 = "10M";
|
||||
|
||||
private static final long NUMBER_155555555 = 155555555L;
|
||||
private static final String RESULT_155555555 = "155M";
|
||||
|
||||
private final IWideReadableNumberConverter converter = ReadableNumberConverter.INSTANCE;
|
||||
|
||||
@Test( expected = AssertionError.class )
|
||||
public void testConvertNeg999999()
|
||||
{
|
||||
assertEquals( RESULT_NEG_999999, this.converter.toWideReadableForm( NUMBER_NEG_999999 ) );
|
||||
}
|
||||
|
||||
@Test( expected = AssertionError.class )
|
||||
public void testConvertNeg9999()
|
||||
{
|
||||
assertEquals( RESULT_NEG_9999, this.converter.toWideReadableForm( NUMBER_NEG_9999 ) );
|
||||
}
|
||||
|
||||
@Test( expected = AssertionError.class )
|
||||
public void testConvertNeg999()
|
||||
{
|
||||
assertEquals( RESULT_NEG_999, this.converter.toWideReadableForm( NUMBER_NEG_999 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert0()
|
||||
{
|
||||
assertEquals( RESULT_0, this.converter.toWideReadableForm( NUMBER_0 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert999()
|
||||
{
|
||||
assertEquals( RESULT_999, this.converter.toWideReadableForm( NUMBER_999 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert9999()
|
||||
{
|
||||
assertEquals( RESULT_9999, this.converter.toWideReadableForm( NUMBER_9999 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert10000()
|
||||
{
|
||||
assertEquals( RESULT_10000, this.converter.toWideReadableForm( NUMBER_10000 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert10500()
|
||||
{
|
||||
assertEquals( RESULT_10500, this.converter.toWideReadableForm( NUMBER_10500 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert155555()
|
||||
{
|
||||
assertEquals( RESULT_155555, this.converter.toWideReadableForm( NUMBER_155555 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert9999999()
|
||||
{
|
||||
assertEquals( RESULT_9999999, this.converter.toWideReadableForm( NUMBER_9999999 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert10000000()
|
||||
{
|
||||
assertEquals( RESULT_10000000, this.converter.toWideReadableForm( NUMBER_10000000 ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvert155555555()
|
||||
{
|
||||
assertEquals( RESULT_155555555, this.converter.toWideReadableForm( NUMBER_155555555 ) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user