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)) }
	}
}
