package Ġdev . d nih ze . rev or ate . model Ċ Ċ import Ġorg . junit . Assert . assertEquals Ċ import Ġorg . junit . Test Ċ Ċ class ĠExchange Rate Test Ġ{ ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġsimple Usage Works () Ġ{ ĊĠĠĠĠĠĠĠ ĠExchange Rate ( 2 . 0 , ĠCurrency . EUR , ĠCurrency . USD ) ĊĠĠĠĠĠĠĠ ĠExchange Rate ( 1 . 0 , ĠCurrency . EUR , ĠCurrency . EUR ) ĊĠĠĠĠĠĠĠ ĠExchange Rate ( 1 . 0 , ĠCurrency . EUR , ĠCurrency . CAD ) ĊĠĠĠĠĠĠĠ ĠExchange Rate ( 0 . 5 , ĠCurrency . USD , ĠCurrency . EUR ) ĊĠĠĠĠĠĠĠ ĠExchange Rate ( 0 . 0 0 0 0 0 1 , ĠCurrency . USD , ĠCurrency . EUR ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠAssertionError :: class ) ĊĠĠĠ Ġfun Ġsame C urrencies Fails With Non One Exchange Rate () Ġ{ ĊĠĠĠĠĠĠĠ ĠExchange Rate ( 0 . 5 , ĠCurrency . USD , ĠCurrency . USD ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠAssertionError :: class ) ĊĠĠĠ Ġfun Ġexchange Rate Zero Fails () Ġ{ ĊĠĠĠĠĠĠĠ ĠExchange Rate (. 0 , ĠCurrency . EUR , ĠCurrency . USD ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠAssertionError :: class ) ĊĠĠĠ Ġfun Ġnegative Exchange Rate Fails () Ġ{ ĊĠĠĠĠĠĠĠ ĠExchange Rate (- 1 . 0 , ĠCurrency . EUR , ĠCurrency . USD ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinvert Self Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġsimple In verted Ġ= ĠExchange Rate ( 0 . 5 , ĠCurrency . USD , ĠCurrency . EUR ). invert () ĊĠĠĠĠĠĠĠ ĠassertEquals ( 2 . 0 , Ġsimple In verted . rate , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . EUR , Ġsimple In verted . for Currency ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġsimple In verted . of Currency ) ĊĊĠĠĠĠĠĠĠ Ġval Ġinverted Same Base Ġ= ĠExchange Rate ( 1 . 0 , ĠCurrency . USD , ĠCurrency . USD ). invert () ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 . 0 , Ġinverted Same Base . rate , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġinverted Same Base . for Currency ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġinverted Same Base . of Currency ) ĊĊĠĠĠĠĠĠĠ Ġval Ġinverted One Exchange Rate Ġ= ĠExchange Rate ( 1 . 0 , ĠCurrency . USD , ĠCurrency . SE K ). invert () ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 . 0 , Ġinverted One Exchange Rate . rate , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . SE K , Ġinverted One Exchange Rate . for Currency ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġinverted One Exchange Rate . of Currency ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġinvert With Different Exchange Rate Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdifferent Ġ= ĠExchange Rate ( 2 . 0 , ĠCurrency . USD , ĠCurrency . CAD ) ĊĠĠĠĠĠĠĠ Ġval Ġsimple In verted Ġ= ĠExchange Rate ( 1 . 0 , ĠCurrency . USD , ĠCurrency . EUR ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. invert Rate With New Base ( different ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 . 5 , Ġsimple In verted . rate , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . CAD , Ġsimple In verted . for Currency ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . EUR , Ġsimple In verted . of Currency ) ĊĊĠĠĠĠĠĠĠ Ġval Ġinverted Same Base Ġ= ĠExchange Rate ( 1 . 0 , ĠCurrency . USD , ĠCurrency . USD ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. invert Rate With New Base ( different ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 0 . 5 , Ġinverted Same Base . rate , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . CAD , Ġinverted Same Base . for Currency ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġinverted Same Base . of Currency ) ĊĊĠĠĠĠĠĠĠ Ġval Ġinverted Same Rate Ġ= Ġdifferent . copy () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. invert Rate With New Base ( different ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( 1 . 0 , Ġinverted Same Rate . rate , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . CAD , Ġinverted Same Rate . for Currency ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . CAD , Ġinverted Same Rate . of Currency ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠAssertionError :: class ) ĊĠĠĠ Ġfun Ġdifferent Base Invert Fails () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdifferent Ġ= ĠExchange Rate ( 2 . 0 , ĠCurrency . USD , ĠCurrency . CAD ) ĊĠĠĠĠĠĠĠ ĠExchange Rate ( 1 . 0 , ĠCurrency . EUR , ĠCurrency . RON ). invert Rate With New Base ( different ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠIllegalArgumentException :: class ) ĊĠĠĠ Ġfun Ġdifferent Same C urrencies Different Rate Fails () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġdifferent Ġ= ĠExchange Rate ( 2 . 0 , ĠCurrency . USD , ĠCurrency . CAD ) ĊĠĠĠĠĠĠĠ ĠExchange Rate ( 1 . 0 , ĠCurrency . USD , ĠCurrency . CAD ). invert Rate With New Base ( different ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġconverting Empty With Same Base Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexchange Rate Ġ= ĠExchange Rate ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrate Ġ= Ġ 2 . 0 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġof Currency Ġ= ĠCurrency . USD , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfor Currency Ġ= ĠCurrency . EUR ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġempty Ġ= ĠCurrency Amount (. 0 , ĠCurrency . EUR ) ĊĠĠĠĠĠĠĠ Ġval Ġconverted Amount Ġ= Ġexchange Rate Ġ* Ġempty ĊĊĠĠĠĠĠĠĠ ĠassertEquals (. 0 , Ġconverted Amount . amount , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġconverted Amount . currency ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġconverting Non Empty With Same Base Works () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexchange Rate Ġ= ĠExchange Rate ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrate Ġ= Ġ 2 . 0 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġof Currency Ġ= ĠCurrency . USD , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfor Currency Ġ= ĠCurrency . EUR ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnon Empty Whole Ġ= ĠCurrency Amount ( 2 . 0 , ĠCurrency . EUR ) ĊĠĠĠĠĠĠĠ Ġval Ġconverted Whole Ġ= Ġ Ġexchange Rate Ġ* Ġnon Empty Whole ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( 4 . 0 , Ġconverted Whole . amount , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġconverted Whole . currency ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnon Empty Without Round ing Ġ= ĠCurrency Amount ( 1 . 5 , ĠCurrency . EUR ) ĊĠĠĠĠĠĠĠ Ġval Ġconverted Without Round ing Ġ= Ġ Ġexchange Rate Ġ* Ġnon Empty Without Round ing ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 . 0 , Ġconverted Without Round ing . amount , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġconverted Without Round ing . currency ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnon Empty With Round ing Ġ= ĠCurrency Amount ( 1 . 5 0 0 1 , ĠCurrency . EUR ) ĊĠĠĠĠĠĠĠ Ġval Ġconverted With Round ing Ġ= Ġ Ġexchange Rate Ġ* Ġnon Empty With Round ing ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 . 0 , Ġconverted With Round ing . amount , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġconverted With Round ing . currency ) ĊĊĠĠĠĠĠĠĠ Ġval Ġnon Empty With Round ing 2 Ġ= ĠCurrency Amount ( 1 . 5 0 9 , ĠCurrency . EUR ) ĊĠĠĠĠĠĠĠ Ġval Ġconverted With Round ing 2 Ġ= Ġexchange Rate Ġ* Ġnon Empty With Round ing 2 ĊĊĠĠĠĠĠĠĠ ĠassertEquals ( 3 . 0 2 , Ġconverted With Round ing 2 . amount , Ġ 0 . 0 ) ĊĠĠĠĠĠĠĠ ĠassertEquals ( Currency . USD , Ġconverted With Round ing 2 . currency ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ( expected Ġ= ĠAssertionError :: class ) ĊĠĠĠ Ġfun Ġconverting With Different Bases Fails () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexchange Rate Ġ= ĠExchange Rate ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrate Ġ= Ġ 2 . 0 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġof Currency Ġ= ĠCurrency . USD , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġfor Currency Ġ= ĠCurrency . EUR ĊĠĠĠĠĠĠĠ Ġ) ĊĊĠĠĠĠĠĠĠ Ġexchange Rate Ġ* ĠCurrency Amount (. 0 , ĠCurrency . CAD ) ĊĠĠĠ Ġ} Ċ Ċ }