Add weak hash set test
This commit is contained in:
parent
77e6eebe92
commit
dba1e1e4a5
@ -0,0 +1,57 @@
|
|||||||
|
package ru.dbotthepony.mc.otm.tests
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
import ru.dbotthepony.mc.otm.core.collect.WeakHashSet
|
||||||
|
import ru.dbotthepony.mc.otm.core.collect.forEach
|
||||||
|
|
||||||
|
object WeakHashSetTests {
|
||||||
|
@Test
|
||||||
|
@DisplayName("WeakHashSet additions")
|
||||||
|
fun add() {
|
||||||
|
val set = WeakHashSet<Int>()
|
||||||
|
|
||||||
|
check(set.add(1))
|
||||||
|
check(set.add(2))
|
||||||
|
check(set.add(3))
|
||||||
|
check(!set.add(3))
|
||||||
|
check(set.add(10))
|
||||||
|
check(set.add(15))
|
||||||
|
check(!set.add(15))
|
||||||
|
check(!set.add(1))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("WeakHashSet removals")
|
||||||
|
fun remove() {
|
||||||
|
val set = WeakHashSet<Int>()
|
||||||
|
|
||||||
|
check(set.add(1))
|
||||||
|
check(set.add(2))
|
||||||
|
check(set.add(3))
|
||||||
|
|
||||||
|
check(set.remove(1))
|
||||||
|
check(set.remove(2))
|
||||||
|
check(set.remove(3))
|
||||||
|
|
||||||
|
check(!set.remove(4))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("WeakHashSet traversal")
|
||||||
|
fun traversal() {
|
||||||
|
val set = WeakHashSet<Int>()
|
||||||
|
|
||||||
|
check(set.add(1))
|
||||||
|
check(set.add(2))
|
||||||
|
check(set.add(3))
|
||||||
|
check(set.add(5))
|
||||||
|
check(set.add(6))
|
||||||
|
check(set.remove(1))
|
||||||
|
|
||||||
|
val set2 = mutableSetOf(2, 3, 5, 6)
|
||||||
|
check(set.containsAll(set2))
|
||||||
|
|
||||||
|
set.iterator().forEach { check(set2.remove(it)) }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user