Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package spec.perfectnumber
- import perfectnumber._
- import org.specs._
- import org.junit.runner.RunWith
- import org.specs.runner.JUnitSuiteRunner
- class PerfectNumberSpec extends SpecificationWithJUnit {
- "Examples of when a number" should {
- val isPerfect: (Int => Boolean) = new PerfectNumberFinder().isPerfect(_)
- "be perfect" in {
- "when sum of divisors equal the number" in {
- "6" in {
- isPerfect(6) must be(true)
- }
- "28" in {
- isPerfect(28) must be(true)
- }
- "496" in {
- isPerfect(496) must be(true)
- }
- }
- }
- "not be perfect" in {
- "when divisiors of number don't add up to number" in {
- "5" in {
- isPerfect(10) must be(false)
- }
- }
- "when the number is zero" in {
- isPerfect(0) must be(false)
- }
- "when the number is negative" in {
- isPerfect(-28) must be(false)
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment