package ru.dbotthepony.mc.otm.tests

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.Test
import ru.dbotthepony.mc.otm.core.util.TickList

object TickListTests {
	@Test
	@DisplayName("TickList.Timer test")
	fun timers() {
		val queue = TickList()

		var state = 0

		queue.Timer(1) { state = 1 }
		queue.Timer(2) { state = 2 }
		queue.Timer(3) { state = 3 }
		queue.Timer(7) { state = 7 }
		queue.Timer(6) { state = 6 }
		queue.Timer(2) { state = 2 }

		queue.tick() // 1
		assertEquals(1, state)
		queue.tick() // 2 + 2
		assertEquals(2, state)
		queue.tick() // 3
		assertEquals(3, state)
		queue.tick() // 4
		assertEquals(3, state)
		queue.tick() // 5
		assertEquals(3, state)
		queue.tick() // 6
		assertEquals(6, state)
		queue.tick() // 7
		assertEquals(7, state)
		queue.tick() // 8
		assertEquals(7, state)
	}

	@Test
	@DisplayName("TickList test")
	fun ticks() {
		val list = TickList()

		var a = false
		var b = 0
		var c = 0

		list.once { a = true }
		list.add { ++b < 4 }
		list.always { c++ }

		for (i in 0 .. 10) {
			list.tick()
		}

		assertEquals(11, list.ticks)
		assertEquals(11, c)
		assertEquals(true, a)
		assertEquals(4, b)
	}
}
