<commit_before>package me.camdenorrb.minibus

import me.camdenorrb.minibus.event.CancellableMiniEvent
import me.camdenorrb.minibus.event.EventWatcher
import me.camdenorrb.minibus.listener.ListenerPriority.*
import me.camdenorrb.minibus.listener.MiniListener
import org.junit.After
import org.junit.Before
import org.junit.Test
import kotlin.system.measureNanoTime



class BenchmarkEvent

class TestEvent(var count: Int = 0, var abc: String = ""): CancellableMiniEvent()


class MiniBusTest: MiniListener {

	val miniBus = MiniBus()

	@Before
	fun setUp() { miniBus.register(this) }

	@Test
	fun eventTest() {

		val calledEvent = miniBus(TestEvent())

		println("Count: ${calledEvent.count}  Order: ${calledEvent.abc}")

		check(calledEvent.count == 6) { "Not all events were called!" }
		check(calledEvent.abc == "aabbcc") { "The events were not called in order!" }
		check(calledEvent.isCancelled) { "Event was not cancelled after the last listener!" }


		var totalTime = 0L
		val benchmarkEvent = BenchmarkEvent()

		/* Warm Up */ for (i in 0..100_000) miniBus(benchmarkEvent)

		for (i in 1..1000) totalTime += measureNanoTime { miniBus(benchmarkEvent) }

		println("1000 * BenchEvent { Average: ${totalTime / 1000}/ns Total: $totalTime/ns  }")
		totalTime = 0

		val meow = "Meow"

		/* Warm Up */ for (i in 0..100_000) miniBus(meow)

		for (i in 1..1000) totalTime += measureNanoTime { miniBus(meow) }
		println("1000 * NonExistent Event { Average: ${totalTime / 1000}/ns Total: $totalTime/ns }")

	}

	@After
	fun tearDown() { miniBus.cleanUp() }


	@EventWatcher
	fun BenchmarkEvent.onBenchMark() = Unit


	@EventWatcher(FIRST)
	fun TestEvent.onTest1() {
		count++
		abc += 'a'
	}

	@EventWatcher(FIRST)
	fun TestEvent.onTest2() {
		count++
		abc += 'a'
	}

	@EventWatcher(NORMAL)
	fun TestEvent.onTest3() {
		count++
		abc += 'b'
	}

	@EventWatcher(NORMAL)
	fun TestEvent.onTest4() {
		count++
		abc += 'b'
	}

	@EventWatcher(LAST)
	fun TestEvent.onTest5() {
		count++
		abc += 'c'
	}

	@EventWatcher(LAST)
	fun TestEvent.onTest6() {
		count++
		abc += 'c'
		isCancelled = true
	}

}<commit_msg>Updated some tests<commit_after>package me.camdenorrb.minibus

import me.camdenorrb.minibus.event.CancellableMiniEvent
import me.camdenorrb.minibus.event.EventWatcher
import me.camdenorrb.minibus.listener.ListenerPriority.*
import me.camdenorrb.minibus.listener.MiniListener
import org.junit.After
import org.junit.Before
import org.junit.Test
import kotlin.system.measureNanoTime



open class BenchmarkEvent

class GenericEvent(var called: Boolean = false) : BenchmarkEvent()

class TestEvent(var count: Int = 0, var abc: String = ""): CancellableMiniEvent()


class MiniBusTest: MiniListener {

	val miniBus = MiniBus()

	@Before
	fun setUp() { miniBus.register(this) }

	@Test
	fun eventTest() {

		val calledEvent = miniBus(TestEvent())

		println("Count: ${calledEvent.count}  Order: ${calledEvent.abc}")

		check(calledEvent.count == 6) { "Not all events were called!" }
		check(calledEvent.abc == "a1 a2 b1 b2 c1 c2") { "The events were not called in order!" }
		check(calledEvent.isCancelled) { "Event was not cancelled after the last listener!" }


		var totalTime = 0L
		val benchmarkEvent = BenchmarkEvent()

		/*
		val genericEvent: BenchmarkEvent = GenericEvent()
		miniBus(genericEvent)

		check((genericEvent as GenericEvent).called) { "Generic event wasn't called!" }
		*/

		/* Warm Up */
		for (i in 0..100_000) miniBus(benchmarkEvent)

		for (i in 1..1000) totalTime += measureNanoTime { miniBus(benchmarkEvent) }

		println("1000 * BenchEvent { Average: ${totalTime / 1000}/ns Total: $totalTime/ns  }")
		totalTime = 0

		val meow = "Meow"

		/* Warm Up */
		for (i in 0..100_000) miniBus(meow)

		for (i in 1..1000) totalTime += measureNanoTime { miniBus(meow) }
		println("1000 * NonExistent Event { Average: ${totalTime / 1000}/ns Total: $totalTime/ns }")

	}

	@After
	fun tearDown() { miniBus.cleanUp() }


	@EventWatcher
	fun BenchmarkEvent.onBenchMark() = Unit

	@EventWatcher
	fun GenericEvent.onGenericEvent() {
		called = true
	}



	@EventWatcher(FIRST)
	fun TestEvent.onTest1() {
		count++
		abc += "a1 "
	}

	@EventWatcher(FIRST)
	fun TestEvent.onTest2() {
		count++
		abc += "a2 "
	}

	@EventWatcher(NORMAL)
	fun TestEvent.onTest3() {
		count++
		abc += "b1 "
	}

	@EventWatcher(NORMAL)
	fun TestEvent.onTest4() {
		count++
		abc += "b2 "
	}

	@EventWatcher(LAST)
	fun TestEvent.onTest5() {
		count++
		abc += "c1 "
	}

	@EventWatcher(LAST)
	fun TestEvent.onTest6() {
		count++
		abc += "c2"
		isCancelled = true
	}

}
{'fraction_non_alphanumeric': 0.13445931125246766, 'fraction_numerical': 0.024566790962930466, 'mean_word_length': 4.04983388704319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5320507', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1622, 'n_words': 379}