Better testing framework, examples added as tests

This commit is contained in:
Andrey Breslav
2011-01-02 21:25:40 +03:00
parent b80460746a
commit 4d4e9cc342
79 changed files with 14379 additions and 60 deletions
+33
View File
@@ -0,0 +1,33 @@
class Queue<T> : IPushPop<T> {
private class Item<T>(val data : T, var next : Item<T>)
private var head : Item<T> = null
private var tail : Item<T> = null
override fun push(item : T) {
val i = new Item(item)
if (tail == null) {
head = i
tail = head
} else {
tail.next = i
tail = i
}
}
override fun pop() =
if (head == null)
throw new UnderflowException()
else {
val result = head.data
head = head.next
if (head == null)
tail = null
result
}
override val isEmpty
get() = head == null
}