All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.idml.utils.PValueComparison.scala Maven / Gradle / Ivy

There is a newer version: 63488a16f994d8c0416bab30ec9ef2b0304a03b5
Show newest version
package io.idml.utils

import io.idml.{IdmlArray, IdmlObject, IdmlValue}

/** A utility for doing a deep comparison of PValues and producing meaningful feedback should they not be the same */
object PValueComparison {

  /** Perform a deep comparison of two PValues */
  def assertEqual(left: IdmlValue, right: IdmlValue, path: List[String] = Nil): Unit = {
    (left, right) match {
      case (l: IdmlObject, r: IdmlObject) =>
        l.fields.keys.foreach { k =>
          assertEqual(l.get(k), r.get(k), k :: path)
        }
        require(l.fields.keys == r.fields.keys, s"${path.reverse.mkString(".")} actual: ${l.fields}, expected: ${r.fields}")
      case (l: IdmlArray, r: IdmlArray) =>
        l.items.zip(r.items).zipWithIndex.foreach {
          case ((ll: IdmlValue, rr: IdmlValue), i: Int) =>
            assertEqual(ll, rr, i.toString :: path)
        }
        require(l.items.length == r.items.length, s"${path.reverse.mkString(".")} actual: ${l.items}, expected: ${r.items}")
      case (l, r) =>
        require(l == r, s"${path.reverse.mkString(".")} actual: $l, expected: $r")
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy