separate compiler and plugin tests

This commit is contained in:
Dmitry Jemerov
2011-10-20 16:19:02 +02:00
parent a80398098b
commit ec6dec0d37
586 changed files with 69 additions and 42 deletions
@@ -0,0 +1,101 @@
class BinaryHeap<T> : IPriorityQueue<T> {
private val data : IMutableList<T>
private val compare : Comparison<T>
this(data : IIterable<T>, compare : Comparison<T> = naturalOrder<T>) {
this.compare = compare
this.data = ArrayList(data)
// siftDown(* this.data.size / 2 .. 0)
for (val i in data.size / 2 .. 0) {
siftDown(i)
}
}
this(compare : Comparison<T>) {
this.compare = compare
this.data = ArrayList()
}
this() {
this.data = ArrayList()
Assert(T is IComparable<T>)
this.comparator = naturalOrder<T>
}
override fun extract() : T {
if (this.isEmpty)
throw UnderflowException()
data.swap(0, data.lastIndex)
data.remove(data.lastIndex)
siftDown(0)
}
override fun add(item : T) {
data.add(item)
siftUp(data.lastItem)
}
private fun siftDown(index : Int) {
var current = index
while (current.left.exists) {
var min = current
if (current.left.value < min.value) {
min = current.left
}
if (current.right.exists && current.right.value < min.value) {
min = current.right
}
if (min == current) break
data.swap(min, current)
current = min
}
}
private fun siftUp(index : Int) {
if (!current.exists) return
var current = index
while (current.parent.exists) {
if (current.value < current.parent.value) {
data.swap(current, current.parent)
current = current.parent
}
}
}
val Int.parent : Int
get() = (this - 1) / 2
val Int.left : Int
get() = this * 2 + 1
val Int.right : Int
get() = this * 2 + 2
val Int.value : T = foo.bar()
get() = data[this]
set(it) {
$value = it
}
val Int.exists : Boolean
get() = (this < data.size) && (this >= 0)
fun <T> T.compareTo(other : T) : Int = compare(this, other)
}
fun IMutableList<T>.swap(a : Int, b : Int) {
val t = this[a]
this[a] = this[b]
this[b] = t
}
val IList<T>.lastIndex : Int
get() = this.size - 1
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,5 @@
open class IPriorityQueue<T> {
fun extract() : T
fun add(item : T)
val isEmpty : Boolean
}
@@ -0,0 +1,63 @@
JetFile: IPriorityQueue.jet
NAMESPACE
CLASS
MODIFIER_LIST
PsiElement(open)('open')
PsiWhiteSpace(' ')
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('IPriorityQueue')
TYPE_PARAMETER_LIST
PsiElement(LT)('<')
TYPE_PARAMETER
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('extract')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiWhiteSpace('\n ')
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('add')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('item')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('isEmpty')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('Boolean')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -0,0 +1,7 @@
class PriorityQueueAsPushPop<T>(wrapped : IPriorityQueue<T>) : IPushPop<T> {
override fun pop() = wrapped.extract()
override fun push(item : T) = wrapped.add(item)
override val isEmpty
get() = wrapped.isEmpty
}
@@ -0,0 +1,135 @@
JetFile: PriorityQueueAsPushPop.jet
NAMESPACE
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('PriorityQueueAsPushPop')
TYPE_PARAMETER_LIST
PsiElement(LT)('<')
TYPE_PARAMETER
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('wrapped')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('IPriorityQueue')
TYPE_ARGUMENT_LIST
PsiElement(LT)('<')
TYPE_PROJECTION
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
DELEGATION_SPECIFIER_LIST
DELEGATOR_SUPER_CLASS
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('IPushPop')
TYPE_ARGUMENT_LIST
PsiElement(LT)('<')
TYPE_PROJECTION
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
FUN
MODIFIER_LIST
PsiElement(override)('override')
PsiWhiteSpace(' ')
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('pop')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('wrapped')
PsiElement(DOT)('.')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('extract')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
FUN
MODIFIER_LIST
PsiElement(override)('override')
PsiWhiteSpace(' ')
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('push')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('item')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('wrapped')
PsiElement(DOT)('.')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('add')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('item')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
PROPERTY
MODIFIER_LIST
PsiElement(override)('override')
PsiWhiteSpace(' ')
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('isEmpty')
PsiWhiteSpace('\n ')
PROPERTY_ACCESSOR
PsiElement(get)('get')
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
DOT_QUALIFIED_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('wrapped')
PsiElement(DOT)('.')
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('isEmpty')
PsiWhiteSpace('\n\n')
PsiElement(RBRACE)('}')