package Ġorg . kotlin lang . ko ans . collections Ċ Ċ import Ġorg . junit . Assert Ċ import Ġorg . junit . Test Ċ Ċ // products Ċ val Ġidea Ġ= ĠProduct (" Int elli J ĠIDEA ĠU lt imate ", Ġ 1 9 9 . 0 ) Ċ val Ġre Sharper Ġ= ĠProduct (" Re Sharper ", Ġ 1 4 9 . 0 ) Ċ val Ġdot Trace Ġ= ĠProduct (" Dot Trace ", Ġ 1 5 9 . 0 ) Ċ val Ġdot Memory Ġ= ĠProduct (" Dot Trace ", Ġ 1 2 9 . 0 ) Ċ val Ġphp Storm Ġ= ĠProduct (" Php Storm ", Ġ 9 9 . 0 ) Ċ val Ġruby Mine Ġ= ĠProduct (" Ruby Mine ", Ġ 9 9 . 0 ) Ċ val Ġweb Storm Ġ= ĠProduct (" Web Storm ", Ġ 4 9 . 0 ) Ċ val Ġyou Track Ġ= ĠProduct (" You Track ", Ġ 5 0 0 . 0 ) Ċ Ċ // customers Ċ const Ġval Ġl uc as Ġ= Ġ" Luc as " Ċ const Ġval Ġc ooper Ġ= Ġ" C ooper " Ċ const Ġval Ġn athan Ġ= Ġ" N athan " Ċ const Ġval Ġre ka Ġ= Ġ" Re ka " Ċ const Ġval Ġb aj ram Ġ= Ġ" B aj ram " Ċ const Ġval Ġas uka Ġ= Ġ" As uka " Ċ const Ġval Ġri ku Ġ= Ġ" R iku " Ċ Ċ // cities Ċ val ĠCan b erra Ġ= ĠCity (" Can b erra ") Ċ val ĠV anco u ver Ġ= ĠCity (" V anco u ver ") Ċ val ĠB ud ape st Ġ= ĠCity (" B ud ape st ") Ċ val ĠAn k ara Ġ= ĠCity (" An k ara ") Ċ val ĠTok yo Ġ= ĠCity (" To ky o ") Ċ Ċ fun Ġcustomer ( name : ĠString , Ġcity : ĠCity , Ġvar arg Ġorders : ĠOrder ) Ġ= ĠCustomer ( name , Ġcity , Ġorders . toList ()) Ċ fun Ġorder ( var arg Ġproducts : ĠProduct , Ġis Deliver ed : ĠBoolean Ġ= Ġtrue ) Ġ= ĠOrder ( products . toList (), Ġis Deliver ed ) Ċ fun Ġshop ( name : ĠString , Ġvar arg Ġcustomers : ĠCustomer ) Ġ= ĠShop ( name , Ġcustomers . toList ()) Ċ Ċ val Ġshop Ġ= Ġshop (" jb Ġtest Ġshop ", ĊĠĠĠĠĠĠĠ Ġcustomer ( luc as , ĠCan b erra , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( re Sharper ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( re Sharper , Ġdot Memory , Ġdot Trace ) ĊĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġcustomer ( co oper , ĠCan b erra ), ĊĠĠĠĠĠĠĠ Ġcustomer ( n athan , ĠV anco u ver , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( ruby Mine , Ġweb Storm ) ĊĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġcustomer ( re ka , ĠB ud ape st , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( idea , Ġis Deliver ed Ġ= Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( idea , Ġis Deliver ed Ġ= Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( idea ) ĊĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġcustomer ( b aj ram , ĠAn k ara , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( re Sharper ) ĊĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġcustomer ( as uka , ĠTok yo , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( idea ) ĊĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠ Ġcustomer ( ri ku , ĠTok yo , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( php Storm , Ġphp Storm ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( php Storm ) ĊĠĠĠĠĠĠĠ Ġ) Ċ Ċ ) Ċ Ċ val Ġcustomers : ĠMap < String , ĠCustomer > Ġ= Ġshop . customers . fold ( hash Map Of ()) Ġ{ Ġmap , Ġcustomer Ġ-> ĊĠĠĠ Ġmap [ customer . name ] Ġ= Ġcustomer ĊĠĠĠ Ġmap Ċ } Ċ Ċ val Ġordered Products Ġ= Ġset Of ( idea , Ġre Sharper , Ġdot Trace , Ġdot Memory , Ġruby Mine , Ġweb Storm , Ġphp Storm ) Ċ Ċ val Ġsorted Customers Ġ= ĠlistOf ( co oper , Ġn athan , Ġb aj ram , Ġas uka , Ġl uc as , Ġri ku , Ġre ka ). map Ġ{ Ġcustomers [ it ] Ġ} Ċ Ċ val Ġgrouped By C ities Ġ= Ġmap Of ( ĊĠĠĠĠĠĠĠ ĠCan b erra Ġto ĠlistOf ( luc as , Ġc ooper ), ĊĠĠĠĠĠĠĠ ĠV anco u ver Ġto ĠlistOf ( n athan ), ĊĠĠĠĠĠĠĠ ĠB ud ape st Ġto ĠlistOf ( re ka ), ĊĠĠĠĠĠĠĠ ĠAn k ara Ġto ĠlistOf ( b aj ram ), ĊĠĠĠĠĠĠĠ ĠTok yo Ġto ĠlistOf ( as uka , Ġri ku ) Ċ ). map Values Ġ{ Ġit . value . map Ġ{ Ġname Ġ-> Ġcustomers [ name ] Ġ} Ġ} Ċ Ċ class ĠTest Shop Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Set Of Customers () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Set Of Customers ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcustomers . values . toSet (), Ġshop . get Set Of Customers ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest C ities Customers Are From () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" getC ities Customers Are From ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( Can b erra , ĠV anco u ver , ĠB ud ape st , ĠAn k ara , ĠTok yo ), Ġshop . getC ities Customers Are From ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Customers From City () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Customers From ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( customers [ luc as ], Ġcustomers [ co oper ]), Ġshop . get Customers From ( Can b erra )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest All Customers Are From City () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertFalse (" check All Customers Are From ", Ġshop . check All Customers Are From ( Can b erra )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Any Customer Is From City () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertTrue (" has Customer From ", Ġshop . has Customer From ( Can b erra )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Count Customers From City () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" count Customers From ", Ġ 2 , Ġshop . count Customers From ( Can b erra )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Any Customer From City () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" find Any Customer From ", Ġcustomers [ luc as ], Ġshop . find Any Customer From ( Can b erra )) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" find Any Customer From ", Ġnull , Ġshop . find Any Customer From ( City (" Ch icago "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Ordered Products Set () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Ordered Products ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( idea ), Ġcustomers [ re ka ] !!. ordered Products ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet All Ordered Products () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" getAll Ordered Products ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġordered Products , Ġshop . all Ordered Products ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Customer With Maximum NumberOf Orders () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Customer With Maximum NumberOf Orders ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcustomers [ re ka ], Ġshop . get Customer With Maximum NumberOf Orders ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest The Most Ex pensive Ordered Product () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Most Ex pensive Ordered Product ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġruby Mine , Ġcustomers [ n athan ] !!. get Most Ex pensive Ordered Product ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Customers Sorted By NumberOf Orders () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Customers Sorted By NumberOf Orders ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsorted Customers , Ġshop . get Customers Sorted By NumberOf Orders ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Total Order Price () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" getTotal Order Price ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 1 4 8 . 0 , Ġcustomers [ n athan ] !!. getTotal Order Price (), Ġ 0 . 0 0 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Total Price For Repeated Products () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" getTotal Order Price ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 5 8 6 . 0 , Ġcustomers [ luc as ] !!. getTotal Order Price (), Ġ 0 . 0 0 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Group Customers By City () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" group Customers By City ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgrouped By C ities , Ġshop . group Customers By City ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Customers Who Have More Un deliver ed Orders Than Deliver ed () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Customer With Maximum NumberOf Orders ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( customers [ re ka ]), Ġshop . get Customers With More Un deliver ed Orders Than Deliver ed ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Products Ordered By All Customers () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Shop Ġ= Ġshop (" test Ġshop Ġfor Ġ' fold '", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcustomer ( luc as , ĠCan b erra , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( idea ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( web Storm ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcustomer ( re ka , ĠB ud ape st , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( idea ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( you Track ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Set Of Products Ordered By Every Customer ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġset Of ( idea ), Ġtest Shop . get Set Of Products Ordered By Every Customer ()) ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Most Ex pensive Deliver ed Product () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtest Shop Ġ= Ġshop (" test Ġshop Ġfor Ġ' most Ġexpensive Ġdelivered Ġproduct '", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcustomer ( luc as , ĠCan b erra , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( is Deliver ed Ġ= Ġfalse , Ġproducts Ġ= Ġ* array Of ( idea )), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġorder ( re Sharper ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" get Most Ex pensive Deliver ed Product ", Ġre Sharper , Ġtest Shop . customers [ 0 ]. get Most Ex pensive Deliver ed Product ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest NumberOf Times Each Product Was Ordered () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals ( 4 , Ġshop . getNumberOf Times Product Was Ordered ( idea )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest NumberOf Times Each Product Was Ordered For Repeated Product () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" A Ġcustomer Ġmay Ġorder Ġa Ġproduct Ġfor Ġseveral Ġtimes ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 3 , Ġshop . getNumberOf Times Product Was Ordered ( re Sharper )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest NumberOf Times Each Product Was Ordered For Repeated In Order Product () Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" An Ġorder Ġmay Ġcontain Ġa Ġparticular Ġproduct Ġmore Ġthan Ġonce ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ 3 , Ġshop . getNumberOf Times Product Was Ordered ( php Storm )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Collection Of One Element () Ġ{ ĊĠĠĠĠĠĠĠ Ġdo Test ( listOf (" a "), ĠlistOf (" a ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Simple Collection () Ġ{ ĊĠĠĠĠĠĠĠ Ġdo Test ( listOf (" a ", Ġ" c "), ĠlistOf (" a ", Ġ" bb ", Ġ" c ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Collection With Empty Strings () Ġ{ ĊĠĠĠĠĠĠĠ Ġdo Test ( listOf ("", Ġ"", Ġ"", Ġ""), ĠlistOf ("", Ġ"", Ġ"", Ġ"", Ġ" a ", Ġ" bb ", Ġ" ccc ", Ġ" dddd ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Collection With Two Groups Of Max imal Size () Ġ{ ĊĠĠĠĠĠĠĠ Ġdo Test ( listOf (" a ", Ġ" c "), ĠlistOf (" a ", Ġ" bb ", Ġ" c ", Ġ" dd ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġdo Test ( expected : ĠCollection < String > ?, Ġargument : ĠCollection < String >) Ġ{ ĊĠĠĠĠĠĠĠ ĠAssert . assertEquals (" The Ġfunction Ġ' do Something Str ange With Collection ' Ġshould Ġdo Ġat Ġleast Ġsomething Ġwith Ġa Ġcollection ", ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġexpected , Ġdo Something Str ange With Collection ( argument )) ĊĠĠĠ Ġ} Ċ }