package Ġxyz . magenta ize . dynamic data . list Ċ Ċ import Ġxyz . magenta ize . dynamic data . domain . Person With Relations Ċ import Ġxyz . magenta ize . dynamic data . list . test . as Aggregator Ċ import Ġxyz . magenta ize . dynamic data . utilities . recursive Map Ċ import Ġorg . am sh ove . k lu ent . shouldBe EqualTo Ċ import Ġkotlin . test . Test Ċ Ċ class ĠTransform Many Fixture Ġ{ ĊĠĠĠ Ġval Ġsource Ġ= ĠSource List < Person With Relations >() ĊĠĠĠ Ġval Ġresult Ġ= Ġsource . connect () ĊĠĠĠĠĠĠĠ Ġ. transform Many Ġ{ Ġit . relations . recursive Map Ġ{ Ġp Ġ-> Ġp . relations Ġ} Ġ} ĊĠĠĠĠĠĠĠ Ġ. as Aggregator () ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġadd () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf 1 Ġ= ĠPerson With Relations (" Friend 1 ", Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 1 Ġ= ĠPerson With Relations (" Child 1 ", Ġ 1 0 , ĠlistOf ( f 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 2 Ġ= ĠPerson With Relations (" Child 2 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 3 Ġ= ĠPerson With Relations (" Child 3 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= ĠPerson With Relations (" M other ", Ġ 3 5 , ĠlistOf ( c 1 , Ġc 2 , Ġc 3 )) ĊĠĠĠĠĠĠĠ Ġsource . add ( m ) ĊĊĠĠĠĠĠĠĠ Ġresult . data . size ĠshouldBe EqualTo Ġ 4 ĊĠĠĠĠĠĠĠ Ġresult . data . items . toSet () ĠshouldBe EqualTo Ġset Of ( c 1 , Ġc 2 , Ġc 3 , Ġf 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġremove Parent () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf 1 Ġ= ĠPerson With Relations (" Friend 1 ", Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 1 Ġ= ĠPerson With Relations (" Child 1 ", Ġ 1 0 , ĠlistOf ( f 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 2 Ġ= ĠPerson With Relations (" Child 2 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 3 Ġ= ĠPerson With Relations (" Child 3 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= ĠPerson With Relations (" M other ", Ġ 3 5 , ĠlistOf ( c 1 , Ġc 2 , Ġc 3 )) ĊĠĠĠĠĠĠĠ Ġsource . add ( m ) ĊĠĠĠĠĠĠĠ Ġsource . remove ( m ) ĊĊĠĠĠĠĠĠĠ Ġresult . data . size ĠshouldBe EqualTo Ġ 0 ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġreplace () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf 1 Ġ= ĠPerson With Relations (" Friend 1 ", Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 1 Ġ= ĠPerson With Relations (" Child 1 ", Ġ 1 0 , ĠlistOf ( f 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 2 Ġ= ĠPerson With Relations (" Child 2 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 3 Ġ= ĠPerson With Relations (" Child 3 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= ĠPerson With Relations (" M other ", Ġ 3 5 , ĠlistOf ( c 1 , Ġc 2 , Ġc 3 )) ĊĠĠĠĠĠĠĠ Ġsource . add ( m ) ĊĠĠĠĠĠĠĠ Ġval Ġc 4 Ġ= ĠPerson With Relations (" Child 4 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġupdated M Ġ= ĠPerson With Relations (" M other ", Ġ 3 5 , ĠlistOf ( c 1 , Ġc 2 , Ġc 4 )) ĊĠĠĠĠĠĠĠ Ġsource . replace ( m , Ġupdated M ) ĊĊĠĠĠĠĠĠĠ Ġresult . data . size ĠshouldBe EqualTo Ġ 4 ĊĠĠĠĠĠĠĠ Ġresult . data . items . toSet () ĠshouldBe EqualTo Ġset Of ( c 1 , Ġc 2 , Ġc 4 , Ġf 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġadd Range () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf 1 Ġ= ĠPerson With Relations (" Friend 1 ", Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 1 Ġ= ĠPerson With Relations (" Child 1 ", Ġ 1 0 , ĠlistOf ( f 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 2 Ġ= ĠPerson With Relations (" Child 2 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 3 Ġ= ĠPerson With Relations (" Child 3 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= ĠPerson With Relations (" M other ", Ġ 3 5 , ĠlistOf ( c 1 , Ġc 2 , Ġc 3 )) ĊĠĠĠĠĠĠĠ Ġsource . add ( m ) ĊĊĠĠĠĠĠĠĠ Ġval Ġc 4 Ġ= ĠPerson With Relations (" Child 4 ", Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 5 Ġ= ĠPerson With Relations (" Child 5 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġa 1 Ġ= ĠPerson With Relations (" Another 1 ", Ġ 2 , ĠlistOf ( c 4 , Ġc 5 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 6 Ġ= ĠPerson With Relations (" Child 6 ", Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 7 Ġ= ĠPerson With Relations (" Child 7 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġa 2 Ġ= ĠPerson With Relations (" Another 2 ", Ġ 2 , ĠlistOf ( c 6 , Ġc 7 )) ĊĠĠĠĠĠĠĠ Ġsource . add Range ( listOf ( a 1 , Ġa 2 )) ĊĊĠĠĠĠĠĠĠ Ġresult . data . size ĠshouldBe EqualTo Ġ 8 ĊĠĠĠĠĠĠĠ Ġresult . data . items . toSet () ĠshouldBe EqualTo Ġset Of ( c 1 , Ġc 2 , Ġc 3 , Ġf 1 , Ġc 4 , Ġc 5 , Ġc 6 , Ġc 7 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġremove Range () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf 1 Ġ= ĠPerson With Relations (" Friend 1 ", Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 1 Ġ= ĠPerson With Relations (" Child 1 ", Ġ 1 0 , ĠlistOf ( f 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 2 Ġ= ĠPerson With Relations (" Child 2 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 3 Ġ= ĠPerson With Relations (" Child 3 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= ĠPerson With Relations (" M other ", Ġ 3 5 , ĠlistOf ( c 1 , Ġc 2 , Ġc 3 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 4 Ġ= ĠPerson With Relations (" Child 4 ", Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 5 Ġ= ĠPerson With Relations (" Child 5 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġa 1 Ġ= ĠPerson With Relations (" Another 1 ", Ġ 2 , ĠlistOf ( c 4 , Ġc 5 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 6 Ġ= ĠPerson With Relations (" Child 6 ", Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 7 Ġ= ĠPerson With Relations (" Child 7 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġa 2 Ġ= ĠPerson With Relations (" Another 2 ", Ġ 2 , ĠlistOf ( c 6 , Ġc 7 )) ĊĠĠĠĠĠĠĠ Ġsource . add Range ( listOf ( m , Ġa 1 , Ġa 2 )) ĊĠĠĠĠĠĠĠ Ġsource . remove Range ( 0 , Ġ 2 ) ĊĊĠĠĠĠĠĠĠ Ġresult . data . size ĠshouldBe EqualTo Ġ 2 ĊĠĠĠĠĠĠĠ Ġresult . data . items . toSet () ĠshouldBe EqualTo Ġset Of ( c 6 , Ġc 7 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġclear () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġf 1 Ġ= ĠPerson With Relations (" Friend 1 ", Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 1 Ġ= ĠPerson With Relations (" Child 1 ", Ġ 1 0 , ĠlistOf ( f 1 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 2 Ġ= ĠPerson With Relations (" Child 2 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 3 Ġ= ĠPerson With Relations (" Child 3 ", Ġ 8 ) ĊĠĠĠĠĠĠĠ Ġval Ġm Ġ= ĠPerson With Relations (" M other ", Ġ 3 5 , ĠlistOf ( c 1 , Ġc 2 , Ġc 3 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 4 Ġ= ĠPerson With Relations (" Child 4 ", Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 5 Ġ= ĠPerson With Relations (" Child 5 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġa 1 Ġ= ĠPerson With Relations (" Another 1 ", Ġ 2 , ĠlistOf ( c 4 , Ġc 5 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 6 Ġ= ĠPerson With Relations (" Child 6 ", Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 7 Ġ= ĠPerson With Relations (" Child 7 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġa 2 Ġ= ĠPerson With Relations (" Another 2 ", Ġ 2 , ĠlistOf ( c 6 , Ġc 7 )) ĊĠĠĠĠĠĠĠ Ġsource . add Range ( listOf ( m , Ġa 1 , Ġa 2 )) ĊĠĠĠĠĠĠĠ Ġsource . clear () ĊĊĠĠĠĠĠĠĠ Ġresult . data . size ĠshouldBe EqualTo Ġ 0 ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġmove () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġc 4 Ġ= ĠPerson With Relations (" Child 4 ", Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 5 Ġ= ĠPerson With Relations (" Child 5 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġa 1 Ġ= ĠPerson With Relations (" Another 1 ", Ġ 2 , ĠlistOf ( c 4 , Ġc 5 )) ĊĠĠĠĠĠĠĠ Ġval Ġc 6 Ġ= ĠPerson With Relations (" Child 6 ", Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġval Ġc 7 Ġ= ĠPerson With Relations (" Child 7 ", Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġval Ġa 2 Ġ= ĠPerson With Relations (" Another 2 ", Ġ 2 , ĠlistOf ( c 6 , Ġc 7 )) ĊĠĠĠĠĠĠĠ Ġsource . add Range ( listOf ( a 1 , Ġa 2 )) ĊĠĠĠĠĠĠĠ Ġresult . messages . size ĠshouldBe EqualTo Ġ 1 ĊĊĠĠĠĠĠĠĠ Ġsource . move ( 1 , Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġresult . messages . size ĠshouldBe EqualTo Ġ 1 ĊĠĠĠ Ġ} Ċ Ċ // ĠĠĠ Ġ@ Test Ċ // ĠĠĠ Ġfun Ġremove () Ġ{ Ċ // ĠĠĠĠĠĠĠ Ġval Ġproviders Ġ= ĠSource List < Tour Provider >() Ċ // ĠĠĠĠĠĠĠ Ġval Ġall T ours Ġ= Ġproviders . connect () Ċ // ĠĠĠĠĠĠĠĠĠĠĠ Ġ. transform Many Ġ{ Ġit . to urs Ġ} Ċ // ĠĠĠĠĠĠĠĠĠĠĠ Ġ. as Observable List () Ċ // Ċ // ĠĠĠĠĠĠĠ Ġval Ġtour 1 _ 1 Ġ= ĠT our (" Tour Ġ 1 . 1 ") Ċ // ĠĠĠĠĠĠĠ Ġval Ġtour 2 _ 1 Ġ= ĠT our (" Tour Ġ 2 . 1 ") Ċ // ĠĠĠĠĠĠĠ Ġval Ġtour 2 _ 2 Ġ= ĠT our (" Tour Ġ 2 . 2 ") Ċ // ĠĠĠĠĠĠĠ Ġval Ġtour 3 _ 1 Ġ= ĠT our (" Tour Ġ 3 . 1 ") Ċ // ĠĠĠĠĠĠĠ Ġval Ġtp 1 Ġ= ĠT our Provider (" TP 1 ", Ġmutable ListOf ( tour 1 _ 1 )) Ċ // ĠĠĠĠĠĠĠ Ġval Ġtp 2 Ġ= ĠT our Provider (" TP 2 ", Ġmutable ListOf ( tour 2 _ 1 , Ġtour 2 _ 2 )) Ċ // ĠĠĠĠĠĠĠ Ġval Ġtp 3 Ġ= ĠT our Provider (" TP 3 ", Ġmutable ListOf ()) Ċ // ĠĠĠĠĠĠĠ Ġproviders . add Range ( listOf ( tp 1 , Ġtp 2 , Ġtp 3 )) Ċ // ĠĠĠĠĠĠĠ Ġall T ours . items . toList () ĠshouldBe EqualTo ĠlistOf ( tour 1 _ 1 , Ġtour 2 _ 1 , Ġtour 2 _ 2 ) Ċ // Ċ // ĠĠĠĠĠĠĠ Ġtp 3 . to urs . add ( tour 3 _ 1 ) Ċ // ĠĠĠĠĠĠĠ Ġall T ours . items . toList () ĠshouldBe EqualTo ĠlistOf ( tour 1 _ 1 , Ġtour 2 _ 1 , Ġtour 2 _ 2 , Ġtour 3 _ 1 ) Ċ // Ċ // ĠĠĠĠĠĠĠ Ġtp 2 . to urs . remove ( tour 2 _ 1 ) Ċ // ĠĠĠĠĠĠĠ Ġall T ours . items . toList () ĠshouldBe EqualTo ĠlistOf ( tour 1 _ 1 , Ġtour 2 _ 2 , Ġtour 3 _ 1 ) Ċ // Ċ // ĠĠĠĠĠĠĠ Ġtp 2 . to urs . add ( tour 2 _ 1 ) Ċ // ĠĠĠĠĠĠĠ Ġall T ours . items . toList () ĠshouldBe EqualTo ĠlistOf ( tour 1 _ 1 , Ġtour 2 _ 1 , Ġtour 2 _ 2 , Ġtour 3 _ 1 ) Ċ // ĠĠĠ Ġ} Ċ // Ċ // ĠĠĠ Ġclass ĠT our Provider ( Ċ // ĠĠĠĠĠĠĠ Ġval Ġname : ĠString , Ċ // ĠĠĠĠĠĠĠ Ġval Ġto urs : ĠMutable List < Tour > Ċ // ĠĠĠ Ġ) Ċ // Ċ // ĠĠĠ Ġclass ĠT our ( val Ġname : ĠString ){ Ċ // ĠĠĠĠĠĠĠ Ġoverride Ġfun ĠtoString (): ĠString Ġ= Ċ // ĠĠĠĠĠĠĠĠĠĠĠ Ġ" name : Ġ$ name " Ċ // ĠĠĠ Ġ} Ċ } Ċ