moved the common test helper methods into the kool.test package as a reusable library
This commit is contained in:
@@ -133,7 +133,7 @@
|
|||||||
</java>
|
</java>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="compileTestlib" depends="jarRT">
|
<target name="compileTestlib" depends="compileKunit">
|
||||||
<mkdir dir="${output}/classes/testlib"/>
|
<mkdir dir="${output}/classes/testlib"/>
|
||||||
<java classname="org.jetbrains.jet.cli.KotlinCompiler" failonerror="true" fork="true">
|
<java classname="org.jetbrains.jet.cli.KotlinCompiler" failonerror="true" fork="true">
|
||||||
<classpath>
|
<classpath>
|
||||||
@@ -157,6 +157,7 @@
|
|||||||
<junit printsummary="yes" haltonfailure="true">
|
<junit printsummary="yes" haltonfailure="true">
|
||||||
<classpath>
|
<classpath>
|
||||||
<pathelement location="${kotlin-home}/lib/kotlin-runtime.jar"/>
|
<pathelement location="${kotlin-home}/lib/kotlin-runtime.jar"/>
|
||||||
|
<pathelement location="${kotlin-home}/lib/kotlin-test.jar"/>
|
||||||
<pathelement location="${basedir}/testlib/lib/junit-4.9.jar"/>
|
<pathelement location="${basedir}/testlib/lib/junit-4.9.jar"/>
|
||||||
<fileset dir="${basedir}/testlib/lib">
|
<fileset dir="${basedir}/testlib/lib">
|
||||||
<include name="**/*.jar"/>
|
<include name="**/*.jar"/>
|
||||||
|
|||||||
@@ -4,66 +4,62 @@
|
|||||||
package kool.test
|
package kool.test
|
||||||
|
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
|
import junit.framework.TestCase
|
||||||
|
|
||||||
/** Asserts that the given block returns true */
|
/** Asserts that the given block returns true */
|
||||||
fun assert(message: String, block: ()-> Boolean) {
|
inline fun assertTrue(message: String, block: ()-> Boolean) {
|
||||||
val actual = block()
|
val actual = block()
|
||||||
Assert.assertTrue(message, actual)
|
Assert.assertTrue(message, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that the given block returns true */
|
/** Asserts that the given block returns true */
|
||||||
fun assert(block: ()-> Boolean) = assert(block.toString(), block)
|
inline fun assertTrue(block: ()-> Boolean) = assertTrue(block.toString(), block)
|
||||||
|
|
||||||
/** Asserts that the given block returns false */
|
/** Asserts that the given block returns false */
|
||||||
fun assertNot(message: String, block: ()-> Boolean) {
|
inline fun assertNot(message: String, block: ()-> Boolean) {
|
||||||
assert(message){ !block() }
|
assertTrue(message){ !block() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that the given block returns true */
|
/** Asserts that the given block returns true */
|
||||||
fun assertNot(block: ()-> Boolean) = assertNot(block.toString(), block)
|
inline fun assertNot(block: ()-> Boolean) = assertNot(block.toString(), block)
|
||||||
|
|
||||||
/** Asserts that the expression is true with an optional message */
|
/** Asserts that the expression is true with an optional message */
|
||||||
fun assert(actual: Boolean, message: String = "") {
|
inline fun assertTrue(actual: Boolean, message: String = "") {
|
||||||
assertTrue(actual, message)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Asserts that the expression is true with an optional message */
|
|
||||||
fun assertTrue(actual: Boolean, message: String = "") {
|
|
||||||
return assertEquals(true, actual, message)
|
return assertEquals(true, actual, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that the expression is false with an optional message */
|
/** Asserts that the expression is false with an optional message */
|
||||||
fun assertFalse(actual: Boolean, message: String = "") {
|
inline fun assertFalse(actual: Boolean, message: String = "") {
|
||||||
return assertEquals(false, actual, message)
|
return assertEquals(false, actual, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that the expected value is equal to the actual value, with an optional message */
|
/** Asserts that the expected value is equal to the actual value, with an optional message */
|
||||||
fun assertEquals(expected: Any?, actual: Any?, message: String = "") {
|
inline fun assertEquals(expected: Any?, actual: Any?, message: String = "") {
|
||||||
Assert.assertEquals(message, expected, actual)
|
Assert.assertEquals(message, expected, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that the expression is not null, with an optional message */
|
/** Asserts that the expression is not null, with an optional message */
|
||||||
fun assertNotNull(actual: Any?, message: String = "") {
|
inline fun assertNotNull(actual: Any?, message: String = "") {
|
||||||
Assert.assertNotNull(message, actual)
|
Assert.assertNotNull(message, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that the expression is null, with an optional message */
|
/** Asserts that the expression is null, with an optional message */
|
||||||
fun assertNull(actual: Any?, message: String = "") {
|
inline fun assertNull(actual: Any?, message: String = "") {
|
||||||
Assert.assertNull(message, actual)
|
Assert.assertNull(message, actual)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Marks a test as having failed if this point in the execution path is reached, with an optional message */
|
/** Marks a test as having failed if this point in the execution path is reached, with an optional message */
|
||||||
fun fail(message: String = "") {
|
inline fun fail(message: String = "") {
|
||||||
Assert.fail(message)
|
Assert.fail(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that given function block returns the given expected value */
|
/** Asserts that given function block returns the given expected value */
|
||||||
fun <T> expect(expected: T, block: ()-> T) {
|
inline fun <T> expect(expected: T, block: ()-> T) {
|
||||||
expect(expected, block.toString(), block)
|
expect(expected, block.toString(), block)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that given function block returns the given expected value and use the given message if it fails */
|
/** Asserts that given function block returns the given expected value and use the given message if it fails */
|
||||||
fun <T> expect(expected: T, message: String, block: ()-> T) {
|
inline fun <T> expect(expected: T, message: String, block: ()-> T) {
|
||||||
val actual = block()
|
val actual = block()
|
||||||
assertEquals(expected, actual, message)
|
assertEquals(expected, actual, message)
|
||||||
}
|
}
|
||||||
@@ -95,6 +91,14 @@ fun <T: Exception> failsWith(block: ()-> Any) {
|
|||||||
* Comments out a block of test code until it is implemented while keeping a link to the code
|
* Comments out a block of test code until it is implemented while keeping a link to the code
|
||||||
* to implement in your unit test output
|
* to implement in your unit test output
|
||||||
*/
|
*/
|
||||||
fun todo(block: ()-> Any) {
|
inline fun todo(block: ()-> Any) {
|
||||||
println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
|
println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Useful base class for test cases using the old JUnit 3 naming convention of functions
|
||||||
|
* starting with "test*" as being a test case
|
||||||
|
*/
|
||||||
|
abstract class TestSupport() : TestCase() {
|
||||||
|
}
|
||||||
|
|||||||
+2
-1
@@ -3,7 +3,8 @@ import kotlin.modules.*
|
|||||||
fun project() {
|
fun project() {
|
||||||
module("testlib") {
|
module("testlib") {
|
||||||
// TODO how to refer to the dir of the module?
|
// TODO how to refer to the dir of the module?
|
||||||
classpath += "testlib/lib/junit-4.9.jar"
|
classpath += "dist/kotlinc/lib/kotlin-test.jar"
|
||||||
|
classpath += "kunit/lib/junit-4.9.jar"
|
||||||
|
|
||||||
addSourceFiles("test")
|
addSourceFiles("test")
|
||||||
}
|
}
|
||||||
|
|||||||
+229
-228
@@ -1,271 +1,272 @@
|
|||||||
package test.collections
|
package test.collections
|
||||||
|
|
||||||
|
import kool.test.*
|
||||||
|
|
||||||
// TODO can we avoid importing all this stuff by default I wonder?
|
// TODO can we avoid importing all this stuff by default I wonder?
|
||||||
// e.g. making println and the collection builder methods public by default?
|
// e.g. making println and the collection builder methods public by default?
|
||||||
import std.*
|
import std.*
|
||||||
import std.io.*
|
import std.io.*
|
||||||
import std.util.*
|
import std.util.*
|
||||||
import stdhack.test.*
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class CollectionTest() : TestSupport() {
|
class CollectionTest() : TestSupport() {
|
||||||
|
|
||||||
class IterableWrapper<T>(collection : java.lang.Iterable<T>) : java.lang.Iterable<T> {
|
class IterableWrapper<T>(collection : java.lang.Iterable<T>) : java.lang.Iterable<T> {
|
||||||
private val collection = collection
|
private val collection = collection
|
||||||
|
|
||||||
override fun iterator(): java.util.Iterator<T> {
|
override fun iterator(): java.util.Iterator<T> {
|
||||||
return collection.iterator().sure()
|
return collection.iterator().sure()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val data = arrayList("foo", "bar")
|
|
||||||
|
|
||||||
fun testAny() {
|
|
||||||
assert {
|
|
||||||
data.any{it.startsWith("f")}
|
|
||||||
}
|
|
||||||
assertNot {
|
|
||||||
data.any{it.startsWith("x")}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testAll() {
|
|
||||||
assert {
|
|
||||||
data.all{it.length == 3}
|
|
||||||
}
|
|
||||||
assertNot {
|
|
||||||
data.all{s -> s.startsWith("b")}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testCount() {
|
|
||||||
assertEquals(1, data.count{it.startsWith("b")})
|
|
||||||
assertEquals(2, data.count{it.size == 3})
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFilter() {
|
|
||||||
val foo = data.filter{it.startsWith("f")}
|
|
||||||
|
|
||||||
assert {
|
|
||||||
foo.all{it.startsWith("f")}
|
|
||||||
}
|
|
||||||
assertEquals(1, foo.size)
|
|
||||||
assertEquals(arrayList("foo"), foo)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFilterNot() {
|
|
||||||
val foo = data.filterNot{it.startsWith("b")}
|
|
||||||
|
|
||||||
assert {
|
|
||||||
foo.all{it.startsWith("f")}
|
|
||||||
}
|
|
||||||
assertEquals(1, foo.size)
|
|
||||||
assertEquals(arrayList("foo"), foo)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFilterIntoLinkedList() {
|
|
||||||
// TODO would be nice to avoid the <String>
|
|
||||||
val foo = data.filter(linkedList<String>()){it.startsWith("f")}
|
|
||||||
|
|
||||||
assert {
|
|
||||||
foo.all{it.startsWith("f")}
|
|
||||||
}
|
|
||||||
assertEquals(1, foo.size)
|
|
||||||
assertEquals(linkedList("foo"), foo)
|
|
||||||
|
|
||||||
assert {
|
|
||||||
foo is LinkedList<String>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFilterIntoSortedSet() {
|
|
||||||
// TODO would be nice to avoid the <String>
|
|
||||||
val foo = data.filter(hashSet<String>()){it.startsWith("f")}
|
|
||||||
|
|
||||||
assert {
|
|
||||||
foo.all{it.startsWith("f")}
|
|
||||||
}
|
|
||||||
assertEquals(1, foo.size)
|
|
||||||
assertEquals(hashSet("foo"), foo)
|
|
||||||
|
|
||||||
assert {
|
|
||||||
foo is HashSet<String>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFind() {
|
|
||||||
val x = data.find{it.startsWith("x")}
|
|
||||||
assertNull(x)
|
|
||||||
fails {
|
|
||||||
x.sure()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val f = data.find{it.startsWith("f")}
|
|
||||||
f.sure()
|
|
||||||
assertEquals("foo", f)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFlatMap() {
|
val data = arrayList("foo", "bar")
|
||||||
val characters = arrayList('f', 'o', 'o', 'b', 'a', 'r')
|
|
||||||
// TODO figure out how to get a line like this to compile :)
|
|
||||||
/*
|
|
||||||
val characters = data.flatMap<String,Character>{
|
|
||||||
it.toCharArray().toList() as Collection<Character>
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
todo {
|
|
||||||
println("Got list of characters ${characters}")
|
|
||||||
val text = characters.join("")
|
|
||||||
assertEquals("foobar", text)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testForeach() {
|
fun testAny() {
|
||||||
var count = 0
|
assertTrue {
|
||||||
data.foreach{ count += it.length }
|
data.any{it.startsWith("f")}
|
||||||
assertEquals(6, count)
|
}
|
||||||
}
|
assertNot {
|
||||||
|
data.any{it.startsWith("x")}
|
||||||
fun testFold() {
|
}
|
||||||
expect(10) {
|
|
||||||
val numbers = arrayList(1, 2, 3, 4)
|
|
||||||
|
|
||||||
// TODO would be nice to be able to write this as this
|
|
||||||
//numbers.fold(0){it + it2}
|
|
||||||
numbers.fold(0){(it, it2) -> it + it2}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(0) {
|
fun testAll() {
|
||||||
val numbers = arrayList<Int>()
|
assertTrue {
|
||||||
numbers.fold(0){(it, it2) -> it + it2}
|
data.all{it.length == 3}
|
||||||
|
}
|
||||||
|
assertNot {
|
||||||
|
data.all{s -> s.startsWith("b")}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect("1234") {
|
fun testCount() {
|
||||||
val numbers = arrayList(1, 2, 3, 4)
|
assertEquals(1, data.count{it.startsWith("b")})
|
||||||
|
assertEquals(2, data.count{it.size == 3})
|
||||||
// TODO would be nice to be able to write this as this
|
|
||||||
// numbers.map{it.toString()}.fold(""){it + it2}
|
|
||||||
numbers.map<Int,String>{it.toString()}.fold(""){(it, it2) -> it + it2}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun testFoldRight() {
|
fun testFilter() {
|
||||||
expect("4321") {
|
val foo = data.filter{it.startsWith("f")}
|
||||||
val numbers = arrayList(1, 2, 3, 4)
|
|
||||||
|
|
||||||
// TODO would be nice to be able to write this as this
|
assertTrue {
|
||||||
// numbers.map{it.toString()}.foldRight(""){it + it2}
|
foo.all{it.startsWith("f")}
|
||||||
numbers.map<Int,String>{it.toString()}.foldRight(""){(it, it2) -> it + it2}
|
}
|
||||||
|
assertEquals(1, foo.size)
|
||||||
|
assertEquals(arrayList("foo"), foo)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
fun testFilterNot() {
|
||||||
|
val foo = data.filterNot{it.startsWith("b")}
|
||||||
|
|
||||||
fun testGroupBy() {
|
assertTrue {
|
||||||
val words = arrayList("a", "ab", "abc", "def", "abcd")
|
foo.all{it.startsWith("f")}
|
||||||
/*
|
}
|
||||||
TODO inference engine should not need this type info?
|
assertEquals(1, foo.size)
|
||||||
*/
|
assertEquals(arrayList("foo"), foo)
|
||||||
val byLength = words.groupBy<String,Int>{it.length}
|
|
||||||
assertEquals(4, byLength.size())
|
|
||||||
|
|
||||||
println("Grouped by length is: $byLength")
|
|
||||||
/*
|
|
||||||
TODO compiler bug...
|
|
||||||
|
|
||||||
val l3 = byLength.getOrElse(3, {ArrayList<String>()})
|
|
||||||
assertEquals(2, l3.size)
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testJoin() {
|
|
||||||
val text = data.join("-", "<", ">")
|
|
||||||
assertEquals("<foo-bar>", text)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testMap() {
|
|
||||||
/**
|
|
||||||
TODO compiler bug
|
|
||||||
we should be able to remove the explicit type on the function
|
|
||||||
http://youtrack.jetbrains.net/issue/KT-1145
|
|
||||||
*/
|
|
||||||
val lengths = data.map<String,Int>{s -> s.length}
|
|
||||||
assert {
|
|
||||||
lengths.all{it == 3}
|
|
||||||
}
|
}
|
||||||
assertEquals(2, lengths.size)
|
|
||||||
assertEquals(arrayList(3, 3), lengths)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testReverse() {
|
fun testFilterIntoLinkedList() {
|
||||||
val rev = data.reverse()
|
// TODO would be nice to avoid the <String>
|
||||||
assertEquals(arrayList("bar", "foo"), rev)
|
val foo = data.filter(linkedList<String>()){it.startsWith("f")}
|
||||||
}
|
|
||||||
|
|
||||||
fun testSort() {
|
assertTrue {
|
||||||
val coll: List<String> = arrayList("foo", "bar", "abc")
|
foo.all{it.startsWith("f")}
|
||||||
|
}
|
||||||
|
assertEquals(1, foo.size)
|
||||||
|
assertEquals(linkedList("foo"), foo)
|
||||||
|
|
||||||
// TODO fixme
|
assertTrue {
|
||||||
// Some sort of in/out variance thing - or an issue with Java interop?
|
foo is LinkedList<String>
|
||||||
//coll.sort()
|
}
|
||||||
todo {
|
}
|
||||||
assertEquals(3, coll.size)
|
|
||||||
assertEquals(arrayList("abc", "bar", "foo"), coll)
|
fun testFilterIntoSortedSet() {
|
||||||
|
// TODO would be nice to avoid the <String>
|
||||||
|
val foo = data.filter(hashSet<String>()){it.startsWith("f")}
|
||||||
|
|
||||||
|
assertTrue {
|
||||||
|
foo.all{it.startsWith("f")}
|
||||||
|
}
|
||||||
|
assertEquals(1, foo.size)
|
||||||
|
assertEquals(hashSet("foo"), foo)
|
||||||
|
|
||||||
|
assertTrue {
|
||||||
|
foo is HashSet<String>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testFind() {
|
||||||
|
val x = data.find{it.startsWith("x")}
|
||||||
|
assertNull(x)
|
||||||
|
fails {
|
||||||
|
x.sure()
|
||||||
|
}
|
||||||
|
|
||||||
|
val f = data.find{it.startsWith("f")}
|
||||||
|
f.sure()
|
||||||
|
assertEquals("foo", f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testFlatMap() {
|
||||||
|
val characters = arrayList('f', 'o', 'o', 'b', 'a', 'r')
|
||||||
|
// TODO figure out how to get a line like this to compile :)
|
||||||
|
/*
|
||||||
|
val characters = data.flatMap<String,Character>{
|
||||||
|
it.toCharArray().toList() as Collection<Character>
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
todo {
|
||||||
|
println("Got list of characters ${characters}")
|
||||||
|
val text = characters.join("")
|
||||||
|
assertEquals("foobar", text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testForeach() {
|
||||||
|
var count = 0
|
||||||
|
data.foreach{ count += it.length }
|
||||||
|
assertEquals(6, count)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testFold() {
|
||||||
|
expect(10) {
|
||||||
|
val numbers = arrayList(1, 2, 3, 4)
|
||||||
|
|
||||||
|
// TODO would be nice to be able to write this as this
|
||||||
|
//numbers.fold(0){it + it2}
|
||||||
|
numbers.fold(0){(it, it2) -> it + it2}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(0) {
|
||||||
|
val numbers = arrayList<Int>()
|
||||||
|
numbers.fold(0){(it, it2) -> it + it2}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect("1234") {
|
||||||
|
val numbers = arrayList(1, 2, 3, 4)
|
||||||
|
|
||||||
|
// TODO would be nice to be able to write this as this
|
||||||
|
// numbers.map{it.toString()}.fold(""){it + it2}
|
||||||
|
numbers.map<Int, String>{it.toString()}.fold(""){(it, it2) -> it + it2}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testFoldRight() {
|
||||||
|
expect("4321") {
|
||||||
|
val numbers = arrayList(1, 2, 3, 4)
|
||||||
|
|
||||||
|
// TODO would be nice to be able to write this as this
|
||||||
|
// numbers.map{it.toString()}.foldRight(""){it + it2}
|
||||||
|
numbers.map<Int, String>{it.toString()}.foldRight(""){(it, it2) -> it + it2}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun testGroupBy() {
|
||||||
|
val words = arrayList("a", "ab", "abc", "def", "abcd")
|
||||||
|
/*
|
||||||
|
TODO inference engine should not need this type info?
|
||||||
|
*/
|
||||||
|
val byLength = words.groupBy<String, Int>{it.length}
|
||||||
|
assertEquals(4, byLength.size())
|
||||||
|
|
||||||
|
println("Grouped by length is: $byLength")
|
||||||
|
/*
|
||||||
|
TODO compiler bug...
|
||||||
|
|
||||||
|
val l3 = byLength.getOrElse(3, {ArrayList<String>()})
|
||||||
|
assertEquals(2, l3.size)
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun testToArray() {
|
fun testJoin() {
|
||||||
val arr = data.toArray()
|
val text = data.join("-", "<", ">")
|
||||||
println("Got array ${arr}")
|
assertEquals("<foo-bar>", text)
|
||||||
todo {
|
|
||||||
assert {
|
|
||||||
arr is Array<String>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun testSimpleCount() {
|
fun testMap() {
|
||||||
assertEquals(2, data.count())
|
/**
|
||||||
assertEquals(3, hashSet(12, 14, 15).count())
|
TODO compiler bug
|
||||||
assertEquals(0, ArrayList<Double>().count())
|
we should be able to remove the explicit type on the function
|
||||||
}
|
http://youtrack.jetbrains.net/issue/KT-1145
|
||||||
|
*/
|
||||||
|
val lengths = data.map<String, Int>{s -> s.length}
|
||||||
|
assertTrue {
|
||||||
|
lengths.all{it == 3}
|
||||||
|
}
|
||||||
|
assertEquals(2, lengths.size)
|
||||||
|
assertEquals(arrayList(3, 3), lengths)
|
||||||
|
}
|
||||||
|
|
||||||
fun testLast() {
|
fun testReverse() {
|
||||||
assertEquals("bar", data.last())
|
val rev = data.reverse()
|
||||||
assertEquals(25, arrayList(15, 19, 20, 25).last())
|
assertEquals(arrayList("bar", "foo"), rev)
|
||||||
// assertEquals(19, TreeSet(arrayList(90, 47, 19)).first())
|
}
|
||||||
assertEquals('a', linkedList('a').last())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testLastException() {
|
fun testSort() {
|
||||||
fails { arrayList<Int>().last() }
|
val coll: List<String> = arrayList("foo", "bar", "abc")
|
||||||
fails { linkedList<String>().last() }
|
|
||||||
fails { hashSet<Char>().last() }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testIndices() {
|
// TODO fixme
|
||||||
val indices = data.indices
|
// Some sort of in/out variance thing - or an issue with Java interop?
|
||||||
assertEquals(0, indices.start)
|
//coll.sort()
|
||||||
assertEquals(1, indices.end)
|
todo {
|
||||||
assertEquals(2, indices.size)
|
assertEquals(3, coll.size)
|
||||||
assertFalse(indices.isReversed)
|
assertEquals(arrayList("abc", "bar", "foo"), coll)
|
||||||
}
|
|
||||||
|
|
||||||
fun testContains() {
|
}
|
||||||
assertTrue(data.contains("foo"))
|
}
|
||||||
assertTrue(data.contains("bar"))
|
|
||||||
assertFalse(data.contains("some"))
|
|
||||||
|
|
||||||
// TODO: Problems with generation
|
fun testToArray() {
|
||||||
// assertTrue(IterableWrapper(data).contains("bar"))
|
val arr = data.toArray()
|
||||||
// assertFalse(IterableWrapper(data).contains("some"))
|
println("Got array ${arr}")
|
||||||
|
todo {
|
||||||
|
assertTrue {
|
||||||
|
arr is Array<String>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assertFalse(hashSet<Int>().contains(12))
|
fun testSimpleCount() {
|
||||||
assertTrue(linkedList(15, 19, 20).contains(15))
|
assertEquals(2, data.count())
|
||||||
|
assertEquals(3, hashSet(12, 14, 15).count())
|
||||||
|
assertEquals(0, ArrayList<Double>().count())
|
||||||
|
}
|
||||||
|
|
||||||
// assertTrue(IterableWrapper(hashSet(45, 14, 13)).contains(14))
|
fun testLast() {
|
||||||
// assertFalse(IterableWrapper(linkedList<Int>()).contains(15))
|
assertEquals("bar", data.last())
|
||||||
}
|
assertEquals(25, arrayList(15, 19, 20, 25).last())
|
||||||
|
// assertEquals(19, TreeSet(arrayList(90, 47, 19)).first())
|
||||||
|
assertEquals('a', linkedList('a').last())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testLastException() {
|
||||||
|
fails { arrayList<Int>().last() }
|
||||||
|
fails { linkedList<String>().last() }
|
||||||
|
fails { hashSet<Char>().last() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testIndices() {
|
||||||
|
val indices = data.indices
|
||||||
|
assertEquals(0, indices.start)
|
||||||
|
assertEquals(1, indices.end)
|
||||||
|
assertEquals(2, indices.size)
|
||||||
|
assertFalse(indices.isReversed)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testContains() {
|
||||||
|
assertTrue(data.contains("foo"))
|
||||||
|
assertTrue(data.contains("bar"))
|
||||||
|
assertFalse(data.contains("some"))
|
||||||
|
|
||||||
|
// TODO: Problems with generation
|
||||||
|
// assertTrue(IterableWrapper(data).contains("bar"))
|
||||||
|
// assertFalse(IterableWrapper(data).contains("some"))
|
||||||
|
|
||||||
|
assertFalse(hashSet<Int>().contains(12))
|
||||||
|
assertTrue(linkedList(15, 19, 20).contains(15))
|
||||||
|
|
||||||
|
// assertTrue(IterableWrapper(hashSet(45, 14, 13)).contains(14))
|
||||||
|
// assertFalse(IterableWrapper(linkedList<Int>()).contains(15))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
import java.util.Vector
|
import java.util.Vector
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import stdhack.test.assertEquals
|
import kool.test.assertEquals
|
||||||
|
|
||||||
class EnumerationIteratorTest() : TestCase() {
|
class EnumerationIteratorTest() : TestCase() {
|
||||||
fun testIteration () {
|
fun testIteration () {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package test.standard
|
package test.standard
|
||||||
|
|
||||||
import std.*
|
import std.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
class GetOrElseTest() : TestSupport() {
|
class GetOrElseTest() : TestSupport() {
|
||||||
val v1: String? = "hello"
|
val v1: String? = "hello"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package test.collections
|
package test.collections
|
||||||
|
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
import std.io.*
|
import std.io.*
|
||||||
import std.util.*
|
import std.util.*
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package testjc
|
package testjc
|
||||||
|
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
class C()
|
class C()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package test.collections
|
package test.collections
|
||||||
|
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
// TODO can we avoid importing all this stuff by default I wonder?
|
// TODO can we avoid importing all this stuff by default I wonder?
|
||||||
// e.g. making println and the collection builder methods public by default?
|
// e.g. making println and the collection builder methods public by default?
|
||||||
|
|||||||
+31
-31
@@ -1,6 +1,6 @@
|
|||||||
package test.collections
|
package test.collections
|
||||||
|
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
// TODO can we avoid importing all this stuff by default I wonder?
|
// TODO can we avoid importing all this stuff by default I wonder?
|
||||||
// e.g. making println and the collection builder methods public by default?
|
// e.g. making println and the collection builder methods public by default?
|
||||||
@@ -10,43 +10,43 @@ import std.util.*
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class MapTest() : TestSupport() {
|
class MapTest() : TestSupport() {
|
||||||
val data: java.util.Map<String,Int> = java.util.HashMap<String, Int>()
|
val data: java.util.Map<String, Int> = java.util.HashMap<String, Int>()
|
||||||
|
|
||||||
fun testGetOrElse() {
|
fun testGetOrElse() {
|
||||||
val a = data.getOrElse("foo"){2}
|
val a = data.getOrElse("foo"){2}
|
||||||
assertEquals(2, a)
|
assertEquals(2, a)
|
||||||
|
|
||||||
val b = data.getOrElse("foo"){3}
|
val b = data.getOrElse("foo"){3}
|
||||||
assertEquals(3, b)
|
assertEquals(3, b)
|
||||||
assertEquals(0, data.size)
|
assertEquals(0, data.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testGetOrPut() {
|
fun testGetOrPut() {
|
||||||
val a = data.getOrPut("foo"){2}
|
val a = data.getOrPut("foo"){2}
|
||||||
assertEquals(2, a)
|
assertEquals(2, a)
|
||||||
|
|
||||||
val b = data.getOrPut("foo"){3}
|
val b = data.getOrPut("foo"){3}
|
||||||
assertEquals(2, b)
|
assertEquals(2, b)
|
||||||
|
|
||||||
assertEquals(1, data.size())
|
assertEquals(1, data.size())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testSizeAndEmpty() {
|
fun testSizeAndEmpty() {
|
||||||
assert{ data.empty }
|
assertTrue{ data.empty }
|
||||||
assertEquals(data.size, 0)
|
assertEquals(data.size, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun testSetViaIndexOperators() {
|
fun testSetViaIndexOperators() {
|
||||||
val map = java.util.HashMap<String, String>()
|
val map = java.util.HashMap<String, String>()
|
||||||
assert{ map.empty }
|
assertTrue{ map.empty }
|
||||||
// TODO cannot use map.size due to compiler bug
|
// TODO cannot use map.size due to compiler bug
|
||||||
assertEquals(map.size(), 0)
|
assertEquals(map.size(), 0)
|
||||||
|
|
||||||
map["name"] = "James"
|
map["name"] = "James"
|
||||||
|
|
||||||
assert{ !map.empty }
|
assertTrue{ !map.empty }
|
||||||
// TODO cannot use map.size due to compiler bug
|
// TODO cannot use map.size due to compiler bug
|
||||||
assertEquals(map.size(), 1)
|
assertEquals(map.size(), 1)
|
||||||
assertEquals("James", map["name"])
|
assertEquals("James", map["name"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import std.math.*
|
|||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
class MathTest : TestSupport() {
|
class MathTest : TestSupport() {
|
||||||
fun testBigInteger() {
|
fun testBigInteger() {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package test.collections
|
|||||||
import std.*
|
import std.*
|
||||||
import std.io.*
|
import std.io.*
|
||||||
import std.util.*
|
import std.util.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ class OldStdlibTest() : TestSupport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun testCollectionSize() {
|
fun testCollectionSize() {
|
||||||
assert {
|
assertTrue {
|
||||||
Arrays.asList(0, 1, 2)?.size == 3
|
Arrays.asList(0, 1, 2)?.size == 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+56
-56
@@ -3,68 +3,68 @@ package test.collections
|
|||||||
import std.*
|
import std.*
|
||||||
import std.io.*
|
import std.io.*
|
||||||
import std.util.*
|
import std.util.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class SetTest() : TestSupport() {
|
class SetTest() : TestSupport() {
|
||||||
val data = hashSet("foo", "bar")
|
val data = hashSet("foo", "bar")
|
||||||
|
|
||||||
fun testAny() {
|
fun testAny() {
|
||||||
assert {
|
assertTrue {
|
||||||
data.any{it.startsWith("f")}
|
data.any{it.startsWith("f")}
|
||||||
}
|
}
|
||||||
assertNot {
|
assertNot {
|
||||||
data.any{it.startsWith("x")}
|
data.any{it.startsWith("x")}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun testAll() {
|
|
||||||
assert {
|
|
||||||
data.all{it.length == 3}
|
|
||||||
}
|
|
||||||
assertNot {
|
|
||||||
data.all{(s: String) -> s.startsWith("b")}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFilter() {
|
|
||||||
val foo = data.filter{it.startsWith("f")}.toSet()
|
|
||||||
|
|
||||||
assert {
|
|
||||||
foo.all{it.startsWith("f")}
|
|
||||||
}
|
|
||||||
assertEquals(1, foo.size)
|
|
||||||
assertEquals(hashSet("foo"), foo)
|
|
||||||
|
|
||||||
assert("Filter on a Set should return a Set") {
|
|
||||||
foo is Set<String>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun testFind() {
|
|
||||||
val x = data.find{it.startsWith("x")}
|
|
||||||
assertNull(x)
|
|
||||||
fails {
|
|
||||||
x.sure()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val f = data.find{it.startsWith("f")}
|
fun testAll() {
|
||||||
f.sure()
|
assertTrue {
|
||||||
assertEquals("foo", f)
|
data.all{it.length == 3}
|
||||||
}
|
}
|
||||||
|
assertNot {
|
||||||
fun testMap() {
|
data.all{(s: String) -> s.startsWith("b")}
|
||||||
/**
|
}
|
||||||
TODO compiler bug
|
}
|
||||||
we should be able to remove the explicit type on the function
|
|
||||||
http://youtrack.jetbrains.net/issue/KT-849
|
fun testFilter() {
|
||||||
*/
|
val foo = data.filter{it.startsWith("f")}.toSet()
|
||||||
val lengths = data.map<String,Int>{(s: String) -> s.length}
|
|
||||||
assert {
|
assertTrue {
|
||||||
lengths.all{it == 3}
|
foo.all{it.startsWith("f")}
|
||||||
|
}
|
||||||
|
assertEquals(1, foo.size)
|
||||||
|
assertEquals(hashSet("foo"), foo)
|
||||||
|
|
||||||
|
assertTrue("Filter on a Set should return a Set") {
|
||||||
|
foo is Set<String>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testFind() {
|
||||||
|
val x = data.find{it.startsWith("x")}
|
||||||
|
assertNull(x)
|
||||||
|
fails {
|
||||||
|
x.sure()
|
||||||
|
}
|
||||||
|
|
||||||
|
val f = data.find{it.startsWith("f")}
|
||||||
|
f.sure()
|
||||||
|
assertEquals("foo", f)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testMap() {
|
||||||
|
/**
|
||||||
|
TODO compiler bug
|
||||||
|
we should be able to remove the explicit type on the function
|
||||||
|
http://youtrack.jetbrains.net/issue/KT-849
|
||||||
|
*/
|
||||||
|
val lengths = data.map<String, Int>{(s: String) -> s.length}
|
||||||
|
assertTrue {
|
||||||
|
lengths.all{it == 3}
|
||||||
|
}
|
||||||
|
assertEquals(2, lengths.size)
|
||||||
|
assertEquals(arrayList(3, 3), lengths)
|
||||||
}
|
}
|
||||||
assertEquals(2, lengths.size)
|
|
||||||
assertEquals(arrayList(3, 3), lengths)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package test.collections
|
package test.collections
|
||||||
|
|
||||||
import std.*
|
import std.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
class StandardCollectionTest() : TestSupport() {
|
class StandardCollectionTest() : TestSupport() {
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ class StandardCollectionTest() : TestSupport() {
|
|||||||
// TODO requires KT-924 to be implemented
|
// TODO requires KT-924 to be implemented
|
||||||
val data: Iterable<String> = std.util.arrayList("foo", "bar")
|
val data: Iterable<String> = std.util.arrayList("foo", "bar")
|
||||||
|
|
||||||
assert {
|
assertTrue {
|
||||||
data.any{it.startsWith("f")}
|
data.any{it.startsWith("f")}
|
||||||
}
|
}
|
||||||
assertNot {
|
assertNot {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package test.stdlib.issues
|
|||||||
|
|
||||||
import java.util.List
|
import java.util.List
|
||||||
import std.util.*
|
import std.util.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
private fun listDifference<T>(first : List<T>, second : List<T>) : List<T> {
|
private fun listDifference<T>(first : List<T>, second : List<T>) : List<T> {
|
||||||
return first.filter{ !second.contains(it) }.toList()
|
return first.filter{ !second.contains(it) }.toList()
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package testString
|
package testString
|
||||||
|
|
||||||
import std.io.*
|
import std.io.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
import junit.framework.*
|
import junit.framework.*
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package test.dom
|
|||||||
import std.*
|
import std.*
|
||||||
import std.dom.*
|
import std.dom.*
|
||||||
import std.util.*
|
import std.util.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
import org.w3c.dom.*
|
import org.w3c.dom.*
|
||||||
|
|
||||||
class DomBuilderTest() : TestSupport() {
|
class DomBuilderTest() : TestSupport() {
|
||||||
@@ -11,7 +11,7 @@ class DomBuilderTest() : TestSupport() {
|
|||||||
fun testBuildDocument() {
|
fun testBuildDocument() {
|
||||||
var doc = createDocument()
|
var doc = createDocument()
|
||||||
|
|
||||||
assert {
|
assertTrue {
|
||||||
doc["grandchild"].isEmpty()
|
doc["grandchild"].isEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ class DomBuilderTest() : TestSupport() {
|
|||||||
|
|
||||||
val root = doc.rootElement
|
val root = doc.rootElement
|
||||||
if (root != null) {
|
if (root != null) {
|
||||||
assert {
|
assertTrue {
|
||||||
root.hasClass("bar")
|
root.hasClass("bar")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package test.dom
|
|||||||
|
|
||||||
import std.*
|
import std.*
|
||||||
import std.dom.*
|
import std.dom.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
import org.w3c.dom.*
|
import org.w3c.dom.*
|
||||||
|
|
||||||
class DomTest() : TestSupport() {
|
class DomTest() : TestSupport() {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package test.language
|
|||||||
|
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import java.util.Collection
|
import java.util.Collection
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
|
|
||||||
class NullableCollectionsTest : TestCase() {
|
class NullableCollectionsTest : TestCase() {
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package test.properties
|
|||||||
import std.*
|
import std.*
|
||||||
import std.properties.*
|
import std.properties.*
|
||||||
import std.util.*
|
import std.util.*
|
||||||
import stdhack.test.*
|
import kool.test.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user