package Ġcom . github . fs bar ata . functional . data . complex Ċ Ċ import Ġcom . github . fs bar ata . functional . control . Monad L aws Ċ import Ġcom . github . fs bar ata . functional . data . Tra versable L aws Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Test Ċ Ċ class ĠComplex Test : ĠMonad L aws < Complex Context >, ĠTra versable L aws < Complex Context > Ġ{ Ċ ĉ override Ġval Ġmon ad Scope Ġ= ĠComplex Ċ ĉ override Ġval Ġtra versable Scope Ġ= ĠComplex ĊĊ ĉ override Ġval Ġpossib ilities : ĠInt Ġ= Ġ 5 ĊĊ ĉ override Ġfun Ġfactory ( poss ibility : ĠInt ) Ġ= ĠComplex ( poss ibility , Ġpossibility Ġ% Ġ 3 ) ĊĊ ĉ override Ġfun Ġ< A > Ġcreate Tra versable ( var arg Ġitems : ĠA ) Ġ= Ċĉ ĉ Complex ( items [ 0 ], Ġitems . get OrNull ( 1 ) Ġ?: Ġitems [ 0 ]) ĊĊ ĉ @ Test Ċ ĉ fun Ġconj ug ate () Ġ{ Ċĉ ĉ assertEquals ( Ċĉĉ ĉ Complex ( 1 , Ġ 3 ), Ċĉĉ ĉ Complex ( 1 , Ġ- 3 ). conj ug ate () Ċĉ ĉ ) Ċĉ ĉ assertEquals ( Ċĉĉ ĉ Complex (- 4 L , Ġ 3 L ), Ċĉĉ ĉ Complex (- 4 L , Ġ- 3 L ). conj ug ate () Ċĉ ĉ ) ĊĊĉ ĉ assertEquals ( Ċĉĉ ĉ Complex ( 1 . 2 f , Ġ- 3 f ), Ċĉĉ ĉ Complex ( 1 . 2 f , Ġ 3 f ). conj ug ate () Ċĉ ĉ ) ĊĊĉ ĉ assertEquals ( Ċĉĉ ĉ Complex (- 1 . 2 , Ġ- 3 . 5 ), Ċĉĉ ĉ Complex (- 1 . 2 , Ġ 3 . 5 ). conj ug ate () Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġmagnitude () Ġ{ Ċĉ ĉ assertEquals ( Ċĉĉĉ 5 . 0 , Ċĉĉ ĉ Complex ( 3 , Ġ 4 ). magnitude (), Ċĉĉĉ 1 e - 1 0 Ċĉ ĉ ) ĊĊĉ ĉ assertEquals ( Ċĉĉĉ 5 . 0 , Ċĉĉ ĉ Complex ( 3 f , Ġ- 4 f ). magnitude (), Ċĉĉĉ 1 e - 1 0 Ċĉ ĉ ) ĊĊĉ ĉ assertEquals ( Ċĉĉĉ 5 . 0 , Ċĉĉ ĉ Complex (- 3 . 0 , Ġ 4 . 0 ). magnitude (), Ċĉĉĉ 1 e - 1 0 Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġphase () Ġ{ Ċĉ ĉ assertEquals ( Ċĉĉĉ 5 3 . 1 3 0 1 , Ċĉĉ ĉ Math . to Degrees ( Complex ( 3 , Ġ 4 ). phase ()), Ċĉĉĉ 1 e - 4 Ċĉ ĉ ) ĊĊĉ ĉ assertEquals ( Ċĉĉ ĉ - 5 3 . 1 3 0 1 , Ċĉĉ ĉ Math . to Degrees ( Complex ( 3 f , Ġ- 4 f ). phase ()), Ċĉĉĉ 1 e - 4 Ċĉ ĉ ) ĊĊĉ ĉ assertEquals ( Ċĉĉ ĉ - 1 2 6 . 8 6 9 9 , Ċĉĉ ĉ Math . to Degrees ( Complex (- 3 . 0 , Ġ- 4 . 0 ). phase ()), Ċĉĉĉ 1 e - 4 Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġfrom Pol ar () Ġ{ Ċĉ ĉ assertEquals ( Ċĉĉ ĉ Complex ( 0 . 0 , Ġ 1 . 0 ), Ċĉĉ ĉ Complex . from Pol ar ( theta Ġ= ĠMath . to Radians ( 9 0 . 0 )), Ċĉĉĉ 1 e - 1 0 , Ċĉ ĉ ) ĊĊĉ ĉ assertEquals ( Ċĉĉ ĉ Complex ( 1 . 0 , Ġ 0 . 0 ), Ċĉĉ ĉ Complex . from Pol ar ( theta Ġ= Ġ 0 . 0 ), Ċĉĉĉ 1 e - 1 0 , Ċĉ ĉ ) ĊĊĉ ĉ assertEquals ( Ċĉĉ ĉ Complex ( 1 . 3 0 , Ġ- 0 . 7 5 ), Ċĉĉ ĉ Complex . from Pol ar ( radius Ġ= Ġ 1 . 5 , Ġtheta Ġ= ĠMath . to Radians (- 3 0 . 0 )), Ċĉĉĉ 1 e - 3 , Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ private Ġfun ĠassertEquals ( expected : ĠComplex < Double >, Ġactual : ĠComplex < Double >, Ġepsilon : ĠDouble ) Ġ{ Ċĉ ĉ assertEquals ( expected . real , Ġactual . real , Ġepsilon ) Ċĉ ĉ assertEquals ( expected . imag , Ġactual . imag , Ġepsilon ) Ċ ĉ } Ċ }