public
Created

Kotlin + JUnit

  • Download Gist
gistfile1.kt
Kotlin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.