package Ġdata _ structures . linked _ list Ċ Ċ import Ġcom . google . common . truth . Truth Ċ import Ġorg . junit . jupiter . api . BeforeEach Ċ import Ġorg . junit . jupiter . api . Test Ċ Ċ internal Ġclass ĠSing ly LinkedList Test Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġsing ly LinkedList : ĠSing ly LinkedList < Int > ĊĊĠĠĠ Ġ@ BeforeEach ĊĠĠĠ Ġfun Ġsetup () Ġ{ ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList Ġ= ĠSing ly LinkedList () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Empty () Ġ{ ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . isEmpty ()). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Add At Head () Ġ{ ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 5 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Add At Tail () Ġ{ ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 5 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Add At () Ġ{ ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add AtIndex ( 0 , Ġ 1 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add AtIndex ( 1 , Ġ 2 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add AtIndex ( 1 , Ġ 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 3 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add AtIndex ( 2 , Ġ 4 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 4 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add AtIndex ( 1 , Ġ 8 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 5 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Clear () Ġ{ ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 2 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . clear () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . head ). isNull () ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 2 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 3 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . clear () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 0 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . head ). isNull () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Head () Ġ{ ĊĠĠĠĠĠĠĠ Ġorg . junit . jupiter . api . assert Throws < RuntimeException >(" List Ġis Ġempty ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsing ly LinkedList . get Head () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . get Head ()). isEqualTo ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun ĠtestGet Tail () Ġ{ ĊĠĠĠĠĠĠĠ Ġorg . junit . jupiter . api . assert Throws < RuntimeException >(" List Ġis Ġempty ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsing ly LinkedList . get Tail () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . get Tail ()). isEqualTo ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . size ). isEqualTo ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Remove Head () Ġ{ ĊĠĠĠĠĠĠĠ Ġorg . junit . jupiter . api . assert Throws < RuntimeException >(" List Ġis Ġempty ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsing ly LinkedList . remove Head () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 5 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . remove Head ()). isEqualTo ( 5 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . isEmpty ()). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Remove Tail () Ġ{ ĊĠĠĠĠĠĠĠ Ġorg . junit . jupiter . api . assert Throws < RuntimeException >(" List Ġis Ġempty ") Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġsing ly LinkedList . remove Tail () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 5 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . remove Tail ()). isEqualTo ( 5 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . isEmpty ()). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Remove AtIndex () Ġ{ ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 1 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 2 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 3 5 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 2 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . remove AtIndex ( 0 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . remove AtIndex ( 2 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . get Head ()). isEqualTo ( 2 1 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . get Tail ()). isEqualTo ( 3 5 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . remove AtIndex ( 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . remove AtIndex ( 0 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . isEmpty ()). isTrue () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest Reverse () Ġ{ ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 5 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 4 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 3 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 2 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Head ( 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . reverse () ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . remove Head ()). isEqualTo ( 5 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . remove Head ()). isEqualTo ( 4 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . remove Head ()). isEqualTo ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . remove Head ()). isEqualTo ( 2 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . remove Head ()). isEqualTo ( 1 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġtest ToString () Ġ{ ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . toString ()). isEqualTo (" [] ") ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 1 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 2 ) ĊĠĠĠĠĠĠĠ Ġsing ly LinkedList . add At Tail ( 3 ) ĊĠĠĠĠĠĠĠ ĠTr uth . assertThat ( sing ly LinkedList . toString ()). isEqualTo ("[ 1 , Ġ 2 , Ġ 3 ]") ĊĠĠĠ Ġ} Ċ }