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:
thatsIch 2015-04-12 22:33:47 +02:00
parent 817163dbf6
commit cc29230ce5
10 changed files with 406 additions and 390 deletions

View file

@ -30,12 +30,21 @@ import net.minecraft.item.ItemStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.core.AEConfig;
import appeng.core.localization.GuiText;
import appeng.util.ISlimReadableNumberConverter;
import appeng.util.IWideReadableNumberConverter;
import appeng.util.ReadableNumberConverter;
/**
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @since rv0
*/
public class AppEngRenderItem extends RenderItem
{
private static final ReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
private static final ISlimReadableNumberConverter SLIM_CONVERTER = ReadableNumberConverter.INSTANCE;
private static final IWideReadableNumberConverter WIDE_CONVERTER = ReadableNumberConverter.INSTANCE;
public IAEItemStack aeStack;
@ -125,11 +134,11 @@ public class AppEngRenderItem extends RenderItem
{
if( AEConfig.instance.useTerminalUseLargeFont() )
{
return NUMBER_CONVERTER.toShortHumanReadableForm( originalSize );
return SLIM_CONVERTER.toSlimReadableForm( originalSize );
}
else
{
return NUMBER_CONVERTER.toLongHumanReadableForm( originalSize );
return WIDE_CONVERTER.toWideReadableForm( originalSize );
}
}
}

View file

@ -37,13 +37,20 @@ import appeng.client.ClientHelper;
import appeng.core.AELog;
import appeng.tile.AEBaseTile;
import appeng.tile.crafting.TileCraftingMonitorTile;
import appeng.util.IWideReadableNumberConverter;
import appeng.util.Platform;
import appeng.util.ReadableNumberConverter;
/**
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @since rv1
*/
public class RenderBlockCraftingCPUMonitor extends RenderBlockCraftingCPU
{
private static final ReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
private static final IWideReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
public RenderBlockCraftingCPUMonitor()
{
@ -177,7 +184,7 @@ public class RenderBlockCraftingCPUMonitor extends RenderBlockCraftingCPU
GL11.glScalef( 1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f );
final long stackSize = ais.getStackSize();
final String renderedStackSize = NUMBER_CONVERTER.toHumanReadableForm( stackSize );
final String renderedStackSize = NUMBER_CONVERTER.toWideReadableForm( stackSize );
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
int width = fr.getStringWidth( renderedStackSize );

View file

@ -59,14 +59,21 @@ import appeng.core.AELog;
import appeng.core.localization.PlayerMessages;
import appeng.helpers.Reflected;
import appeng.me.GridAccessException;
import appeng.util.IWideReadableNumberConverter;
import appeng.util.Platform;
import appeng.util.ReadableNumberConverter;
import appeng.util.item.AEItemStack;
/**
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @since rv0
*/
public class PartStorageMonitor extends PartMonitor implements IPartStorageMonitor, IStackWatcherHost
{
private static final ReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
private static final IWideReadableNumberConverter NUMBER_CONVERTER = ReadableNumberConverter.INSTANCE;
IAEItemStack configuredItem;
boolean isLocked;
IStackWatcher myWatcher;
@ -341,7 +348,7 @@ public class PartStorageMonitor extends PartMonitor implements IPartStorageMonit
GL11.glScalef( 1.0f / 62.0f, 1.0f / 62.0f, 1.0f / 62.0f );
final long stackSize = ais.getStackSize();
final String renderedStackSize = NUMBER_CONVERTER.toHumanReadableForm( stackSize );
final String renderedStackSize = NUMBER_CONVERTER.toWideReadableForm( stackSize );
FontRenderer fr = Minecraft.getMinecraft().fontRenderer;
int width = fr.getStringWidth( renderedStackSize );

View file

@ -0,0 +1,31 @@
package appeng.util;
import javax.annotation.Nonnegative;
/**
* Limits a number converter to a char width of at max 3 characters.
* This is generally used for players, who activated the large font extension.
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public interface ISlimReadableNumberConverter
{
/**
* Converts a number into a human readable form. It will not round the number, but down it.
* Will try to cut the number down 1 decimal later, but rarely because of the 3 width limitation.
* Can only handle non negative numbers
*
* Example:
* 10000L -> 10K
* 9999L -> 9K, not 9.9K cause 4 width
*
* @param number to be converted number
*
* @return String in SI format cut down as far as possible
*/
String toSlimReadableForm( @Nonnegative long number );
}

View file

@ -0,0 +1,30 @@
package appeng.util;
import javax.annotation.Nonnegative;
/**
* Limits a number converter to a char width of at max 4 characters
*
* @author thatsIch
* @version rv2
* @since rv2
*/
public interface IWideReadableNumberConverter
{
/**
* Converts a number into a human readable form. It will not round the number, but down it.
* Will try to cut the number down 1 decimal later if width can be below 4.
* Can only handle non negative numbers
*
* Example:
* 10000L -> 10K
* 9999L -> 9999
*
* @param number to be converted number
*
* @return String in SI format cut down as far as possible
*/
String toWideReadableForm( @Nonnegative long number );
}

View file

@ -1,6 +1,12 @@
package appeng.util;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.Format;
/**
* Converter class to convert a large number into a SI system.
*
@ -8,7 +14,7 @@ package appeng.util;
* @version rv2
* @since rv2
*/
public enum ReadableNumberConverter
public enum ReadableNumberConverter implements ISlimReadableNumberConverter, IWideReadableNumberConverter
{
INSTANCE;
@ -17,125 +23,82 @@ public enum ReadableNumberConverter
*/
private static final int DIVISION_BASE = 1000;
/**
* for lg(1000) = 3, just saves some calculation
*/
private static final double LOG_DIVISION_BASE = Math.log( DIVISION_BASE );
/**
* String representation of the sorted postfixes
*/
private static final char[] ENCODED_POSTFIXES = "KMGTPE".toCharArray();
/**
* if a result would be higher than this threshold,
* it is pushed into the next bigger group,
* so the display string is shorter
*/
private static final int SHORT_THRESHOLD = 100;
private final Format format;
/**
* Converts a number into a human readable form. It will not round the number, but floor it.
*
* Example: 15555L -> 15.5K
*
* @param number to be converted number
*
* @return String in SI format cut down as far as possible
* Initializes the specific decimal format with special format for negative and positive numbers
*/
public String toHumanReadableForm( long number )
ReadableNumberConverter()
{
final String sign = this.getSign( number );
final long absNumber = Math.abs( number );
final DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator( '.' );
final DecimalFormat format = new DecimalFormat( ".#;0.#" );
format.setDecimalFormatSymbols( symbols );
format.setRoundingMode( RoundingMode.DOWN );
if( absNumber < DIVISION_BASE )
return Long.toString( number );
this.format = format;
}
final int exp = (int) ( Math.log( absNumber ) / LOG_DIVISION_BASE );
final char postFix = ENCODED_POSTFIXES[exp - 1];
final int result = (int) ( absNumber / Math.pow( DIVISION_BASE, exp ) );
return String.format( "%s%d%s", sign, result, postFix );
@Override
public String toSlimReadableForm( long number )
{
return this.toReadableFormRestrictedByWidth( number, 3 );
}
/**
* Gets character representation of the sign of a number
* restricts a string representation of a number to a specific width
*
* @param number maybe signed number
* @param number to be formatted number
* @param width width limitation of the resulting number
*
* @return '-' if the number is signed, else an empty character
* @return formatted number restricted by the width limitation
*/
private String getSign( long number )
private String toReadableFormRestrictedByWidth( long number, int width )
{
if( number < 0 )
assert number >= 0;
// handles low numbers more efficiently since no format is needed
final String numberString = Long.toString( number );
int numberSize = numberString.length();
if( numberSize <= width )
return numberString;
long base = number;
double last = base * 1000;
int exponent = -1;
String postFix = "";
while( numberSize > width )
{
return "-";
}
else
{
return "";
last = base;
base /= DIVISION_BASE;
exponent++;
// adds +1 due to the postfix
numberSize = Long.toString( base ).length() + 1;
postFix = String.valueOf( ENCODED_POSTFIXES[exponent] );
}
final String withPrecision = this.format.format( last / DIVISION_BASE ) + postFix;
final String withoutPrecision = Long.toString( base ) + postFix;
final String slimResult = ( withPrecision.length() <= width ) ? withPrecision : withoutPrecision;
// post condition
assert slimResult.length() <= width;
return slimResult;
}
/**
* Converts a number into a human readable form. It will not round the number, but floor it.
* Will try to cut the number down 1 decimal earlier. This will limit the String size to 3 chars.
*
* Example: 900L -> 0.9K
*
* @param number to be converted number
*
* @return String in SI format cut down as far as possible
*/
public String toShortHumanReadableForm( long number )
@Override
public String toWideReadableForm( final long number )
{
final String sign = this.getSign( number );
final long absNumber = Math.abs( number );
if( absNumber < DIVISION_BASE )
return Long.toString( number );
final int exp = (int) ( Math.log( absNumber ) / LOG_DIVISION_BASE );
final int result = (int) ( absNumber / Math.pow( DIVISION_BASE, exp ) );
if( result >= SHORT_THRESHOLD )
{
final int shortResult = result / SHORT_THRESHOLD;
final char postFix = ENCODED_POSTFIXES[exp];
return String.format( "%s.%d%s", sign, shortResult, postFix );
}
else
{
final char postFix = ENCODED_POSTFIXES[exp - 1];
return String.format( "%s%d%s", sign, result, postFix );
}
}
/**
* Converts a number into a human readable form. It will not round the number, but floor it.
* Will try to cut the number down 1 decimal later.
*
* Example:
* 10000L -> 10K
* 9999L -> 9999
*
* @param number to be converted number
*
* @return String in SI format cut down as far as possible
*/
public String toLongHumanReadableForm( long number )
{
final String sign = this.getSign( number );
final long absNumber = Math.abs( number );
if( absNumber < 10 * DIVISION_BASE )
return Long.toString( number );
final int exp = (int) ( Math.log( absNumber / 10 ) / LOG_DIVISION_BASE );
final int result = (int) ( absNumber / Math.pow( DIVISION_BASE, exp ) );
final char postFix = ENCODED_POSTFIXES[exp - 1];
return String.format( "%s%d%s", sign, result, postFix );
return this.toReadableFormRestrictedByWidth( number, 4 );
}
}

View file

@ -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 ) );
}
}

View file

@ -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 ) );
}
}

View file

@ -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 ) );
}
}

View file

@ -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 ) );
}
}