package Ġlesson 8 . task 2 Ċ Ċ import Ġorg . junit . jupiter . api . Assertions .* Ċ import Ġorg . junit . jupiter . api . Tag Ċ import Ġorg . junit . jupiter . api . Test Ċ import Ġkotlin . math . abs Ċ Ċ class ĠTests Ġ{ ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" Example ") ĊĠĠĠ Ġfun Ġinside () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertTrue ( Square ( 1 , Ġ 1 ). inside ()) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Square ( 8 , Ġ 8 ). inside ()) ĊĠĠĠĠĠĠĠ ĠassertTrue ( Square ( 1 , Ġ 8 ). inside ()) ĊĠĠĠĠĠĠĠ ĠassertFalse ( Square ( 0 , Ġ 0 ). inside ()) ĊĠĠĠĠĠĠĠ ĠassertFalse ( Square ( 0 , Ġ 1 ). inside ()) ĊĠĠĠĠĠĠĠ ĠassertFalse ( Square ( 9 , Ġ 4 ). inside ()) ĊĠĠĠĠĠĠĠ ĠassertFalse ( Square ( 6 , Ġ 9 ). inside ()) ĊĠĠĠĠĠĠĠ ĠassertFalse ( Square ( 1 0 0 , Ġ 1 ). inside ()) ĊĠĠĠĠĠĠĠ ĠassertFalse ( Square ( 7 , Ġ- 1 0 0 ). inside ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 2 ") ĊĠĠĠ Ġfun Ġnotation () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ("", ĠSquare ( 1 , Ġ 0 ). notation ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" b 3 ", ĠSquare ( 2 , Ġ 3 ). notation ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" g 6 ", ĠSquare ( 7 , Ġ 6 ). notation ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" a 8 ", ĠSquare ( 1 , Ġ 8 ). notation ()) ĊĠĠĠĠĠĠĠ ĠassertEquals (" h 1 ", ĠSquare ( 8 , Ġ 1 ). notation ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 2 ") ĊĠĠĠ Ġfun Ġsquare () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( Square ( 3 , Ġ 2 ), Ġsquare (" c 2 ")) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Square ( 5 , Ġ 5 ), Ġsquare (" e 5 ")) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Square ( 6 , Ġ 8 ), Ġsquare (" f 8 ")) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Square ( 4 , Ġ 1 ), Ġsquare (" d 1 ")) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 2 ") ĊĠĠĠ Ġfun Ġro ok Move Number () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġro ok Move Number ( square (" e 3 "), Ġsquare (" e 3 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġro ok Move Number ( square (" c 2 "), Ġsquare (" b 1 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġro ok Move Number ( square (" g 8 "), Ġsquare (" f 6 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġro ok Move Number ( square (" a 8 "), Ġsquare (" g 8 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġro ok Move Number ( square (" h 3 "), Ġsquare (" h 8 "))) ĊĠĠĠĠĠĠĠ ĠassertThrows ( IllegalArgumentException :: class . java ) Ġ{ Ġro ok Move Number ( square (" a 0 "), Ġsquare (" h 8 ")) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠList < Square >. assert R ook Trajectory ( start : ĠSquare , Ġend : ĠSquare , Ġlength : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( length Ġ+ Ġ 1 , Ġsize ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( start , Ġfirst ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( end , Ġlast ()) ĊĠĠĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 0 .. size Ġ- Ġ 2 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġprevious Ġ= Ġthis [ i ] ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnext Ġ= Ġthis [ i Ġ+ Ġ 1 ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( previous . row Ġ== Ġnext . row Ġ|| Ġprevious . column Ġ== Ġnext . column ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 3 ") ĊĠĠĠ Ġfun Ġro ok Trajectory () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" g 5 ")), Ġro ok Trajectory ( square (" g 5 "), Ġsquare (" g 5 "))) ĊĠĠĠĠĠĠĠ Ġro ok Trajectory ( square (" c 3 "), Ġsquare (" h 6 ")). assert R ook Trajectory ( square (" c 3 "), Ġsquare (" h 6 "), Ġ 2 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" h 2 "), Ġsquare (" h 7 ")), Ġro ok Trajectory ( square (" h 2 "), Ġsquare (" h 7 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" a 2 "), Ġsquare (" h 2 ")), Ġro ok Trajectory ( square (" a 2 "), Ġsquare (" h 2 "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 2 ") ĊĠĠĠ Ġfun Ġb ish op Move Number () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals (- 1 , Ġb ish op Move Number ( square (" a 1 "), Ġsquare (" g 8 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals (- 1 , Ġb ish op Move Number ( square (" c 1 "), Ġsquare (" f 3 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġb ish op Move Number ( square (" d 4 "), Ġsquare (" d 4 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġb ish op Move Number ( square (" a 3 "), Ġsquare (" e 7 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġb ish op Move Number ( square (" c 1 "), Ġsquare (" c 7 "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠList < Square >. assert B ish op Trajectory ( start : ĠSquare , Ġend : ĠSquare , Ġlength : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( length Ġ+ Ġ 1 , Ġsize ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( start , Ġfirst ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( end , Ġlast ()) ĊĠĠĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 0 .. size Ġ- Ġ 2 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġprevious Ġ= Ġthis [ i ] ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnext Ġ= Ġthis [ i Ġ+ Ġ 1 ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( abs ( next . row Ġ- Ġprevious . row ) Ġ== Ġabs ( next . column Ġ- Ġprevious . column )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 5 ") ĊĠĠĠ Ġfun Ġb ish op Trajectory () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf < Square >(), Ġb ish op Trajectory ( square (" a 1 "), Ġsquare (" g 8 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf < Square >(), Ġb ish op Trajectory ( square (" c 1 "), Ġsquare (" f 3 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" d 4 ")), Ġb ish op Trajectory ( square (" d 4 "), Ġsquare (" d 4 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" a 3 "), Ġsquare (" e 7 ")), Ġb ish op Trajectory ( square (" a 3 "), Ġsquare (" e 7 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" c 1 "), Ġsquare (" f 4 "), Ġsquare (" c 7 ")), Ġb ish op Trajectory ( square (" c 1 "), Ġsquare (" c 7 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" f 1 "), Ġsquare (" c 4 "), Ġsquare (" f 7 ")), Ġb ish op Trajectory ( square (" f 1 "), Ġsquare (" f 7 "))) ĊĠĠĠĠĠĠĠ Ġb ish op Trajectory ( square (" d 2 "), Ġsquare (" e 5 ")). assert B ish op Trajectory ( square (" d 2 "), Ġsquare (" e 5 "), Ġ 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 3 ") ĊĠĠĠ Ġfun Ġking Move Number () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġking Move Number ( square (" e 3 "), Ġsquare (" e 3 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġking Move Number ( square (" c 2 "), Ġsquare (" b 1 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġking Move Number ( square (" g 8 "), Ġsquare (" f 6 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 6 , Ġking Move Number ( square (" a 8 "), Ġsquare (" g 8 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 7 , Ġking Move Number ( square (" a 1 "), Ġsquare (" h 8 "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠList < Square >. assert King Trajectory ( start : ĠSquare , Ġend : ĠSquare , Ġlength : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( length Ġ+ Ġ 1 , Ġsize ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( start , Ġfirst ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( end , Ġlast ()) ĊĠĠĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 0 .. size Ġ- Ġ 2 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġprevious Ġ= Ġthis [ i ] ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnext Ġ= Ġthis [ i Ġ+ Ġ 1 ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( abs ( next . column Ġ- Ġprevious . column ) Ġ<= Ġ 1 ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( abs ( next . row Ġ- Ġprevious . row ) Ġ<= Ġ 1 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 5 ") ĊĠĠĠ Ġfun Ġking Trajectory () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" f 3 ")), Ġking Trajectory ( square (" f 3 "), Ġsquare (" f 3 "))) ĊĠĠĠĠĠĠĠ Ġking Trajectory ( square (" c 2 "), Ġsquare (" a 6 ")). assert King Trajectory ( square (" c 2 "), Ġsquare (" a 6 "), Ġ 4 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( square (" h 2 "), Ġsquare (" g 3 "), Ġsquare (" f 4 "), Ġsquare (" e 5 "), Ġsquare (" d 6 "), Ġsquare (" c 7 ")), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġking Trajectory ( square (" h 2 "), Ġsquare (" c 7 ")) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 6 ") ĊĠĠĠ Ġfun Ġk night Move Number () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 , Ġk night Move Number ( square (" d 3 "), Ġsquare (" d 3 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 , Ġk night Move Number ( square (" e 4 "), Ġsquare (" d 6 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 , Ġk night Move Number ( square (" f 5 "), Ġsquare (" g 6 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġk night Move Number ( square (" g 6 "), Ġsquare (" g 3 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 , Ġk night Move Number ( square (" d 4 "), Ġsquare (" a 8 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 4 , Ġk night Move Number ( square (" h 7 "), Ġsquare (" f 5 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 4 , Ġk night Move Number ( square (" g 7 "), Ġsquare (" h 8 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 6 , Ġk night Move Number ( square (" a 8 "), Ġsquare (" h 1 "))) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠList < Square >. assert K night Trajectory ( start : ĠSquare , Ġend : ĠSquare , Ġlength : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( length Ġ+ Ġ 1 , Ġsize ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( start , Ġfirst ()) ĊĠĠĠĠĠĠĠ ĠassertEquals ( end , Ġlast ()) ĊĠĠĠĠĠĠĠ Ġfor Ġ( i Ġin Ġ 0 .. size Ġ- Ġ 2 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġprevious Ġ= Ġthis [ i ] ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnext Ġ= Ġthis [ i Ġ+ Ġ 1 ] ĊĠĠĠĠĠĠĠĠĠĠĠ ĠassertTrue ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġabs ( next . column Ġ- Ġprevious . column ) Ġ== Ġ 2 Ġ&& Ġabs ( next . row Ġ- Ġprevious . row ) Ġ== Ġ 1 Ġ|| ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġabs ( next . column Ġ- Ġprevious . column ) Ġ== Ġ 1 Ġ&& Ġabs ( next . row Ġ- Ġprevious . row ) Ġ== Ġ 2 ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Tag (" 1 0 ") ĊĠĠĠ Ġfun Ġk night Trajectory () Ġ{ ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" d 3 ")), Ġk night Trajectory ( square (" d 3 "), Ġsquare (" d 3 "))) ĊĠĠĠĠĠĠĠ ĠassertEquals ( listOf ( square (" e 4 "), Ġsquare (" d 6 ")), Ġk night Trajectory ( square (" e 4 "), Ġsquare (" d 6 "))) ĊĠĠĠĠĠĠĠ Ġk night Trajectory ( square (" f 5 "), Ġsquare (" g 6 ")). assert K night Trajectory ( square (" f 5 "), Ġsquare (" g 6 "), Ġ 2 ) ĊĠĠĠĠĠĠĠ Ġk night Trajectory ( square (" g 6 "), Ġsquare (" g 3 ")). assert K night Trajectory ( square (" g 6 "), Ġsquare (" g 3 "), Ġ 3 ) ĊĠĠĠĠĠĠĠ Ġk night Trajectory ( square (" d 4 "), Ġsquare (" a 8 ")). assert K night Trajectory ( square (" d 4 "), Ġsquare (" a 8 "), Ġ 3 ) ĊĠĠĠĠĠĠĠ Ġk night Trajectory ( square (" h 7 "), Ġsquare (" f 5 ")). assert K night Trajectory ( square (" h 7 "), Ġsquare (" f 5 "), Ġ 4 ) ĊĠĠĠĠĠĠĠ Ġk night Trajectory ( square (" g 7 "), Ġsquare (" h 8 ")). assert K night Trajectory ( square (" g 7 "), Ġsquare (" h 8 "), Ġ 4 ) ĊĠĠĠĠĠĠĠ Ġk night Trajectory ( square (" a 1 "), Ġsquare (" a 8 ")). assert K night Trajectory ( square (" a 1 "), Ġsquare (" a 8 "), Ġ 5 ) ĊĠĠĠĠĠĠĠ Ġk night Trajectory ( square (" a 8 "), Ġsquare (" h 1 ")). assert K night Trajectory ( square (" a 8 "), Ġsquare (" h 1 "), Ġ 6 ) ĊĠĠĠ Ġ} Ċ } Ċ