Skip to content

Commit

Permalink
- NUnit Tests for straighten consistency
Browse files Browse the repository at this point in the history
- Some documentation
  • Loading branch information
tsutomi committed May 4, 2015
1 parent 3712b0c commit b8336b6
Show file tree
Hide file tree
Showing 5 changed files with 240 additions and 575 deletions.
4 changes: 2 additions & 2 deletions nuget/dmath.pcl.tmpl.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<tags>math decimal bigdecimal integer biginteger int deveel harmony portable</tags>
</metadata>
<files>
<file src="..\dist\$platform$\pcl\Deveel.Math.dll" target="lib/portable-net40+sl50+win+wpa81+wp80/Deveel.Math.dll"/>
<file src="..\dist\$platform$\pcl\Deveel.Math.dll" target="lib/portable-net40+sl50+win+wpa81+wp80/Deveel.Math.pdb"/>
<file src="..\dist\anycpu\pcl\Deveel.Math.dll" target="lib/portable-net40+sl50+win+wpa81+wp80/Deveel.Math.dll"/>
<file src="..\dist\anycpu\pcl\Deveel.Math.dll" target="lib/portable-net40+sl50+win+wpa81+wp80/Deveel.Math.pdb"/>
</files>
</package>
107 changes: 45 additions & 62 deletions src/Deveel.Math.NUnit/Deveel.Math/BigDecimalArithmeticTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,80 +177,67 @@ public void DivideByZero() {
Assert.Throws<ArithmeticException>(() => aNumber.Divide(bNumber), "ArithmeticException has not been caught");
}

