samedi 31 octobre 2015

Test private members of a object in scala

Here is the object:

package object beautifier {
  private val scientificPattern = """([+-]?\d+(\.\d+)?)([Ee]([+-]?\d+))?""".r
}

And the test:

import org.scalatest._ import vu.co.kaiyin.formatting.scientificNotaion.beautifier.scientificPattern

class ScientificNotationSpec extends FlatSpec with Matchers {
  "Regex" should "return correct matches" in {
    "-4.2e-3" match {
      case scientificPattern(coef, _, _, exponent) => {
        coef should be (-4.2)
        exponent should be (-3)
      }
    }
  }
}

And I got an error of course:

Error:(2, 8) object scientificPattern is not a member of package vu.co.kaiyin.formatting.scientificNotaion.beautifier
import vu.co.kaiyin.formatting.scientificNotaion.beautifier.scientificPattern
       ^

How do I solve this problem?

Aucun commentaire:

Enregistrer un commentaire