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>
|
||||
</target>
|
||||
|
||||
<target name="compileTestlib" depends="jarRT">
|
||||
<target name="compileTestlib" depends="compileKunit">
|
||||
<mkdir dir="${output}/classes/testlib"/>
|
||||
<java classname="org.jetbrains.jet.cli.KotlinCompiler" failonerror="true" fork="true">
|
||||
<classpath>
|
||||
@@ -157,6 +157,7 @@
|
||||
<junit printsummary="yes" haltonfailure="true">
|
||||
<classpath>
|
||||
<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"/>
|
||||
<fileset dir="${basedir}/testlib/lib">
|
||||
<include name="**/*.jar"/>
|
||||
|
||||
@@ -4,66 +4,62 @@
|
||||
package kool.test
|
||||
|
||||
import org.junit.Assert
|
||||
import junit.framework.TestCase
|
||||
|
||||
/** Asserts that the given block returns true */
|
||||
fun assert(message: String, block: ()-> Boolean) {
|
||||
inline fun assertTrue(message: String, block: ()-> Boolean) {
|
||||
val actual = block()
|
||||
Assert.assertTrue(message, actual)
|
||||
}
|
||||
|
||||
/** 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 */
|
||||
fun assertNot(message: String, block: ()-> Boolean) {
|
||||
assert(message){ !block() }
|
||||
inline fun assertNot(message: String, block: ()-> Boolean) {
|
||||
assertTrue(message){ !block() }
|
||||
}
|
||||
|
||||
/** 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 */
|
||||
fun assert(actual: Boolean, message: String = "") {
|
||||
assertTrue(actual, message)
|
||||
}
|
||||
|
||||
/** Asserts that the expression is true with an optional message */
|
||||
fun assertTrue(actual: Boolean, message: String = "") {
|
||||
inline fun assertTrue(actual: Boolean, message: String = "") {
|
||||
return assertEquals(true, actual, 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)
|
||||
}
|
||||
|
||||
/** 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)
|
||||
}
|
||||
|
||||
/** 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)
|
||||
}
|
||||
|
||||
/** 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)
|
||||
}
|
||||
|
||||
/** 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)
|
||||
}
|
||||
|
||||
/** 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)
|
||||
}
|
||||
|
||||
/** 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()
|
||||
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
|
||||
* 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)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
module("testlib") {
|
||||
// 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")
|
||||
}
|
||||
|
||||
+229
-228
@@ -1,271 +1,272 @@
|
||||
package test.collections
|
||||
|
||||
import kool.test.*
|
||||
|
||||
// TODO can we avoid importing all this stuff by default I wonder?
|
||||
// e.g. making println and the collection builder methods public by default?
|
||||
import std.*
|
||||
import std.io.*
|
||||
import std.util.*
|
||||
import stdhack.test.*
|
||||
import java.util.*
|
||||
|
||||
class CollectionTest() : TestSupport() {
|
||||
|
||||
class IterableWrapper<T>(collection : java.lang.Iterable<T>) : java.lang.Iterable<T> {
|
||||
private val collection = collection
|
||||
class IterableWrapper<T>(collection : java.lang.Iterable<T>) : java.lang.Iterable<T> {
|
||||
private val collection = collection
|
||||
|
||||
override fun iterator(): java.util.Iterator<T> {
|
||||
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()
|
||||
override fun iterator(): java.util.Iterator<T> {
|
||||
return collection.iterator().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)
|
||||
}
|
||||
}
|
||||
val data = arrayList("foo", "bar")
|
||||
|
||||
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}
|
||||
fun testAny() {
|
||||
assertTrue {
|
||||
data.any{it.startsWith("f")}
|
||||
}
|
||||
assertNot {
|
||||
data.any{it.startsWith("x")}
|
||||
}
|
||||
}
|
||||
|
||||
expect(0) {
|
||||
val numbers = arrayList<Int>()
|
||||
numbers.fold(0){(it, it2) -> it + it2}
|
||||
fun testAll() {
|
||||
assertTrue {
|
||||
data.all{it.length == 3}
|
||||
}
|
||||
assertNot {
|
||||
data.all{s -> s.startsWith("b")}
|
||||
}
|
||||
}
|
||||
|
||||
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 testCount() {
|
||||
assertEquals(1, data.count{it.startsWith("b")})
|
||||
assertEquals(2, data.count{it.size == 3})
|
||||
}
|
||||
}
|
||||
|
||||
fun testFoldRight() {
|
||||
expect("4321") {
|
||||
val numbers = arrayList(1, 2, 3, 4)
|
||||
fun testFilter() {
|
||||
val foo = data.filter{it.startsWith("f")}
|
||||
|
||||
// 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}
|
||||
assertTrue {
|
||||
foo.all{it.startsWith("f")}
|
||||
}
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(arrayList("foo"), foo)
|
||||
}
|
||||
}
|
||||
|
||||
fun testFilterNot() {
|
||||
val foo = data.filterNot{it.startsWith("b")}
|
||||
|
||||
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 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}
|
||||
assertTrue {
|
||||
foo.all{it.startsWith("f")}
|
||||
}
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(arrayList("foo"), foo)
|
||||
}
|
||||
assertEquals(2, lengths.size)
|
||||
assertEquals(arrayList(3, 3), lengths)
|
||||
}
|
||||
|
||||
fun testReverse() {
|
||||
val rev = data.reverse()
|
||||
assertEquals(arrayList("bar", "foo"), rev)
|
||||
}
|
||||
fun testFilterIntoLinkedList() {
|
||||
// TODO would be nice to avoid the <String>
|
||||
val foo = data.filter(linkedList<String>()){it.startsWith("f")}
|
||||
|
||||
fun testSort() {
|
||||
val coll: List<String> = arrayList("foo", "bar", "abc")
|
||||
assertTrue {
|
||||
foo.all{it.startsWith("f")}
|
||||
}
|
||||
assertEquals(1, foo.size)
|
||||
assertEquals(linkedList("foo"), foo)
|
||||
|
||||
// TODO fixme
|
||||
// Some sort of in/out variance thing - or an issue with Java interop?
|
||||
//coll.sort()
|
||||
todo {
|
||||
assertEquals(3, coll.size)
|
||||
assertEquals(arrayList("abc", "bar", "foo"), coll)
|
||||
assertTrue {
|
||||
foo is LinkedList<String>
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
val arr = data.toArray()
|
||||
println("Got array ${arr}")
|
||||
todo {
|
||||
assert {
|
||||
arr is Array<String>
|
||||
}
|
||||
fun testJoin() {
|
||||
val text = data.join("-", "<", ">")
|
||||
assertEquals("<foo-bar>", text)
|
||||
}
|
||||
}
|
||||
|
||||
fun testSimpleCount() {
|
||||
assertEquals(2, data.count())
|
||||
assertEquals(3, hashSet(12, 14, 15).count())
|
||||
assertEquals(0, ArrayList<Double>().count())
|
||||
}
|
||||
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}
|
||||
assertTrue {
|
||||
lengths.all{it == 3}
|
||||
}
|
||||
assertEquals(2, lengths.size)
|
||||
assertEquals(arrayList(3, 3), lengths)
|
||||
}
|
||||
|
||||
fun testLast() {
|
||||
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 testReverse() {
|
||||
val rev = data.reverse()
|
||||
assertEquals(arrayList("bar", "foo"), rev)
|
||||
}
|
||||
|
||||
fun testLastException() {
|
||||
fails { arrayList<Int>().last() }
|
||||
fails { linkedList<String>().last() }
|
||||
fails { hashSet<Char>().last() }
|
||||
}
|
||||
fun testSort() {
|
||||
val coll: List<String> = arrayList("foo", "bar", "abc")
|
||||
|
||||
fun testIndices() {
|
||||
val indices = data.indices
|
||||
assertEquals(0, indices.start)
|
||||
assertEquals(1, indices.end)
|
||||
assertEquals(2, indices.size)
|
||||
assertFalse(indices.isReversed)
|
||||
}
|
||||
// TODO fixme
|
||||
// Some sort of in/out variance thing - or an issue with Java interop?
|
||||
//coll.sort()
|
||||
todo {
|
||||
assertEquals(3, coll.size)
|
||||
assertEquals(arrayList("abc", "bar", "foo"), coll)
|
||||
|
||||
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"))
|
||||
fun testToArray() {
|
||||
val arr = data.toArray()
|
||||
println("Got array ${arr}")
|
||||
todo {
|
||||
assertTrue {
|
||||
arr is Array<String>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertFalse(hashSet<Int>().contains(12))
|
||||
assertTrue(linkedList(15, 19, 20).contains(15))
|
||||
fun testSimpleCount() {
|
||||
assertEquals(2, data.count())
|
||||
assertEquals(3, hashSet(12, 14, 15).count())
|
||||
assertEquals(0, ArrayList<Double>().count())
|
||||
}
|
||||
|
||||
// assertTrue(IterableWrapper(hashSet(45, 14, 13)).contains(14))
|
||||
// assertFalse(IterableWrapper(linkedList<Int>()).contains(15))
|
||||
}
|
||||
fun testLast() {
|
||||
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 junit.framework.TestCase
|
||||
import stdhack.test.assertEquals
|
||||
import kool.test.assertEquals
|
||||
|
||||
class EnumerationIteratorTest() : TestCase() {
|
||||
fun testIteration () {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package test.standard
|
||||
|
||||
import std.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
class GetOrElseTest() : TestSupport() {
|
||||
val v1: String? = "hello"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package test.collections
|
||||
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
import std.io.*
|
||||
import std.util.*
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package testjc
|
||||
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
class C()
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package test.collections
|
||||
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
// TODO can we avoid importing all this stuff by default I wonder?
|
||||
// e.g. making println and the collection builder methods public by default?
|
||||
|
||||
+31
-31
@@ -1,6 +1,6 @@
|
||||
package test.collections
|
||||
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
// TODO can we avoid importing all this stuff by default I wonder?
|
||||
// e.g. making println and the collection builder methods public by default?
|
||||
@@ -10,43 +10,43 @@ import std.util.*
|
||||
import java.util.*
|
||||
|
||||
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() {
|
||||
val a = data.getOrElse("foo"){2}
|
||||
assertEquals(2, a)
|
||||
fun testGetOrElse() {
|
||||
val a = data.getOrElse("foo"){2}
|
||||
assertEquals(2, a)
|
||||
|
||||
val b = data.getOrElse("foo"){3}
|
||||
assertEquals(3, b)
|
||||
assertEquals(0, data.size)
|
||||
}
|
||||
val b = data.getOrElse("foo"){3}
|
||||
assertEquals(3, b)
|
||||
assertEquals(0, data.size)
|
||||
}
|
||||
|
||||
fun testGetOrPut() {
|
||||
val a = data.getOrPut("foo"){2}
|
||||
assertEquals(2, a)
|
||||
fun testGetOrPut() {
|
||||
val a = data.getOrPut("foo"){2}
|
||||
assertEquals(2, a)
|
||||
|
||||
val b = data.getOrPut("foo"){3}
|
||||
assertEquals(2, b)
|
||||
val b = data.getOrPut("foo"){3}
|
||||
assertEquals(2, b)
|
||||
|
||||
assertEquals(1, data.size())
|
||||
}
|
||||
assertEquals(1, data.size())
|
||||
}
|
||||
|
||||
fun testSizeAndEmpty() {
|
||||
assert{ data.empty }
|
||||
assertEquals(data.size, 0)
|
||||
}
|
||||
fun testSizeAndEmpty() {
|
||||
assertTrue{ data.empty }
|
||||
assertEquals(data.size, 0)
|
||||
}
|
||||
|
||||
fun testSetViaIndexOperators() {
|
||||
val map = java.util.HashMap<String, String>()
|
||||
assert{ map.empty }
|
||||
// TODO cannot use map.size due to compiler bug
|
||||
assertEquals(map.size(), 0)
|
||||
fun testSetViaIndexOperators() {
|
||||
val map = java.util.HashMap<String, String>()
|
||||
assertTrue{ map.empty }
|
||||
// TODO cannot use map.size due to compiler bug
|
||||
assertEquals(map.size(), 0)
|
||||
|
||||
map["name"] = "James"
|
||||
map["name"] = "James"
|
||||
|
||||
assert{ !map.empty }
|
||||
// TODO cannot use map.size due to compiler bug
|
||||
assertEquals(map.size(), 1)
|
||||
assertEquals("James", map["name"])
|
||||
}
|
||||
assertTrue{ !map.empty }
|
||||
// TODO cannot use map.size due to compiler bug
|
||||
assertEquals(map.size(), 1)
|
||||
assertEquals("James", map["name"])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import std.math.*
|
||||
import java.math.BigInteger
|
||||
import java.math.BigDecimal
|
||||
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
class MathTest : TestSupport() {
|
||||
fun testBigInteger() {
|
||||
|
||||
@@ -3,7 +3,7 @@ package test.collections
|
||||
import std.*
|
||||
import std.io.*
|
||||
import std.util.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
import java.util.*
|
||||
import java.io.*
|
||||
|
||||
@@ -15,7 +15,7 @@ class OldStdlibTest() : TestSupport() {
|
||||
}
|
||||
|
||||
fun testCollectionSize() {
|
||||
assert {
|
||||
assertTrue {
|
||||
Arrays.asList(0, 1, 2)?.size == 3
|
||||
}
|
||||
}
|
||||
|
||||
+56
-56
@@ -3,68 +3,68 @@ package test.collections
|
||||
import std.*
|
||||
import std.io.*
|
||||
import std.util.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
import java.util.*
|
||||
|
||||
class SetTest() : TestSupport() {
|
||||
val data = hashSet("foo", "bar")
|
||||
val data = hashSet("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: 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()
|
||||
fun testAny() {
|
||||
assertTrue {
|
||||
data.any{it.startsWith("f")}
|
||||
}
|
||||
assertNot {
|
||||
data.any{it.startsWith("x")}
|
||||
}
|
||||
}
|
||||
|
||||
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}
|
||||
assert {
|
||||
lengths.all{it == 3}
|
||||
fun testAll() {
|
||||
assertTrue {
|
||||
data.all{it.length == 3}
|
||||
}
|
||||
assertNot {
|
||||
data.all{(s: String) -> s.startsWith("b")}
|
||||
}
|
||||
}
|
||||
|
||||
fun testFilter() {
|
||||
val foo = data.filter{it.startsWith("f")}.toSet()
|
||||
|
||||
assertTrue {
|
||||
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
|
||||
|
||||
import std.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
class StandardCollectionTest() : TestSupport() {
|
||||
|
||||
@@ -13,7 +13,7 @@ class StandardCollectionTest() : TestSupport() {
|
||||
// TODO requires KT-924 to be implemented
|
||||
val data: Iterable<String> = std.util.arrayList("foo", "bar")
|
||||
|
||||
assert {
|
||||
assertTrue {
|
||||
data.any{it.startsWith("f")}
|
||||
}
|
||||
assertNot {
|
||||
|
||||
@@ -2,7 +2,7 @@ package test.stdlib.issues
|
||||
|
||||
import java.util.List
|
||||
import std.util.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
private fun listDifference<T>(first : List<T>, second : List<T>) : List<T> {
|
||||
return first.filter{ !second.contains(it) }.toList()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package testString
|
||||
|
||||
import std.io.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
import junit.framework.*
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package test.dom
|
||||
import std.*
|
||||
import std.dom.*
|
||||
import std.util.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
import org.w3c.dom.*
|
||||
|
||||
class DomBuilderTest() : TestSupport() {
|
||||
@@ -11,7 +11,7 @@ class DomBuilderTest() : TestSupport() {
|
||||
fun testBuildDocument() {
|
||||
var doc = createDocument()
|
||||
|
||||
assert {
|
||||
assertTrue {
|
||||
doc["grandchild"].isEmpty()
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class DomBuilderTest() : TestSupport() {
|
||||
|
||||
val root = doc.rootElement
|
||||
if (root != null) {
|
||||
assert {
|
||||
assertTrue {
|
||||
root.hasClass("bar")
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package test.dom
|
||||
|
||||
import std.*
|
||||
import std.dom.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
import org.w3c.dom.*
|
||||
|
||||
class DomTest() : TestSupport() {
|
||||
|
||||
@@ -2,7 +2,7 @@ package test.language
|
||||
|
||||
import junit.framework.TestCase
|
||||
import java.util.Collection
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
|
||||
class NullableCollectionsTest : TestCase() {
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package test.properties
|
||||
import std.*
|
||||
import std.properties.*
|
||||
import std.util.*
|
||||
import stdhack.test.*
|
||||
import kool.test.*
|
||||
import java.util.*
|
||||
import junit.framework.TestCase
|
||||
|
||||
|
||||
Reference in New Issue
Block a user