/* Ċ package Ġme . cam den or rb . min ibus Ċ Ċ import Ġme . cam den or rb . min ibus . event . Event Watcher Ċ import Ġme . cam den or rb . min ibus . listener . Listener Priority Ċ import Ġme . cam den or rb . min ibus . listener . Mini Listener Ċ import Ġkotlin . system . measure Nano Time Ċ Ċ open Ġclass ĠBenchmark Event ĊĊ Ċ class ĠGeneric Event ( var Ġcalled : ĠBoolean Ġ= Ġfalse ) Ġ: ĠBenchmark Event () Ċ Ċ class ĠGeneric Event 2 < T Ġ: ĠAny >( var Ġcalled : ĠBoolean Ġ= Ġfalse ) Ġ: ĠBenchmark Event () ĊĊ Ċ fun Ġmain () Ġ{ Ċ ĉ Mini Bus Test (). apply Ġ{ Ċĉ ĉ setUp () Ċĉ ĉ event Test () Ċĉ ĉ te ar Down () Ċ ĉ } Ċ } Ċ Ċ class ĠMini Bus Test : ĠMini Listener Ġ{ ĊĊ ĉ val Ġmini Bus Ġ= ĠMini Bus () ĊĊ ĉ fun ĠsetUp () Ġ{ Ċĉ ĉ mini Bus . register ( this ) Ċ ĉ } ĊĊ ĉ fun Ġevent Test () Ġ{ ĊĊĉ ĉ val Ġcalled Event Ġ= Ġmini Bus ( Test Event ()) ĊĊĉ ĉ println (" Count : Ġ${ called Event . count } Ġ ĠOrder : Ġ${ called Event . abc }") ĊĊĉ ĉ check ( called Event . count Ġ== Ġ 6 ) Ġ{ Ġ" Not Ġall Ġevents Ġwere Ġcalled !" Ġ} Ċĉ ĉ check ( called Event . abc Ġ== Ġ" a 1 Ġa 2 Ġb 1 Ġb 2 Ġc 1 Ġc 2 ") Ġ{ Ġ" The Ġevents Ġwere Ġnot Ġcalled Ġin Ġorder !" Ġ} Ċĉ ĉ check ( called Event . is Cancelled ) Ġ{ Ġ" Event Ġwas Ġnot Ġcancelled Ġafter Ġthe Ġlast Ġlistener !" Ġ} ĊĊĊĉ ĉ var Ġtotal Time Ġ= Ġ 0 L Ċĉ ĉ val Ġbenchmark Event Ġ= ĠBenchmark Event () ĊĊĊĉ ĉ val Ġgeneric Event String Ġ= ĠGeneric Event 2 < String >() ĊĊĉ ĉ mini Bus ( generic Event String ) ĊĊĉ ĉ println ( generic Event String . called ) ĊĊĊĉ ĉ */ Ċ /* Ċĉ ĉ val Ġgeneric Event : ĠBenchmark Event Ġ= ĠGeneric Event () Ċĉ ĉ mini Bus ( generic Event ) ĊĊĉ ĉ check (( generic Event Ġas ĠGeneric Event ). called ) Ġ{ Ġ" Generic Ġevent Ġwasn 't Ġcalled !" Ġ} Ċĉ ĉ * //* ĊĊĊĉ ĉ */ Ċ /* ĠW arm ĠUp Ġ* //* ĊĊĉ ĉ for Ġ( i Ġin Ġ 0 .. 1 0 0 _ 0 0 0 ) Ġmini Bus ( benchmark Event ) ĊĊĉ ĉ for Ġ( i Ġin Ġ 1 .. 1 0 0 0 ) Ġtotal Time Ġ+= Ġmeasure Nano Time Ġ{ Ġmini Bus ( benchmark Event ) Ġ} ĊĊĉ ĉ println (" 1 0 0 0 Ġ* ĠB ench Event Ġ{ ĠAverage : Ġ${ total Time Ġ/ Ġ 1 0 0 0 }/ ns ĠTotal : Ġ$ total Time / ns Ġ Ġ} ") Ċĉ ĉ total Time Ġ= Ġ 0 ĊĊĉ ĉ val Ġme ow Ġ= Ġ" Me ow " ĊĊĉ ĉ */ Ċ /* ĠW arm ĠUp Ġ* //* ĊĊĉ ĉ for Ġ( i Ġin Ġ 0 .. 1 0 0 _ 0 0 0 ) Ġmini Bus ( me ow ) ĊĊĉ ĉ for Ġ( i Ġin Ġ 1 .. 1 0 0 0 ) Ġtotal Time Ġ+= Ġmeasure Nano Time Ġ{ Ġmini Bus ( me ow ) Ġ} Ċĉ ĉ println (" 1 0 0 0 Ġ* ĠNon Ex istent ĠEvent Ġ{ ĠAverage : Ġ${ total Time Ġ/ Ġ 1 0 0 0 }/ ns ĠTotal : Ġ$ total Time / ns Ġ} ") ĊĊ ĉ } ĊĊ ĉ fun ĠtearDown () Ġ{ Ċĉ ĉ mini Bus . clean Up () Ċ ĉ } ĊĊĊ ĉ @ Event Watcher Ċ ĉ fun Ġon Bench Mark ( event : ĠBenchmark Event ) Ġ= ĠUnit ĊĊ ĉ @ Event Watcher Ċ ĉ fun Ġon Generic Event ( event : ĠGeneric Event ) Ġ{ Ċĉ ĉ event . called Ġ= Ġtrue Ċ ĉ } ĊĊ ĉ @ Event Watcher Ċ ĉ fun Ġon Generic Event String ( event : ĠGeneric Event 2 < String >) Ġ{ Ċĉ ĉ event . called Ġ= Ġtrue Ċ ĉ } ĊĊ ĉ @ Event Watcher Ċ ĉ fun Ġon Generic Event Int ( event : ĠGeneric Event 2 < Int >) Ġ{ Ċĉ ĉ error (" Int Ġgeneric Ġevent Ġshouldn 't Ġhave Ġbeen Ġcalled !") Ċ ĉ } ĊĊĊ ĉ @ Event Watcher ( Listener Priority . FIRST ) Ċ ĉ fun Ġon Test 1 ( event : ĠTest Event ) Ġ{ Ċĉ ĉ event . count ++ Ċĉ ĉ event . abc Ġ+= Ġ" a 1 Ġ" Ċ ĉ } ĊĊ ĉ @ Event Watcher ( Listener Priority . FIRST ) Ċ ĉ fun Ġon Test 2 ( event : ĠTest Event ) Ġ{ Ċĉ ĉ event . count ++ Ċĉ ĉ event . abc Ġ+= Ġ" a 2 Ġ" Ċ ĉ } ĊĊ ĉ @ Event Watcher ( Listener Priority . NORMAL ) Ċ ĉ fun Ġon Test 3 ( event : ĠTest Event ) Ġ{ Ċĉ ĉ event . count ++ Ċĉ ĉ event . abc Ġ+= Ġ" b 1 Ġ" Ċ ĉ } ĊĊ ĉ @ Event Watcher ( Listener Priority . NORMAL ) Ċ ĉ fun Ġon Test 4 ( event : ĠTest Event ) Ġ{ Ċĉ ĉ event . count ++ Ċĉ ĉ event . abc Ġ+= Ġ" b 2 Ġ" Ċ ĉ } ĊĊ ĉ @ Event Watcher ( Listener Priority . LAST ) Ċ ĉ fun Ġon Test 5 ( event : ĠTest Event ) Ġ{ Ċĉ ĉ event . count ++ Ċĉ ĉ event . abc Ġ+= Ġ" c 1 Ġ" Ċ ĉ } ĊĊ ĉ @ Event Watcher ( Listener Priority . LAST ) Ċ ĉ fun Ġon Test 6 ( event : ĠTest Event ) Ġ{ Ċĉ ĉ event . count ++ Ċĉ ĉ event . abc Ġ+= Ġ" c 2 " Ċĉ ĉ event . is Cancelled Ġ= Ġtrue Ċ ĉ } Ċ Ċ } Ċ */ Ċ