Created
May 1, 2012 16:37
-
-
Save abreslav/2569478 to your computer and use it in GitHub Desktop.
Kotlin + JUnit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package hhh.csp | |
import org.junit.* | |
import org.junit.rules.ExpectedException | |
import junit.framework.TestCase | |
import junit.framework.TestSuite | |
public class IntervalTest(name :String) : TestCase(name) { | |
fun testIntervalPlus() { | |
val values : Array<Interval> = Array(10000,{Interval.zero()}); | |
var v:Interval = Interval.zero(); | |
for( i in values ) i.u = 1.0; | |
for ( i in values) v = v+i; | |
println(v); | |
} | |
} | |
class Interval(var l : Double, var u : Double) { | |
class object { | |
inline fun zero() = Interval(0.0, 0.0) | |
} | |
inline fun clone() = Interval(l,u) | |
// should be implemented manually | |
fun plusAssign(other : Interval) { | |
l += other.l; | |
u += other.u; | |
} | |
// should be implemented automatically | |
fun plus(other : Interval):Interval { | |
val v = this.clone() | |
v.plusAssign(other) | |
return v | |
} | |
inline fun toString() = "[${l},${u}]"; | |
public fun main(args: Array<String> ) { | |
val values : Array<Interval> = Array<Interval>(10000,{Interval.zero()}); | |
var v:Interval = Interval.zero() + Interval(-1.0,1.0); | |
for( i in values ) i.u = 1.0; | |
for ( i in values) v = v + i; | |
println(v); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment