当前位置: 首页>>代码示例>>Scala>>正文


Scala TolerantNumerics类代码示例

本文整理汇总了Scala中org.scalactic.TolerantNumerics的典型用法代码示例。如果您正苦于以下问题:Scala TolerantNumerics类的具体用法?Scala TolerantNumerics怎么用?Scala TolerantNumerics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TolerantNumerics类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: BooleanExpressionTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars

import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.prop.Tables.Table
import org.scalactic.TolerantNumerics

class BooleanExpressionTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	val doubleEq = TolerantNumerics.tolerantDoubleEquality(1e-4f)

	property(s"Should work, damn it") {
		BooleanRealNumberGrammar.eval("5*sin(50+sqrt(10)) - min(5, 10, 15, 20) = -3", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("5*sin(50+sqrt(10)) - min(5, 10, 15, 20) ? -3.788", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("5*sin(50+sqrt(10)) - min(5, 10, 15, 20) ? -3.788", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("(15+20) < 50", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("(15-20) > -50", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("(15-20) > -50 and (50*2)=100", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("5 = 5 = 5", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("5 = 5 = 6", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("5 < 6 < 7", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("5 > 20 < 15", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("5 < 10 = 10", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("2=0 or 50=50 and ((50*2)=100)", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("(2=0 or 50=50) and ((50*2)=100)", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("0=1 or 2<5 and 5=5", 0.01) should equal (true) // tests precedence
		BooleanRealNumberGrammar.eval("sqrt(10) < mean(10, 50, 60) nand 50=50", 0.01) should equal (false)
		BooleanRealNumberGrammar.eval("sqrt(10) < mean(10, 50, 60) and 50=50", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("sqrt(10) >= mean(10, 50, 60) or 50=50", 0.01) should equal (true)
		BooleanRealNumberGrammar.eval("sqrt(10) >= mean(10, 50, 60) nor 50=50", 0.01) should equal (false)
	}

} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:34,代码来源:BooleanRealNumberGrammarTest.scala

示例2: RealNumberGrammarTest

//设置package包名称以及导入依赖的类
package kokellab.utils.grammars

import org.scalatest.{Matchers, PropSpec}
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.prop.Tables.Table
import org.scalactic.TolerantNumerics

class RealNumberGrammarTest extends PropSpec with TableDrivenPropertyChecks with Matchers {

	val doubleEq = TolerantNumerics.tolerantDoubleEquality(1e-4f)

	property(s"Should work, damn it") {
		RealNumberGrammar.eval("5*sin(50+sqrt(10)) - min(5, 10, 15, 20) + mean(10, 20)") should equal (11.211799096658236)
	}

	property("Exp notation") {
		RealNumberGrammar.eval("-5.0E10 + (2E10) + (1E-2) + (3E+5)") should equal (-2.999969999999E10)
	}

	property("NaN") {
		assert(RealNumberGrammar.eval("-NaN*5").isNaN)
	}
	property("Inf") {
		assert(RealNumberGrammar.eval("-?").isNegInfinity)
	}
} 
开发者ID:kokellab,项目名称:kl-common-scala,代码行数:27,代码来源:RealNumberGrammarTest.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: WeightModelSpec

//设置package包名称以及导入依赖的类
package ch.fhnw.ima.saav.model

import ch.fhnw.ima.saav._
import org.scalactic.TolerantNumerics
import org.scalatest.{FunSpec, Matchers}

class WeightModelSpec extends FunSpec with Matchers {

  it("should calculate weighted means") {
      val valuesWithWeights = Seq((13d, 0.1), (23d, 0.03), (54d, 0.04))
      val weightedMean = weight.weightedMean(valuesWithWeights)
      implicit val doubleEquality = TolerantNumerics.tolerantDoubleEquality(0.01)
      weightedMean match {
        case Some(mean) => assert(mean === 24.418)
        case wrongValue @ _ => fail(s"Unexpected mean value $wrongValue")
      }
  }

  it("should handle empty value collection") {
    weight.weightedMean(Seq.empty) shouldBe None
  }

} 
开发者ID:fhnw-saav,项目名称:saav,代码行数:24,代码来源:WeightModelSpec.scala

示例5: RoomAreaSpec

//设置package包名称以及导入依赖的类
package E07

import fi.kajstrom.efpscala.E07.RoomArea
import org.scalactic.TolerantNumerics
import org.scalatest.{FlatSpec, Matchers}


class RoomAreaSpec extends FlatSpec with Matchers{
  implicit val doubleEq = TolerantNumerics.tolerantDoubleEquality(0.001)
  val room = new RoomArea(15, 20)

  "areaFeet" should "return 300 when size is 15 x 20 feet" in {
    room.areaFeet() should be (300)
  }

  "areaMeters" should "return 27.871 when size is 15 x 20 feet" in {
    assert(room.areaMeters() === 27.871)
  }
} 
开发者ID:kajstrom,项目名称:EFP-Scala,代码行数:20,代码来源:RoomAreaSpec.scala

示例6: Vector3DSpec

//设置package包名称以及导入依赖的类
package name.ryanboder.maestroid

import org.scalactic.TolerantNumerics
import org.scalatest.FlatSpec

import scala.math._

class Vector3DSpec extends FlatSpec {
  implicit val doubleEquality = TolerantNumerics.tolerantDoubleEquality(0.01)

  behavior of "Vector3D"

  it should "calculate magnitude" in {
    val subject = Vector3D(1.0, 1.0, 1.0)
    assert(subject.magnitude === sqrt(3))
  }

  it should "calculate the dot product of 2 vectors" in {
    val a = Vector3D(1.0, 1.0, 1.0)
    val b = Vector3D(-1.0, -1.0, -1.0)
    val c = Vector3D(1.0, 1.0, 0.0)
    val d = Vector3D(1.0, -1.0, 0.0)
    assert((a dot a) === 3.0)
    assert((a dot b) === -3.0)
    assert((c dot d) === 0.0)
  }

  it should "calculate the angle between 2 vector" in {
    val a = Vector3D(1.0f, 1.0f, 1.0f)
    val c = Vector3D(1.0f, 1.0f, 0.0f)
    val d = Vector3D(1.0f, -1.0f, 0.0f)
    assert((a angle a) === 0.0)
    assert((c angle d) === Pi / 2.0)
  }

} 
开发者ID:ryan-boder,项目名称:maestroid,代码行数:37,代码来源:Vector3DSpec.scala


注:本文中的org.scalactic.TolerantNumerics类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。