Correct Comparable interface used for isOrderedAndUnique()

This commit is contained in:
Ross Nicoll 2016-10-24 14:52:27 +01:00
parent 8f1329b03f
commit 65a03efc55
2 changed files with 25 additions and 2 deletions

View File

@ -13,7 +13,6 @@ import rx.Observable
import rx.subjects.UnicastSubject
import java.io.BufferedInputStream
import java.io.InputStream
import java.lang.Comparable
import java.math.BigDecimal
import java.nio.file.Files
import java.nio.file.LinkOption
@ -293,7 +292,7 @@ fun <T, I: Comparable<I>> Iterable<T>.isOrderedAndUnique(extractId: T.() -> I):
if (lastLast == null) {
true
} else {
lastLast.compareTo(extractId(it)) < 0
lastLast < extractId(it)
}
}
}

View File

@ -0,0 +1,24 @@
package com.r3corda.core
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class UtilsTest {
fun `ordered and unique basic`() {
val basic = listOf(1, 2, 3, 5, 8)
assertTrue(basic.isOrderedAndUnique { this })
val negative = listOf(-1, 2, 5)
assertTrue(negative.isOrderedAndUnique { this })
}
fun `ordered and unique duplicate`() {
val duplicated = listOf(1, 2, 2, 3, 5, 8)
assertFalse(duplicated.isOrderedAndUnique { this })
}
fun `ordered and unique out of sequence`() {
val mixed = listOf(3, 1, 2, 8, 5)
assertFalse(mixed.isOrderedAndUnique { this })
}
}