package Ġcom . example . android . architecture . blueprint s . todo app . statistics Ċ Ċ import Ġcom . example . android . architecture . blueprint s . todo app . data . Task Ċ import Ġorg . hamcrest . Matcher Assert . assertThat Ċ import Ġorg . hamcrest . Matchers .` is ` Ċ // import Ġjunit . framework . Assert . assertEquals Ċ // import Ġorg . junit . Assert Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Test ĊĊ Ċ // class ĠStatistics UtilsTest Ġ: ĠTestCase (){ Ċ class ĠStatistics UtilsTest { Ċ Ċ // ĠĠĠ ĠYou 're Ġgoing Ġto Ġwrite Ġa Ġtest Ġthat Ġchecks : Ċ // ĠĠĠ Ġif Ġthere Ġare Ġno Ġcompleted Ġtasks Ġand Ġone Ġactive Ġtask , Ċ // ĠĠĠ Ġthat Ġthe Ġpercentage Ġof Ġactive Ġtests Ġis Ġ 1 0 0 %, Ċ // ĠĠĠ Ġand Ġthe Ġpercentage Ġof Ġcompleted Ġtasks Ġis Ġ 0 % ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Active And Completed Stats _ no Completed _ returns H undred Zero (){ ĊĠĠĠĠĠĠĠ Ġ// ĠCreate Ġan Ġactive Ġtask ĊĠĠĠĠĠĠĠ Ġval Ġtasks Ġ= ĠlistOf < Task >( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTask (" title ", Ġ" description ", Ġis Completed Ġ= Ġfalse ) ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCall Ġyour Ġfunction ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġget Active And Completed Stats ( tasks ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠCheck Ġthe Ġresult ĊĠĠĠĠĠĠĠ Ġ// REPLACE Ċ // ĠĠĠĠĠĠĠ ĠassertEquals ( result . completed Tasks Percent , Ġ 0 f ) Ċ // ĠĠĠĠĠĠĠ ĠassertEquals ( result . active Tasks Percent , Ġ 1 0 0 f ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠWITH ĊĠĠĠĠĠĠĠ ĠassertThat ( result . active Tasks Percent , Ġ` is `( 1 0 0 f )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . completed Tasks Percent , Ġ` is `( 0 f )) ĊĠĠĠ Ġ} ĊĊĊĊĠĠĠ Ġ/* Instead Ġof Ġstarting Ġby Ġfixing Ġthe Ġbug , Ġyou 'll Ġstart Ġby Ġwriting Ġthe Ġtests Ġfirst . ĊĠĠĠ ĠThen Ġyou Ġcan Ġconfirm Ġthat Ġyou Ġhave Ġtests Ġprotect ing Ġyou Ġfrom Ġever Ġaccidentally ĊĠĠĠ Ġre intro ducing Ġthese Ġbugs Ġin Ġthe Ġfuture . ĊĊĠĠĠĠ 1 . If Ġthere Ġis Ġan Ġempty Ġlist Ġ( emptyList ()), Ġthen Ġboth Ġpercent ages Ġshould Ġbe Ġ 0 f . ĊĠĠĠĠ 2 . If Ġthere Ġwas Ġan Ġerror Ġloading Ġthe Ġtasks , Ġthe Ġlist Ġwill Ġbe Ġnull , Ġand Ġboth Ġpercent ages Ġshould Ġbe Ġ 0 f . ĊĠĠĠĠ 3 . Run Ġyour Ġtests Ġand Ġconfirm Ġthat Ġthey Ġfail : */ ĊĊĠĠĠ Ġ// getActive And Completed Stats _ no Active _ returns Zero H undred ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Active And Completed Stats _ no Active _ returns Zero H undred () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġtasks Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTask (" title ", Ġ" desc ", Ġis Completed Ġ= Ġtrue ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ// ĠWhen Ġthe Ġlist Ġof Ġtasks Ġis Ġcomputed Ġwith Ġa Ġcompleted Ġtask ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġget Active And Completed Stats ( tasks ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen Ġthe Ġpercent ages Ġare Ġ 0 Ġand Ġ 1 0 0 ĊĠĠĠĠĠĠĠ ĠassertThat ( result . active Tasks Percent , Ġ` is `( 0 f )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . completed Tasks Percent , Ġ` is `( 1 0 0 f )) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ// getActive And Completed Stats _ both _ returns Fort y Six ty ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Active And Completed Stats _ both _ returns Fort y Six ty () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠGiven Ġ 3 Ġcompleted Ġtasks Ġand Ġ 2 Ġactive Ġtasks ĊĠĠĠĠĠĠĠ Ġval Ġtasks Ġ= ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTask (" title ", Ġ" desc ", Ġis Completed Ġ= Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTask (" title ", Ġ" desc ", Ġis Completed Ġ= Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTask (" title ", Ġ" desc ", Ġis Completed Ġ= Ġtrue ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTask (" title ", Ġ" desc ", Ġis Completed Ġ= Ġfalse ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠTask (" title ", Ġ" desc ", Ġis Completed Ġ= Ġfalse ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ// ĠWhen Ġthe Ġlist Ġof Ġtasks Ġis Ġcomputed ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġget Active And Completed Stats ( tasks ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠThen Ġthe Ġresult Ġis Ġ 4 0 - 6 0 ĊĠĠĠĠĠĠĠ ĠassertThat ( result . active Tasks Percent , Ġ` is `( 4 0 f )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . completed Tasks Percent , Ġ` is `( 6 0 f )) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ// getActive And Completed Stats _ error _ returns Z eros ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Active And Completed Stats _ error _ returns Z eros () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠWhen Ġthere 's Ġan Ġerror Ġloading Ġstats ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġget Active And Completed Stats ( null ) ĊĊĠĠĠĠĠĠĠ Ġ// ĠBoth Ġactive Ġand Ġcompleted Ġtasks Ġare Ġ 0 ĊĠĠĠĠĠĠĠ ĠassertThat ( result . active Tasks Percent , Ġ` is `( 0 f )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . completed Tasks Percent , Ġ` is `( 0 f )) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ// getActive And Completed Stats _ empty _ returns Z eros ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġget Active And Completed Stats _ empty _ returns Z eros () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠWhen Ġthere Ġare Ġno Ġtasks ĊĠĠĠĠĠĠĠ Ġval Ġresult Ġ= Ġget Active And Completed Stats ( emptyList ()) ĊĊĠĠĠĠĠĠĠ Ġ// ĠBoth Ġactive Ġand Ġcompleted Ġtasks Ġare Ġ 0 ĊĠĠĠĠĠĠĠ ĠassertThat ( result . active Tasks Percent , Ġ` is `( 0 f )) ĊĠĠĠĠĠĠĠ ĠassertThat ( result . completed Tasks Percent , Ġ` is `( 0 f )) ĊĠĠĠ Ġ} Ċ }