Skip to content

Instantly share code, notes, and snippets.

@fsarradin
Created February 13, 2012 10:50
Show Gist options
  • Save fsarradin/1815986 to your computer and use it in GitHub Desktop.
Save fsarradin/1815986 to your computer and use it in GitHub Desktop.
Test that shows a side-effect while calling BigDecimal.stripTrailingZeros
package com.whatever
{
import org.flexunit.asserts.assertEquals;
import org.granite.math.BigDecimal;
public class BigDecimalTest {
public function BigDecimalTest() {
}
[Test]
public function should_return_value_division():void {
var value1:BigDecimal = new BigDecimal(500000000);
var value2:BigDecimal = new BigDecimal(0.02);
var result:BigDecimal = value1.multiply(value2);
// huh? this method changes the given object!?
result.stripTrailingZeros();
assertEquals("Expected " + new BigDecimal(500000000).toPlainString() + " but was " + value1.toPlainString(), 0, value1.compareTo(new BigDecimal(500000000)));
assertEquals("Expected " + new BigDecimal(0.02).toPlainString() + " but was " + value2.toPlainString(), 0, value2.compareTo(new BigDecimal(0.02)));
// it fails here :(
assertEquals("Expected " + new BigDecimal(10000000).toPlainString() + " but was " + result.toPlainString(), 0, result.compareTo(new BigDecimal(10000000)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment