Skip to content

Instantly share code, notes, and snippets.

@abreslav
Created May 1, 2012 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abreslav/2569478 to your computer and use it in GitHub Desktop.
Save abreslav/2569478 to your computer and use it in GitHub Desktop.
Kotlin + JUnit
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