本文整理汇总了Scala中org.scalactic.Equality类的典型用法代码示例。如果您正苦于以下问题:Scala Equality类的具体用法?Scala Equality怎么用?Scala Equality使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Equality类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: streamlinedXmlEquality
//设置package包名称以及导入依赖的类
package fr.ramiro.scala.dom
import scala.xml.NodeSeq
import org.scalactic.{ Equality, Uniformity }
trait StreamlinedXmlEquality {
implicit def streamlinedXmlEquality[T <: NodeSeq]: Equality[T] = {
new Equality[T] {
val xu: Uniformity[T] = StreamlinedXml.streamlined[T]
def areEqual(a: T, b: Any): Boolean = {
xu.normalized(a) == xu.normalizedOrSame(b)
}
}
}
}
object StreamlinedXmlEquality extends StreamlinedXmlEquality
开发者ID:rrramiro,项目名称:scala-dom,代码行数:18,代码来源:StreamlinedXmlEquality.scala
示例2: serialize
//设置package包名称以及导入依赖的类
package com.commodityvectors.snapshotmatchers.playJson
import com.commodityvectors.snapshotmatchers.{SnapshotLoader, SnapshotMessages, SnapshotSerializer}
import org.scalactic.Equality
import org.scalatest.matchers.{MatchResult, Matcher}
import play.api.libs.json.{JsValue, Json, Reads}
trait PlayJsonSnapshotMatcher extends SnapshotLoader with SnapshotMessages {
implicit lazy val playJsonSerializer = new SnapshotSerializer[JsValue] {
override def serialize(in: JsValue): String = Json.prettyPrint(in)
}
class JsonDeserializerShouldMatch[T](in: T)(implicit reads: Reads[T], equals: Equality[T]) extends Matcher[String] {
override def apply(explicitId: String): MatchResult = {
loadSnapshot(explicitId) match {
case Some(content) =>
val parsed = Json.parse(content).as[T]
val isEquals = equals.areEqual(parsed, in)
MatchResult(isEquals, errorMessage(in.toString, parsed.toString), ContentsAreEqual)
case None => MatchResult(matches = false, s"Could not find snapshot for id: $explicitId", ContentsAreEqual)
}
}
}
def deserializeAs[T](in: T)(implicit reads: Reads[T], equals: Equality[T]) = new JsonDeserializerShouldMatch[T](in)
}
开发者ID:commodityvectors,项目名称:scalatest-snapshot-matchers,代码行数:27,代码来源:PlayJsonSnapshotMatcher.scala
示例3: TestPerfectScores
//设置package包名称以及导入依赖的类
package com.github.jongwook
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession
import org.scalactic.{Equality, TolerantNumerics}
import org.scalatest.{FlatSpec, Matchers}
class TestPerfectScores extends FlatSpec with Matchers {
import TestFixture._
implicit val doubleEquality: Equality[Double] = TolerantNumerics.tolerantDoubleEquality(eps)
val perfectScores: Seq[(String, Map[Metric, Seq[Double]])] = {
val spark = SparkSession.builder().master(new SparkConf().get("spark.master", "local[8]")).getOrCreate()
import spark.implicits._
val predictionDF = spark.createDataset(prediction)
val groundTruthDF = spark.createDataset(groundTruth)
for ((name, df) <- Seq("prediction" -> predictionDF, "ground truth" -> groundTruthDF)) yield {
val metrics = new SparkRankingMetrics(df, df, itemCol = "product", predictionCol = "rating")
name -> Map[Metric, Seq[Double]](
NDCG -> metrics.ndcgAt(ats),
MAP -> metrics.mapAt(ats),
Precision -> metrics.precisionAt(Seq(Integer.MAX_VALUE)),
Recall -> metrics.recallAt(Seq(Integer.MAX_VALUE))
)
}
}
for ((name, scores) <- perfectScores) {
for (metric <- Seq(NDCG, MAP, Precision, Recall)) {
s"In $name dataset, our $metric implementation" should s"return 1.0 for the perfect prediction" in {
for (score <- scores(metric)) {
score should equal(1.0)
}
}
}
}
}
开发者ID:jongwook,项目名称:spark-ranking-metrics,代码行数:43,代码来源:TestPerfectScores.scala
示例4: XmlImplicits
//设置package包名称以及导入依赖的类
package anchorman.docx
import java.io.StringWriter
import org.scalactic.Equality
import scala.xml._
object XmlImplicits {
implicit val nodeSeqEquality = new Equality[NodeSeq] {
val regex = "[ \\t\\r\\n]+".r
def areEqual(a: NodeSeq, b: Any): Boolean = {
b match {
case b: NodeSeq =>
val aWriter = new StringWriter
val bWriter = new StringWriter
XML.write(aWriter, Group(a), "utf-8", false, null, MinimizeMode.Default)
XML.write(bWriter, Group(b), "utf-8", false, null, MinimizeMode.Default)
val aString = aWriter.toString.replaceAll("\\s", "")
val bString = bWriter.toString.replaceAll("\\s", "")
// println(aString)
// println(bString)
aString == bString
case _ => false
}
}
}
}
开发者ID:davegurnell,项目名称:anchorman,代码行数:29,代码来源:XmlImplicits.scala
示例5: TableEquality
//设置package包名称以及导入依赖的类
package org.fs.utility.collection.table
import org.scalactic.Equality
class TableEquality[A <: GenTable[_, _, _]] extends Equality[A] {
def areEqual(a: A, b: Any): Boolean = b match {
case b: GenTable[_, _, _] => (
a == b
&& b == a
&& a.hashCode == b.hashCode
&& a.elementsWithIndices == b.elementsWithIndices
&& a.elements == b.elements
)
case _ =>
false
}
}
object TableEquality {
implicit def equality[A <: GenTable[_, _, _]] = new TableEquality[A]
}
开发者ID:frozenspider,项目名称:fs-common-utils,代码行数:22,代码来源:TableEquality.scala
示例6: areEqual
//设置package包名称以及导入依赖的类
package argus.macros
import org.scalactic.Equality
import org.scalatest.matchers.{ MatchResult, Matcher }
import scala.tools.reflect.ToolBox
trait ASTMatchers {
val runtimeUniverse = scala.reflect.runtime.universe
import runtimeUniverse._
import scala.reflect.runtime.currentMirror
val toolbox = currentMirror.mkToolBox()
// For testing equality between trees in tests
implicit val treeEq = new Equality[Tree] {
def areEqual(a: Tree, b: Any): Boolean =
b match {
// equalsStructure bug: https://github.com/scalamacros/paradise/issues/80
case c: Tree => showRaw(a) == showRaw(c) //.equalsStructure(c)
case _ => false
}
}
implicit val valDefEq = new Equality[ValDef] {
def areEqual(a: ValDef, b: Any): Boolean =
b match {
case c: ValDef => showRaw(a) == showRaw(c)
case _ => false
}
}
implicit val listTreeEq = new Equality[List[Tree]] {
def areEqual(a: List[Tree], b: Any): Boolean =
b match {
case c: List[_] => a.size == c.size && a.zip(c).forall { case(x,y) => treeEq.areEqual(x,y) }
case _ => false
}
}
val extractCodecNameAndType: PartialFunction[Tree, (String, String)] = {
case q"implicit val $name: $typ = $_" => (name.toString, typ.toString)
}
}
开发者ID:aishfenton,项目名称:Argus,代码行数:46,代码来源:ASTMatchers.scala
示例7: beSameJsonAs
//设置package包名称以及导入依赖的类
package argus.macros
import argus.json.JsonDiff
import org.scalactic.Equality
import cats.syntax.either._
import io.circe._
import org.scalatest.matchers.{ MatchResult, Matcher }
// TODO Should refactor this into somewhere generally useful.
trait JsonMatchers {
def beSameJsonAs(jrStr: String): Matcher[Json] = new Matcher[Json] {
def apply(jl: Json) = {
val jr = parser.parse(jrStr).toOption.get
beSameJsonAs(jr)(jl)
}
}
def beSameJsonAs(jr: Json): Matcher[Json] = new Matcher[Json] {
def apply(jl: Json) = {
val diff = JsonDiff.diff(jl, jr)
MatchResult(diff.isEmpty, "Differences found in json: " + diff.mkString(","), "No differences found!")
}
}
implicit val jsonEq = new Equality[Json] {
def areEqual(a: Json, b: Any): Boolean =
b match {
case c: Json => JsonDiff.diff(a, c) == Nil
case c: String => JsonDiff.diff(a, parser.parse(c).toOption.get) == Nil
case _ => false
}
}
}
开发者ID:aishfenton,项目名称:Argus,代码行数:36,代码来源:JsonMatchers.scala
示例8: beSameJsonAs
//设置package包名称以及导入依赖的类
package vegas
import argus.json.JsonDiff
import org.scalactic.Equality
import io.circe._
import org.scalatest.matchers.{ MatchResult, Matcher }
// TODO This is copy-and-pasted from argus. Really needs to be put somewhere shared.
trait JsonMatchers {
def beSameJsonAs(jrStr: String): Matcher[Json] = new Matcher[Json] {
def apply(jl: Json) = {
val jr = parser.parse(jrStr).right.get
beSameJsonAs(jr)(jl)
}
}
def beSameJsonAs(jr: Json): Matcher[Json] = new Matcher[Json] {
def apply(jl: Json) = {
val diff = JsonDiff.diff(jl, jr)
MatchResult(diff.isEmpty, "Differences found in json: " + diff.mkString(","), "No differences found!")
}
}
implicit val jsonEq = new Equality[Json] {
def areEqual(a: Json, b: Any): Boolean =
b match {
case c: Json => JsonDiff.diff(a, c) == Nil
case c: String => JsonDiff.diff(a, parser.parse(c).right.get) == Nil
case _ => false
}
}
}
开发者ID:vegas-viz,项目名称:Vegas,代码行数:35,代码来源:JsonMatchers.scala
示例9: MonoidDemo
//设置package包名称以及导入依赖的类
package howitworks.cats
import cats._
import org.scalactic.Equality
class MonoidDemo extends wp.Spec {
"clock monoid" in {
implicit val __ = clockSemigrop
Monoid[Clock].empty mustBe Clock.c12
Monoid[Clock].combine(Clock.c1, Clock.c2) mustEqual Clock.c3
Monoid[Clock].combine(Clock.c12, Clock.c2) mustEqual Clock.c2
import cats.syntax.semigroup._
Clock.c1 |+| Clock.c1 mustEqual Clock.c2 //at now (08.04.2016) it looks red in intellij, probably because it uses custom macros under to hood
}
trait Clock {
def hour: Int
override def toString = s"Clock($hour)"
}
object Clock {
val c1 = new Clock {override def hour: Int = 1}
val c2 = new Clock {override def hour: Int = 2}
val c3 = new Clock {override def hour: Int = 3}
//...
val c11 = new Clock {override def hour: Int = 11}
val c12 = new Clock {override def hour: Int = 12}
def apply(i: Int): Clock = new Clock{
override def hour: Int = i.abs%12
}
}
val clockSemigrop: Monoid[Clock] = new Monoid[Clock] {
override def empty: Clock = Clock.c12
override def combine(x: Clock, y: Clock): Clock = Clock(x.hour + y.hour)
}
implicit lazy val clockEquality: Equality[Clock] = new Equality[Clock] {
override def areEqual(a: Clock, b: Any): Boolean = b match {
case c:Clock => a.hour==c.hour
case _ => false
}
}
}
开发者ID:jawp,项目名称:wicked-playground,代码行数:50,代码来源:MonoidDemo.scala
示例10: Utils
//设置package包名称以及导入依赖的类
package fr.ramiro.sfuzzy
import org.scalactic.Equality
object Utils {
def tolerantFuzzyEvaluationTypeEquality(tolerance: FuzzyEvaluationType): Equality[FuzzyEvaluationType] = {
if (tolerance <= (0: BigDecimal))
throw new IllegalArgumentException(tolerance.toString + " passed to tolerantFuzzyEvaluationTypeEquality was zero or negative. Must be a positive non-zero number.")
new Equality[FuzzyEvaluationType] {
def areEqual(a: FuzzyEvaluationType, b: Any): Boolean = {
b match {
case bFuzzyEvaluationType: Number =>
(a <= tolerance + bFuzzyEvaluationType.doubleValue()) && (a >= (-tolerance) + bFuzzyEvaluationType.doubleValue())
case _ => false
}
}
override def toString: String = s"TolerantFuzzyEvaluationTypeEquality($tolerance)"
}
}
}
开发者ID:rrramiro,项目名称:sFuzzyLogic,代码行数:21,代码来源:Utils.scala
注:本文中的org.scalactic.Equality类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论