Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1429 from jbgi/digits
Add digitsFrom{Int, Long, BigInt}: extract digits of a number,
- Loading branch information
Showing
2 changed files
with
41 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,30 @@ | ||
package scalaz | ||
|
||
import Scalaz._ | ||
import scalaz.scalacheck.ScalazProperties._ | ||
import scalaz.scalacheck.ScalazArbitrary._ | ||
import org.scalacheck.Prop.forAll | ||
|
||
object DigitTest extends SpecLite { | ||
checkAll(enum.laws[Digit]) | ||
checkAll(monoid.laws[Digit]) | ||
|
||
"correctly extract int digits" ! forAll { | ||
(i: Int) => { | ||
Digit.digitsFromInt(i).longDigits must_===(scala.math.abs(i.toLong)) | ||
} | ||
} | ||
|
||
"correctly extract long digits" ! forAll { | ||
(i: Long) => { | ||
Digit.digitsFromLong(i).map(_.toInt.toString).suml must_===(i.toString.stripPrefix("-")) | ||
} | ||
} | ||
|
||
"correctly extract bigint digits" ! forAll { | ||
(i: BigInt) => { | ||
Digit.digitsFromBigInt(i).map(_.toInt.toString).suml must_===(i.toString.stripPrefix("-")) | ||
} | ||
} | ||
|
||
} |