Better testing framework, examples added as tests
This commit is contained in:
@@ -6,7 +6,7 @@ class LinkedList<T> : IMutableList<T> {
|
||||
|
||||
private var head : Item = null
|
||||
private var tail : Item = null
|
||||
override var size get private set;
|
||||
override var size get private set
|
||||
|
||||
override fun add(index : Int, value : T) {
|
||||
size++
|
||||
|
||||
@@ -6,9 +6,11 @@ enum class List<out T>(theSize : Int) : IList<T> {
|
||||
override val size : Int
|
||||
get() = theSize
|
||||
|
||||
|
||||
override val isEmpty : Boolean
|
||||
get() = this == Nil
|
||||
|
||||
|
||||
override fun iterator() = new IIterator() {
|
||||
private var current = List.this
|
||||
|
||||
|
||||
@@ -28,18 +28,19 @@ class FileInput : IIterator<Byte>, JavaCloseableWrapper {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
override val hasNext
|
||||
get() { // implicitly throws IOException
|
||||
if (nextUsed && next != -1) {
|
||||
nextUsed = false
|
||||
next = stream.read() // throws IOException
|
||||
}
|
||||
return next != -1
|
||||
return next != -1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FileOutput throws IOException : IAdder<Byte>, JavaCloseableWrapper {
|
||||
class FileOutput : IAdder<Byte>, JavaCloseableWrapper {
|
||||
private val stream : OutputStream
|
||||
|
||||
this(file : File) : JavaCloseableWrapper(stream) {
|
||||
@@ -53,8 +54,8 @@ class FileOutput throws IOException : IAdder<Byte>, JavaCloseableWrapper {
|
||||
|
||||
fun example() { // this does not rethrow, no appropriate parameters given
|
||||
|
||||
val f1 : File = ...
|
||||
val f2 : File = ...
|
||||
val f1 : File //= ...
|
||||
val f2 : File //= ...
|
||||
|
||||
streamCopy(FileInput(f1), f2) // throws IOException, you must catch or rethrow explicitly
|
||||
|
||||
|
||||
@@ -5,12 +5,12 @@ class BinaryHeap<T> : IPriorityQueue<T> {
|
||||
this(data : IIterable<T>, compare : Comparison<T> = naturalOrder<T>) {
|
||||
this.compare = compare
|
||||
this.data = ArrayList(data)
|
||||
siftDown(* this.data.size / 2 .. 0)
|
||||
/*
|
||||
// siftDown(* this.data.size / 2 .. 0)
|
||||
|
||||
for (val i in data.size / 2 .. 0) {
|
||||
siftDown(i)
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
this(compare : Comparison<T>) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class PriorityQueueAsPushPop<T> wraps(wrapped : IPriorityQueue<T>) : IPushPop<T> {
|
||||
override fun pop() = wrapped.extract()
|
||||
override fun push(item : T) = wrapped.add(item)
|
||||
override val isEmpty
|
||||
override val isEmpty
|
||||
get() = wrapped.isEmpty
|
||||
|
||||
}
|
||||
@@ -5,7 +5,7 @@ fun naturalOrder<in T : IComparable<T>>(a : T, b : T) : Int = a.compareTo(b)
|
||||
fun castingNaturalOrder(a : Object, b : Object) : Int = (a as Comparable<Object>).compareTo(b as Comparable<Object>)
|
||||
|
||||
enum class ComparisonResult {
|
||||
LS, EQ, GR
|
||||
LS; EQ; GR
|
||||
}
|
||||
|
||||
type MatchableComparison<in T> = {(T, T) : ComparisonResult}
|
||||
|
||||
Reference in New Issue
Block a user