0

I'm new to scala but I'm trying to add some tests to a simple file. The problem is that when I try to import the object into the test I get "error: not found: value"

PerfectNumberImperative.scala

package perfectImperative

package object perfectImperative{
    def main(args: Array[String]){
        perfectImperative(args(0).toInt)
    }

    def perfectImperative(input: Int): Boolean = {
        var evaluation = (for (possibleFactor <-1 to input if (input % possibleFactor == 0)) yield possibleFactor).sum == input*2
        return evaluation
    }
}   

PerfectNumberSpec.scala

import org.scalatest.FlatSpec
import perfectImperative._

class PerfectNumberSpec extends FlatSpec {
    it should "return true for 6" in {
        assert(perfectImperative.perfectImperative(6))
    }

}


[error] C:\Users\Daniel\PerfectNumbersScala\src\test\scala\PerfectNumberSpec.scala:2: not found: object perfectImperative
[error] import perfectImperative._
[error]        ^
[error] C:\Users\Daniel\PerfectNumbersScala\src\test\scala\PerfectNumberSpec.scala:6: not found: value perfectImperative
[error]                 assert(perfectImperative.perfectImperative(6))
[error]                        ^
[error] two errors found
[error] (test:compileIncremental) Compilation failed
[error] Total time: 2 s, completed Sep 16, 2015 2:30:38 AM

I would appreciate if someone could point me in the right direction.

Suavocado
  • 949
  • 12
  • 27
  • 1
    In an ideal scenario, there is nothing wrong with the code (although you have put the main method in the package object) structure and it should compile fine. Can you share your directory structure, as well as how you are compiling the code? – Bhashit Parikh Sep 16 '15 at 08:28
  • 1. Usually we name objects with camel starting with capital letter it might mess up with you package name. 2. In function perfectImperative var could be val and return is redundant. – Haito Sep 16 '15 at 08:37
  • I found my file structure was one folder off. Thanks for the help – Suavocado Sep 17 '15 at 06:09

0 Answers0