mirror of
https://github.com/corda/corda.git
synced 2025-01-19 03:06:36 +00:00
Merged in rnicoll-unique-identifier-comparable (pull request #414)
Correct Comparable interface used for isOrderedAndUnique()
This commit is contained in:
commit
63b1e356ad
@ -13,7 +13,6 @@ import rx.Observable
|
|||||||
import rx.subjects.UnicastSubject
|
import rx.subjects.UnicastSubject
|
||||||
import java.io.BufferedInputStream
|
import java.io.BufferedInputStream
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
import java.lang.Comparable
|
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import java.nio.file.LinkOption
|
import java.nio.file.LinkOption
|
||||||
@ -293,7 +292,7 @@ fun <T, I: Comparable<I>> Iterable<T>.isOrderedAndUnique(extractId: T.() -> I):
|
|||||||
if (lastLast == null) {
|
if (lastLast == null) {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
lastLast.compareTo(extractId(it)) < 0
|
lastLast < extractId(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
24
core/src/test/kotlin/com/r3corda/core/UtilsTest.kt
Normal file
24
core/src/test/kotlin/com/r3corda/core/UtilsTest.kt
Normal 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 })
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user