/* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 1 6 . ĠSun gh you k ĠB ae Ġ< sun gh you k . bae @ gmail . com > Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ* Ċ Ġ*/ Ċ Ċ package Ġdeb op 4 k . units Ċ Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . assertj . core . api . Assertions . assertThat Thrown By Ċ import Ġorg . junit . Test Ċ Ċ class ĠMass Kotlin Test Ġ: ĠAbstract Unit Kotlin Test () Ġ{ ĊĊĠ Ġ@ Test Ġfun Ġconvert Mass Unit () Ġ{ ĊĠĠĠ Ġval Ġmillis Ġ= Ġ 1 . 0 . mill ig ram () ĊĠĠĠ Ġval Ġmg Ġ= Ġmillis . in M ill ig ram () ĊĊĠĠĠ ĠassertThat ( mg ). isEqualTo ( 1 . 0 ) ĊĊĠĠĠ ĠassertThat ( 1 . 0 . mill ig ram (). in M ill ig ram ()). isEqualTo ( 1 . 0 ) ĊĠĠĠ ĠassertThat ( 1 . 0 . gram (). in Gram ()). isEqualTo ( 1 . 0 ) ĊĠĠĠ ĠassertThat ( 1 . ki log ram (). in K ilog ram ()). isEqualTo ( 1 . 0 ) ĊĠĠĠ ĠassertThat ( 1 . ton (). in T on ()). isEqualTo ( 1 . 0 ) ĊĊĠĠĠ ĠassertThat ( 1 0 0 0 . 0 . mill ig ram (). in Gram ()). isEqualTo ( 1 . 0 ) ĊĠĠĠ ĠassertThat ( 1 . 0 . mill ig ram (). in Gram ()). isEqualTo ( 1 . 0 e - 3 ) ĊĠĠĠ ĠassertThat ( 1 . gram (). in M ill ig ram ()). isEqualTo ( 1 0 0 0 . 0 ) ĊĠĠĠ ĠassertThat ( 1 . ki log ram (). in Gram ()). isEqualTo ( 1 0 0 0 . 0 ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġgram To Gram () Ġ{ ĊĊĠĠĠ ĠassertThat ( 5 . 0 . gram (). gram ). isEqualTo ( 5 . 0 , ĠT OL ER ANCE ) ĊĠĠĠ ĠassertThat ( Double . POSITIVE _ INFINITY . gram (). gram ). isEqualTo ( Double . POSITIVE _ INFINITY ) ĊĠĠĠ ĠassertThat ( Mass . POSITIVE _ INF . gram ). isEqualTo ( Double . POSITIVE _ INFINITY ) ĊĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġto Human () Ġ{ ĊĠĠĠ ĠassertThat ( 9 0 0 . mill ig ram (). to Human ()). isEqualTo (" 9 0 0 . 0 Ġmg ") ĊĠĠĠ ĠassertThat ( 1 0 . 5 . ki log ram (). to Human ()). isEqualTo (" 1 0 . 5 Ġk g ") ĊĠĠĠ ĠassertThat ( 1 0 . 5 6 . ki log ram (). to Human ()). isEqualTo (" 1 0 . 6 Ġk g ") ĊĊĠĠĠ ĠassertThat ( 1 0 0 5 0 . gram (). to Human ()). isEqualTo (" 1 0 . 1 Ġk g ") ĊĠĠĠ Ġ// ĠĠĠ ĠassertThat ( gram ( Integer . MAX _ VALUE ). to Human ()). isEqualTo (" 2 1 4 7 . 5 Ġton "); ĊĊĠĠĠ ĠassertThat ( 9 0 0 . mill ig ram (). to Human ()). isEqualTo (" 9 0 0 . 0 Ġmg ") ĊĠĠĠ ĠassertThat ( 1 0 . 5 . ki log ram (). to Human ()). isEqualTo (" 1 0 . 5 Ġk g ") ĊĠĠĠ ĠassertThat ( 1 0 . 5 6 . ki log ram (). to Human ()). isEqualTo (" 1 0 . 6 Ġk g ") ĊĠĠĠ ĠassertThat ( 1 0 0 5 0 . gram (). to Human ()). isEqualTo (" 1 0 . 1 Ġk g ") ĊĠĠĠ ĠassertThat ( 2 . 1 1 . ton (). to Human ()). isEqualTo (" 2 . 1 Ġton ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġparsing () Ġ{ ĊĠĠĠ ĠassertThat ( Mass . parse (" 1 4 2 . 0 Ġmg "). in Gram ()). isEqualTo ( 1 4 2 . mill ig ram (). in Gram (), ĠT OL ER ANCE ) ĊĠĠĠ ĠassertThat ( Mass . parse (" 0 . 1 Ġg "). in Gram ()). isEqualTo ( 0 . 1 . gram (). in Gram (), ĠT OL ER ANCE ) ĊĠĠĠ ĠassertThat ( Mass . parse (" 1 0 0 0 0 . 1 Ġg "). in Gram ()). isEqualTo ( 1 0 0 0 0 . 1 . gram (). in Gram (), ĠT OL ER ANCE ) ĊĠĠĠ ĠassertThat ( Mass . parse (" 7 8 . 4 Ġk g "). in Gram ()). isEqualTo ( 7 8 . 4 . ki log ram (). in Gram (), ĠT OL ER ANCE ) ĊĊĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠ ĠMass . parse (" 1 0 0 . bot tles ") ĊĠĠĠ Ġ}. isInstanceOf ( Number FormatException :: class . java ) ĊĊĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠ ĠMass . parse (" 1 0 0 Ġm ") ĊĠĠĠ Ġ}. isInstanceOf ( Number FormatException :: class . java ) ĊĊĠĠĠ ĠassertThat Thrown By Ġ{ ĊĠĠĠĠĠ ĠMass . parse (" 1 0 0 . 0 . 0 . 0 . gram ") ĊĠĠĠ Ġ}. isInstanceOf ( Number FormatException :: class . java ) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġnegative () Ġ{ ĊĠĠĠ Ġval Ġa Ġ= Ġ- 1 3 2 ĊĠĠĠ ĠassertThat ( a . gram (). in Gram ()). isEqualTo (- 1 3 2 . 0 , ĠT OL ER ANCE ) ĊĊĠĠĠ Ġval Ġb Ġ= Ġ- 2 ĊĠĠĠ ĠassertThat ( b . ki log ram (). to Human ()). isEqualTo ("- 2 . 0 Ġk g ") ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġsame _ hashCode () Ġ{ ĊĠĠĠ Ġval Ġi Ġ= Ġ 4 . ki log ram () ĊĠĠĠ Ġval Ġj Ġ= Ġ 4 . ki log ram () ĊĠĠĠ Ġval Ġk Ġ= Ġ 4 . 0 . ki log ram () ĊĊĠĠĠ ĠassertThat ( i . hashCode ()). isEqualTo ( j . hashCode ()) ĊĠĠĠ ĠassertThat ( j . hashCode ()). isEqualTo ( k . hashCode ()) ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġcompare () Ġ{ ĊĠĠĠ ĠassertThat ( 4 . 1 . ki log ram () Ġ> Ġ 3 . 9 . ki log ram ()). isTrue () ĊĠĠĠ ĠassertThat ((- 1 . 2 ). gram () Ġ< Ġ(- 0 . 2 ). gram ()). isTrue () ĊĠĠĠ ĠassertThat ((- 1 . 2 ). gram () Ġ> Ġ(- 2 . 5 ). gram ()). isTrue () ĊĠ Ġ} ĊĊĠ Ġ@ Test Ġfun Ġar ith met ics () Ġ{ ĊĠĠĠ ĠassertThat ( 1 . ki log ram () Ġ+ Ġ 2 . ki log ram ()). isEqualTo ( 3 0 0 0 . gram ()) ĊĠĠĠ ĠassertThat ( 1 . ki log ram () Ġ- Ġ 2 . ki log ram ()). isEqualTo ((- 1 ). ki log ram ()) ĊĠĠĠ ĠassertThat ( 4 . ki log ram () Ġ* Ġ 2 . 0 ). isEqualTo ( 8 . ki log ram ()) ĊĠĠĠ ĠassertThat ( 4 . ki log ram () Ġ/ Ġ 2 . 0 ). isEqualTo ( 2 . ki log ram ()) ĊĊĠĠĠ ĠassertThat ( 2 . 1 Ġ* Ġ 4 . ki log ram ()). isEqualTo ( 8 . 4 . ki log ram ()) ĊĠĠĠ ĠassertThat ( 5 Ġ* Ġ 4 . ki log ram ()). isEqualTo ( 2 0 . ki log ram ()) ĊĠ Ġ} Ċ }