added extensions for BigInteger and BigDecimal
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package std.math
|
||||
|
||||
import java.math.BigInteger
|
||||
import java.math.BigDecimal
|
||||
|
||||
fun BigInteger.plus(other: BigInteger) = this.add(other).sure()
|
||||
|
||||
fun BigInteger.minus(other: BigInteger) = this.subtract(other).sure()
|
||||
|
||||
fun BigInteger.times(other: BigInteger) = this.multiply(other).sure()
|
||||
|
||||
fun BigInteger.div(other: BigInteger) = this.divide(other).sure()
|
||||
|
||||
fun BigInteger.minus() = this.negate().sure()
|
||||
|
||||
|
||||
fun BigDecimal.plus(other: BigDecimal) = this.add(other).sure()
|
||||
|
||||
fun BigDecimal.minus(other: BigDecimal) = this.subtract(other).sure()
|
||||
|
||||
fun BigDecimal.times(other: BigDecimal) = this.multiply(other).sure()
|
||||
|
||||
fun BigDecimal.div(other: BigDecimal) = this.divide(other).sure()
|
||||
|
||||
fun BigDecimal.mod(other: BigDecimal) = this.remainder(other).sure()
|
||||
|
||||
fun BigDecimal.minus() = this.negate().sure()
|
||||
@@ -0,0 +1,39 @@
|
||||
package test.collections;
|
||||
|
||||
import std.math.*
|
||||
import java.math.BigInteger
|
||||
import java.math.BigDecimal
|
||||
|
||||
import stdhack.test.*
|
||||
|
||||
class MathTest : TestSupport() {
|
||||
fun testBigInteger() {
|
||||
val a = BigInteger("2")
|
||||
val b = BigInteger("3")
|
||||
|
||||
assertEquals(BigInteger("5"), a + b)
|
||||
assertEquals(BigInteger("-1"), a - b)
|
||||
assertEquals(BigInteger("6"), a * b)
|
||||
assertEquals(BigInteger("0"), a / b)
|
||||
assertEquals(BigInteger("-2"), -a)
|
||||
assertEquals(BigInteger("1"), -a % b)
|
||||
assertEquals(BigInteger("-2"), -a remainder b)
|
||||
}
|
||||
|
||||
fun testBigDecimal() {
|
||||
val a = BigDecimal("2")
|
||||
val b = BigDecimal("3")
|
||||
|
||||
assertEquals(BigDecimal("5"), a + b)
|
||||
assertEquals(BigDecimal("-1"), a - b)
|
||||
assertEquals(BigDecimal("6"), a * b)
|
||||
assertEquals(BigDecimal("2"), BigDecimal("4") / a)
|
||||
assertEquals(BigDecimal("-2"), -a)
|
||||
assertEquals(BigDecimal("-2"), -a % b)
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
MathTest().testBigInteger()
|
||||
MathTest().testBigDecimal()
|
||||
}
|
||||
@@ -30,11 +30,11 @@ protected class BuiltTest<T>(name: String, val builder: TestBuilder<T>, val test
|
||||
}
|
||||
|
||||
open class TestBuilder<T>(name: String) {
|
||||
val mySuite = TestSuite(name)
|
||||
val mySuite : TestSuite = TestSuite(name)
|
||||
|
||||
var setUp : BuiltTest<T>.() -> Unit = {}
|
||||
public var setUp : BuiltTest<T>.() -> Unit = {}
|
||||
|
||||
var tearDown : BuiltTest<T>.() -> Unit = {}
|
||||
public var tearDown : BuiltTest<T>.() -> Unit = {}
|
||||
|
||||
fun String.minus(test: BuiltTest<T>.() -> Unit) {
|
||||
mySuite.addTest(BuiltTest<T>(this, this@TestBuilder, test))
|
||||
|
||||
@@ -6,7 +6,7 @@ import stdhack.test.*
|
||||
import junit.framework.*
|
||||
import junit.textui.TestRunner
|
||||
|
||||
val suite = testSuite<Int>("test group") {
|
||||
public val suite : TestSuite? = testSuite<Int>("test group") {
|
||||
var staticState = 10
|
||||
|
||||
setUp = {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package test.collections;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class TestAll {
|
||||
// public static TestSuite suite() {
|
||||
// TestSuite suite = new TestSuite(StandardCollectionTest.class, CollectionTest.class, IoTest.class, ListTest.class, MapTest.class, SetTest.class, OldStdlibTest.class);
|
||||
// TestSuite suite = new TestSuite(StandardCollectionTest.class, CollectionTest.class, IoTest.class, ListTest.class, MapTest.class, SetTest.class, OldStdlibTest.class, MathTest.class);
|
||||
// suite.addTest(testDslExample.namespace.getSuite());
|
||||
// return suite;
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user