/**
* Divide with ROUND_UNNECESSARY
*/
[Test]
public void DivideExceptionRM() {
public void DivideExceptionRoundingMode() {
String a = "1231212478987482988429808779810457634781384756794987";
int aScale = 15;
const int aScale = 15;
String b = "747233429293018787918347987234564568";
int bScale = 10;
const int bScale = 10;
BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
try {
aNumber.Divide(bNumber, RoundingMode.Unnecessary);
Assert.Fail("ArithmeticException has not been caught");
} catch (ArithmeticException e) {
Assert.AreEqual("Rounding necessary", e.Message, "Improper exception message");
}
Assert.Throws<ArithmeticException>(() => aNumber.Divide(bNumber, RoundingMode.Unnecessary));
}

/**
* Divide with invalid rounding mode
*/
[Test]
public void DivideExceptionInvalidRM() {
public void DivideExceptionInvalidRoundingMode() {
String a = "1231212478987482988429808779810457634781384756794987";
int aScale = 15;
const int aScale = 15;
String b = "747233429293018787918347987234564568";
int bScale = 10;
const int bScale = 10;
BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
Assert.Throws<ArgumentException>(() => aNumber.Divide(bNumber, 100));
}

/**
* Divide: local variable exponent is less than zero
*/
[Test]
public void DivideExpLessZero() {
String a = "1231212478987482988429808779810457634781384756794987";
int aScale = 15;
String b = "747233429293018787918347987234564568";
int bScale = 10;
String c = "1.64770E+10";
int resScale = -5;
// Divide: local variable exponent is less than zero

const string a = "1231212478987482988429808779810457634781384756794987";
const int aScale = 15;
const string b = "747233429293018787918347987234564568";
const int bScale = 10;
string c = "1.64770E+10";
const int resScale = -5;

BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
BigDecimal result = aNumber.Divide(bNumber, resScale, RoundingMode.Ceiling);
Assert.AreEqual(c, result.ToString(), "incorrect value");
Assert.AreEqual(resScale, result.Scale, "incorrect scale");
}

/**
* Divide: local variable exponent is equal to zero
*/
[Test]
public void DivideExpEqualsZero() {
String a = "1231212478987482988429808779810457634781384756794987";
int aScale = -15;
String b = "747233429293018787918347987234564568";
int bScale = 10;
String c = "1.64769459009933764189139568605273529E+40";
int resScale = -5;
// Divide: local variable exponent is equal to zero

const string a = "1231212478987482988429808779810457634781384756794987";
const int aScale = -15;
string b = "747233429293018787918347987234564568";
const int bScale = 10;
string c = "1.64769459009933764189139568605273529E+40";
const int resScale = -5;
BigDecimal aNumber = new BigDecimal(BigInteger.Parse(a), aScale);
BigDecimal bNumber = new BigDecimal(BigInteger.Parse(b), bScale);
BigDecimal result = aNumber.Divide(bNumber, resScale, RoundingMode.Ceiling);
Assert.AreEqual(c, result.ToString(), "incorrect value");
Assert.AreEqual(resScale, result.Scale, "incorrect scale");
}

/**
* Divide: local variable exponent is greater than zero
*/
[Test]
public void DivideExpGreaterZero() {
// Divide: local variable exponent is greater than zero

String a = "1231212478987482988429808779810457634781384756794987";
int aScale = -15;
String b = "747233429293018787918347987234564568";
Expand Down Expand Up @@ -736,7 +723,7 @@ public void DivideBigDecimal2() {
* divide(BigDecimal, scale, RoundingMode)
*/
[Test]
public void DivideBigDecimalScaleRoundingModeUP() {
public void DivideBigDecimalScaleRoundingModeUp() {
String a = "-37361671119238118911893939591735";
int aScale = 10;
String b = "74723342238476237823787879183470";
Expand All @@ -755,7 +742,7 @@ public void DivideBigDecimalScaleRoundingModeUP() {
* divide(BigDecimal, scale, RoundingMode)
*/
[Test]
public void DivideBigDecimalScaleRoundingModeDOWN() {
public void DivideBigDecimalScaleRoundingModeDown() {
String a = "-37361671119238118911893939591735";
int aScale = 10;
String b = "74723342238476237823787879183470";
Expand All @@ -774,7 +761,7 @@ public void DivideBigDecimalScaleRoundingModeDOWN() {
* divide(BigDecimal, scale, RoundingMode)
*/
[Test]
public void DivideBigDecimalScaleRoundingModeCEILING() {
public void DivideBigDecimalScaleRoundingModeCeiling() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 100;
String b = "74723342238476237823787879183470";
Expand All @@ -793,7 +780,7 @@ public void DivideBigDecimalScaleRoundingModeCEILING() {
* divide(BigDecimal, scale, RoundingMode)
*/
[Test]
public void DivideBigDecimalScaleRoundingModeFLOOR() {
public void DivideBigDecimalScaleRoundingModeFloor() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 100;
String b = "74723342238476237823787879183470";
Expand All @@ -812,7 +799,7 @@ public void DivideBigDecimalScaleRoundingModeFLOOR() {
* divide(BigDecimal, scale, RoundingMode)
*/
[Test]
public void DivideBigDecimalScaleRoundingModeHALF_UP() {
public void DivideBigDecimalScaleRoundingModeHalfUp() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = -51;
String b = "74723342238476237823787879183470";
Expand All @@ -833,7 +820,7 @@ public void DivideBigDecimalScaleRoundingModeHALF_UP() {
* divide(BigDecimal, scale, RoundingMode)
*/
[Test]
public void DivideBigDecimalScaleRoundingModeHALF_DOWN() {
public void DivideBigDecimalScaleRoundingModeHalfDown() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 5;
String b = "74723342238476237823787879183470";
Expand All @@ -852,7 +839,7 @@ public void DivideBigDecimalScaleRoundingModeHALF_DOWN() {
* divide(BigDecimal, scale, RoundingMode)
*/
[Test]
public void DivideBigDecimalScaleRoundingModeHALF_EVEN() {
public void DivideBigDecimalScaleRoundingModeHalfEven() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 5;
String b = "74723342238476237823787879183470";
Expand All @@ -871,7 +858,7 @@ public void DivideBigDecimalScaleRoundingModeHALF_EVEN() {
* divide(BigDecimal, MathContext)
*/
[Test]
public void DivideBigDecimalScaleMathContextUP() {
public void DivideBigDecimalScaleMathContextUp() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 15;
String b = "748766876876723342238476237823787879183470";
Expand All @@ -892,7 +879,7 @@ public void DivideBigDecimalScaleMathContextUP() {
* divide(BigDecimal, MathContext)
*/
[Test]
public void DivideBigDecimalScaleMathContextDOWN() {
public void DivideBigDecimalScaleMathContextDown() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 15;
String b = "748766876876723342238476237823787879183470";
Expand All @@ -913,7 +900,7 @@ public void DivideBigDecimalScaleMathContextDOWN() {
* divide(BigDecimal, MathContext)
*/
[Test]
public void DivideBigDecimalScaleMathContextCEILING() {
public void DivideBigDecimalScaleMathContextCeiling() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 15;
String b = "748766876876723342238476237823787879183470";
Expand All @@ -934,7 +921,7 @@ public void DivideBigDecimalScaleMathContextCEILING() {
* divide(BigDecimal, MathContext)
*/
[Test]
public void DivideBigDecimalScaleMathContextFLOOR() {
public void DivideBigDecimalScaleMathContextFloor() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 15;
String b = "748766876876723342238476237823787879183470";
Expand Down Expand Up @@ -976,7 +963,7 @@ public void DivideBigDecimalScaleMathContextHALF_UP() {
* divide(BigDecimal, MathContext)
*/
[Test]
public void DivideBigDecimalScaleMathContextHALF_DOWN() {
public void DivideBigDecimalScaleMathContextHalfDown() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
Expand All @@ -997,7 +984,7 @@ public void DivideBigDecimalScaleMathContextHALF_DOWN() {
* divide(BigDecimal, MathContext)
*/
[Test]
public void DivideBigDecimalScaleMathContextHALF_EVEN() {
public void DivideBigDecimalScaleMathContextHalfEven() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
Expand All @@ -1024,12 +1011,8 @@ public void DivideBigDecimalScaleMathContextHALF_EVEN() {
public void DivideLargeScale() {
BigDecimal arg1 = BigDecimal.Parse("320.0E+2147483647");
BigDecimal arg2 = BigDecimal.Parse("6E-2147483647");
try {
BigDecimal result = arg1.Divide(arg2, Int32.MaxValue, RoundingMode.Ceiling);
Assert.Fail("Expected ArithmeticException when dividing with a scale that's too large");
} catch (ArithmeticException e) {
// expected behaviour
}
Assert.Throws<ArithmeticException>(() => arg1.Divide(arg2, Int32.MaxValue, RoundingMode.Ceiling),
"Expected ArithmeticException when dividing with a scale that's too large");
}

/**
Expand All @@ -1054,7 +1037,7 @@ public void DivideToIntegralValue() {
* divideToIntegralValue(BigDecimal, MathContext)
*/
[Test]
public void DivideToIntegralValueMathContextUP() {
public void DivideToIntegralValueMathContextUp() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
Expand All @@ -1075,7 +1058,7 @@ public void DivideToIntegralValueMathContextUP() {
* divideToIntegralValue(BigDecimal, MathContext)
*/
[Test]
public void DivideToIntegralValueMathContextDOWN() {
public void DivideToIntegralValueMathContextDown() {
String a = "3736186567876876578956958769675785435673453453653543654354365435675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
Expand Down Expand Up @@ -1144,7 +1127,7 @@ public void DivideAndRemainder2() {
* divideAndRemainder(BigDecimal, MathContext)
*/
[Test]
public void DivideAndRemainderMathContextUP() {
public void DivideAndRemainderMathContextUp() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
Expand All @@ -1170,7 +1153,7 @@ public void DivideAndRemainderMathContextUP() {
* divideAndRemainder(BigDecimal, MathContext)
*/
[Test]
public void DivideAndRemainderMathContextDOWN() {
public void DivideAndRemainderMathContextDown() {
String a = "3736186567876876578956958765675671119238118911893939591735";
int aScale = 45;
String b = "134432345432345748766876876723342238476237823787879183470";
Expand Down
Loading

0 comments on commit b8336b6

Please sign in to comment.