Fixed FloatMath.toString(), added tests.
This commit is contained in:
@@ -388,7 +388,11 @@ public class FloatMath
|
||||
public static String toString (float value)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(value >= 0 ? "+" : "-");
|
||||
if (value >= 0) buf.append("+");
|
||||
else {
|
||||
buf.append("-");
|
||||
value = -value;
|
||||
}
|
||||
int ivalue = (int)value;
|
||||
buf.append(ivalue);
|
||||
if (TO_STRING_DECIMAL_PLACES > 0) {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Pythagoras - a collection of geometry classes
|
||||
// http://github.com/samskivert/pythagoras
|
||||
|
||||
package pythagoras.f;
|
||||
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests parts of the {@link FloatMath} class.
|
||||
*/
|
||||
public class FloatMathTest
|
||||
{
|
||||
@Test public void testToString () {
|
||||
assertEquals("+1.0", FloatMath.toString(1f));
|
||||
assertEquals("-1.0", FloatMath.toString(-1f));
|
||||
assertEquals("+1.1", FloatMath.toString(1.1f));
|
||||
assertEquals("-1.1", FloatMath.toString(-1.1f));
|
||||
assertEquals("+3.141", FloatMath.toString(FloatMath.PI));
|
||||
assertEquals("-3.141", FloatMath.toString(-FloatMath.PI));
|
||||
|
||||
FloatMath.setToStringDecimalPlaces(5);
|
||||
assertEquals("+1.0", FloatMath.toString(1f));
|
||||
assertEquals("-1.0", FloatMath.toString(-1f));
|
||||
assertEquals("+1.1", FloatMath.toString(1.1f));
|
||||
assertEquals("-1.1", FloatMath.toString(-1.1f));
|
||||
assertEquals("+3.14159", FloatMath.toString(FloatMath.PI));
|
||||
assertEquals("-3.14159", FloatMath.toString(-FloatMath.PI));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user