• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Specification类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: RefusedByRateLimiterErrorSpec

//设置package包名称以及导入依赖的类
package com.lookout.ratelimitingfilter

import com.twitter.finagle.http.{Request, Status}
import org.specs2.{Specification, ScalaCheck}
import io.circe.syntax._
import io.circe.jawn._
import com.lookout.ratelimitingfilter.models._

class RefusedByRateLimiterErrorSpec extends Specification with ScalaCheck with Arbitraries {
  def is = s2"""
    RefusedByRateLimiterError object
      it should not lose data on roundtrips to JSON $dataIntegrity
      it should contain a `message` field           $messageField
      it should create a response with 429 status   $statusCode
  """

  def fields(error: RefusedByRateLimiterError): Seq[String] =
    error.asJson.asObject.toList.flatMap(_.fields)

  def dataIntegrity = prop {
    (error: RefusedByRateLimiterError) => {
      (decode[RefusedByRateLimiterError](error.asJson.noSpaces)) must_== Right(error)
    }
  }

  def messageField = prop {
    (error: RefusedByRateLimiterError) => {
      fields(error) must contain("message")
    }
  }

  def statusCode = prop {
    (error: RefusedByRateLimiterError) => {
      error.toResponse.status must_== Status.TooManyRequests
    }
  }
} 
开发者ID:lookout,项目名称:rate-limiting-strategy,代码行数:38,代码来源:RefusedByRateLimiterErrorSpec.scala


示例2: TestLogisticRegression

//设置package包名称以及导入依赖的类
package com.zobot.ai.spark

import breeze.linalg.Matrix
import com.zobot.ai.spark.helpers.LogisticRegressionHelpers
import org.apache.spark.ml.classification.LogisticRegression
import org.apache.spark.ml.linalg.Vectors
import org.specs2.Specification

class TestLogisticRegression extends Specification {
  def is = s2"""
                Logistic Regression
                  can train model $testTrainLogisticRegressionModel
      """

  val context = new Context().spark

  def testTrainLogisticRegressionModel = {
    val model = LogisticRegressionHelpers.trainModel(new LogisticRegression, context.createDataFrame(Seq(
      (1.0, Vectors.dense(0.0, 1.1, 0.1)),
      (0.0, Vectors.dense(2.0, 1.0, -1.0)),
      (0.0, Vectors.dense(2.0, 1.3, 1.0)),
      (1.0, Vectors.dense(0.0, 1.2, -0.5))
    )).toDF("label", "features"))

    model.coefficientMatrix.toString().must_==("-19.086478256375067  16.278339464295065  -2.494930802874724  ")
  }
} 
开发者ID:BecauseNoReason,项目名称:zobot,代码行数:28,代码来源:TestLogisticRegression.scala


示例3: InferenceSpec

//设置package包名称以及导入依赖的类
package org.atnos.eff

import all._
import syntax.all._
import cats.data._
import org.specs2.Specification

class InferenceSpec extends Specification { def is = s2"""

 All the examples should compile ok

"""
  def e1 = {
    import Example1._

    putAndTell[S](4).runState(0).runWriter.runReader("").run
    putAndTell[S](4).runReader("").runState(0).runWriter.run

    // in this case a type annotation is required on runWriter
    putAndTell[S](4).runReader("").runWriter[String].runState(0).run

    ok
  }
}

object Example1  {
  type RNG[R] = Member[State[Int, ?], R]
  type Log[R] = Member[Writer[String, ?], R]
  type Env[R] = Member[Reader[String, ?], R]

  type S = Fx.fx3[State[Int, ?], Writer[String, ?], Reader[String, ?]]

  def putAndTell[R : RNG : Log: Env](i: Int) =
    for {
      _ <- put(i)
      _ <- tell("stored " + i)
    } yield i

} 
开发者ID:atnos-org,项目名称:eff,代码行数:40,代码来源:InferenceSpec.scala


示例4: EvalEffectSpec

//设置package包名称以及导入依赖的类
package org.atnos.eff

import org.specs2.Specification
import org.atnos.eff.all._
import org.atnos.eff.syntax.all._

import cats.syntax.all._
import cats.instances.all._
import cats.instances.all._
import cats.Eval

class EvalEffectSpec extends Specification { def is = s2"""

 run is stack safe with Eval               $stacksafeRun
 attempt is stack safe with Eval           $stacksafeAttempt
 recursion in Eval.defer is stack safe     $stacksafeRecursion

"""

  type E = Fx.fx1[Eval]

  val list = (1 to 5000).toList

  def stacksafeRun = {
    val action = list.traverseU(i => EvalEffect.delay(i))
    action.runEval.run ==== list
  }

  def stacksafeAttempt = {
    val action = list.traverseU(i => EvalEffect.delay(i))
    action.attemptEval.run ==== Right(list)
  }

  def stacksafeRecursion = {
    def loop(i: Int): Eval[Eff[Fx.fx1[Eval], Int]] =
      if (i == 0) {
        Eval.now(Eff.pure(1))
      } else {
        Eval.now(eval.defer(loop(i - 1)).map(_  + 1))
      }

    loop(100000).value.runEval.run ==== 100001
  }
} 
开发者ID:atnos-org,项目名称:eff,代码行数:45,代码来源:EvalEffectSpec.scala


示例5: SortSpec

//设置package包名称以及导入依赖的类
import com.stremlenye.sort.Sort
import org.specs2.Specification

class SortSpec extends Specification {
  def is =
    s2"""

Quick sort

  sort sorted list ${Quick.sortSorted}
  sort reversed list ${Quick.sortReversed}
  sort randomed list ${Quick.sortRandomed}
  sort empty list ${Quick.sortEmpty}
  sort single-item list ${Quick.sortSingle}
  sort equal items list ${Quick.sortEqTuple}
      """

  val sorted = List(6,5,4,3,2,1)
  val reversed = sorted.reverse
  val randomed = List(3,4,5,2,1,6)
  val empty = List.empty[Int]
  val single = List(1)
  val eqTuple = List(1,1)
  val huge = (1 to 10000).toList
  val hugeSorted = huge.reverse

  object Quick {
    def sortSorted = Sort.quick(sorted) mustEqual sorted

    def sortReversed = Sort.quick(reversed) mustEqual sorted

    def sortRandomed = Sort.quick(randomed) mustEqual sorted

    def sortEmpty = Sort.quick(empty) mustEqual empty

    def sortSingle = Sort.quick(single) mustEqual single

    def sortEqTuple = Sort.quick(eqTuple) mustEqual eqTuple

    def sortHuge = Sort.quick(huge) mustEqual hugeSorted
  }
} 
开发者ID:stremlenye,项目名称:alogrithms,代码行数:43,代码来源:SortSpec.scala


示例6: HelloWorldSpec

//设置package包名称以及导入依赖的类
package com.tomogle.specs2.acceptance

import org.specs2.Specification

class HelloWorldSpec extends Specification { def is =
  s2"""
      Specification to check the 'Hello, world' String

      The 'Hello, world' String should
        contain 12 characters             $e1
        start with 'Hello'                $e2
        end with 'world'                  $e3
    """

  val underTest = "Hello, world"

  def e1 = underTest must have size 12
  def e2 = underTest must startWith("Hello")
  def e3 = underTest must endWith("world")

} 
开发者ID:tom-ogle,项目名称:scala-scratch-code,代码行数:22,代码来源:HelloWorldSpec.scala


示例7: EitherSpec

//设置package包名称以及导入依赖的类
package fpinscala.errorhandling

import org.specs2.Specification

class EitherSpec extends Specification { def is = s2"""
  Either[E, A] related exercises for Chapter 4:
    map function should square 2 for Right(2) and nothing for Left(NumberFormatException)  $exer1
    flatMap function should square the string "2" for Right("2") and Left(NumberFormatException) for Right("x")  $exer2

  """

  def exer1 = {
    val either1 = Right(2)
    val either2: Either[Exception, Int] = Left(new NumberFormatException)
    either1.map(n => n * n) must_== Right(4)
    either2.map(n => n * n) must_== Left(new NumberFormatException)
  }

  def exer2 = {
    val either1 = Right("2")
    val either2 = Right("x")

    def squareString(s: String): Either[Exception, Int] = {
      try {
        val v = s.toInt
        Right(v * v)
      } catch {
        case e: Exception => Left(e)
      }
    }

    either1.flatMap(s => squareString(s)) must_== Right(4)
    either2.flatMap(s => squareString(s)) must_== Left(new NumberFormatException)
  }
} 
开发者ID:higuaro,项目名称:scala-training,代码行数:36,代码来源:EitherSpec.scala


示例8: MiscSpec

//设置package包名称以及导入依赖的类
package fpinscala.errorhandling

import org.specs2.Specification

class MiscSpec extends Specification { def is = s2"""
  Answer to miscellanious exercises for Chapter 4:
    Write a function to calculate the variance of a sequence using flatMap.
    Using Seq(1, 3, 4, 1, 23), it should be 70.24000000000002   $exer1
    Write a map2 function, which takes a function f(A, B) => C as parameter  $exer2
  """

  def exer1 =
    Misc.variance(List(1, 3, 4, 1, 23)) must_== Some(70.24000000000002)

  def exer2 = {
    def calcSalary(name: String, job: String) = job match {
      case "boss" => 10000.0f
      case _ => name.size.toFloat * 100.0f
    }
    val optA = Some("Bob")
    val optB = Some("boss")

    Option.map2(optA, optB)(calcSalary) must_== Some(10000.0f)
    Option.map2(optA, None())(calcSalary) must_== None()
    Option.map2(None(), optB)(calcSalary) must_== None()
    Option.map2(None(), None())(calcSalary) must_== None()
  }
} 
开发者ID:higuaro,项目名称:scala-training,代码行数:29,代码来源:MiscSpec.scala


示例9: OptionSpec

//设置package包名称以及导入依赖的类
package fpinscala.errorhandling

import org.specs2.Specification

class OptionSpec extends Specification { def is = s2"""
  Option[T] related exercises for Chapter 4:
    Use map function to increment the value of an Option[Int]         $exer1
    sequence must return None if there is a None in the list          $exerSeq
    sequence must return Some(List(1, 2)) for List(Some(1), Some(2))  $exerSeq2
    sequence must return Some(List()) for List()                      $exerSeq3
    Traverse must square all number in List(1, 2, 3, 4)               $exerTraverse
    Traverse must return None for List(1, 2, oo, 4)                   $exerTraverseWithNone
    Traverse must return Some(List()) for List()                      $exerTraverseWithNone2
  """

  def exer1 =
    Some(4).map(_ + 1) must_== Some(5)

  def exerSeq = {
    val options = List(Some(1), None(), Some(2), Some(3))
    Option.sequence(options) must_== None()
    Option.sequence_1(options) must_== None()
    Option.sequence_2(options) must_== None()
    Option.sequence_t(options) must_== None()
  }

  def exerSeq2 = {
    val options = List(Some(1), Some(2))
    val result = Some(List(1, 2))
    Option.sequence(options) must_== result
    Option.sequence_1(options) must_== result
    Option.sequence_2(options) must_== result
    Option.sequence_t(options) must_== result
  }

  def exerSeq3 = {
    val options: List[Option[Int]] = List()
    val result: Option[List[Int]] = Some(List())
    Option.sequence(options) must_== result
    Option.sequence_1(options) must_== result
    Option.sequence_2(options) must_== result
    Option.sequence_t(options) must_== result
  }

  def exerTraverse =
    Option.traverse(List(1, 2, 3, 4))(n => Some(n * n)) must_== Some(List(1, 4, 9, 16))

  def exerTraverseWithNone =
    Option.traverse(List(1, 2, Integer.MAX_VALUE, 4))(n => if (n != Integer.MAX_VALUE) Some(n * n) else None()) must_== None()

  def exerTraverseWithNone2 =
    Option.traverse(List() : List[Int])(n => Some(n + 1)) must_== Some(List())
} 
开发者ID:higuaro,项目名称:scala-training,代码行数:54,代码来源:OptionSpec.scala


示例10: TreeSpec

//设置package包名称以及导入依赖的类
package fpinscala.datastructures

import org.specs2.Specification

class TreeSpec extends Specification { def is = s2"""
  Given the following tree:
             *
          /     \
        *         *
       / \       / \
      1   5     *   4
               / \
              3   6
    Its size is 5                        $exer1
    Its maximum node value is 6          $exer2
    Its depth is 4                       $exer3
    It should duplicate the node values  $exer4
  """

  private val tree = Branch(Branch(Leaf(1), Leaf(5)), Branch(Branch(Leaf(3), Leaf(6)), Leaf(4)))

  def exer1 =
    Tree.size(tree) must_== 5

  def exer2 =
    Tree.maximum(tree) must_== 6

  def exer3 =
    Tree.depth(tree) must_== 3

  def exer4 =
    Tree.map(tree){ _ * 2 } must_== Branch(Branch(Leaf(2), Leaf(10)), Branch(Branch(Leaf(6), Leaf(12)), Leaf(8)))

} 
开发者ID:higuaro,项目名称:scala-training,代码行数:35,代码来源:TreeSpec.scala


示例11: Week1Spec

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

import org.specs2.Specification

class Week1Spec extends Specification { def is = s2"""
  Specification for week1 exercises from the Scala Coursera course:
    The pascal triangle for (0, 0) should be 1   ${exer1(0, 0, 1)}
    The pascal triangle for (1, 0) should be 1   ${exer1(1, 0, 1)}
    The pascal triangle for (1, 1) should be 1   ${exer1(1, 1, 1)}
    The pascal triangle for (2, 0) should be 1   ${exer1(2, 0, 1)}
    The pascal triangle for (2, 1) should be 2   ${exer1(2, 1, 2)}
    The pascal triangle for (2, 2) should be 1   ${exer1(2, 2, 1)}
    The pascal triangle for (3, 0) should be 1   ${exer1(3, 0, 1)}
    The pascal triangle for (3, 1) should be 3   ${exer1(3, 1, 3)}
    The pascal triangle for (3, 2) should be 3   ${exer1(3, 2, 3)}
    The pascal triangle for (3, 3) should be 1   ${exer1(3, 3, 1)}
    The pascal triangle for (4, 0) should be 1   ${exer1(4, 0, 1)}
    The pascal triangle for (4, 1) should be 4   ${exer1(4, 1, 4)}
    The pascal triangle for (4, 2) should be 6   ${exer1(4, 2, 6)}
    The pascal triangle for (4, 3) should be 4   ${exer1(4, 3, 4)}
    The pascal triangle for (4, 4) should be 1   ${exer1(4, 4, 1)}

  Specifications for exercise 2, checking if the parenthesis of a string are balanced:
    "(if (zero? x) max (/ 1 x))"  is balanced                                      ${exer2("(if (zero? x) max (/ 1 x))", balanced = true)}
    "I told him (that it’s not (yet) done). (But he wasn’t listening)" is balanced ${exer2("I told him (that it’s not (yet) done). (But he wasn’t listening)", balanced = true)}
    ":((---)" is not balanced                                                      ${exer2(":((---)", balanced = false)}
    "())(" is not balanced                                                         ${exer2("())(", balanced = false)}

  Specifications for exercise 3, count change problem:
    There are 4 ways to represent 6 with coins 1 and 2   ${exer3(4)}
  """

  def exer1(row: Int, col: Int, value: Int) =
    Week1.pascal(row, col) must_== value

  def exer2(string: String, balanced: Boolean) =
    Week1.balance(string.toList) must_== balanced

  def exer3(expected: Int) =
    Week1.countChange(6, List(1, 2)) must_== expected
} 
开发者ID:higuaro,项目名称:scala-training,代码行数:42,代码来源:Week1Spec.scala


示例12: NinjaNameGeneratorTest

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

import org.specs2.Specification

class NinjaNameGeneratorTest extends Specification { def is = s2"""
 This is a specification to check the 'NinjaNameGenerator'
 NinjaNameGenerator.generate should
   return "" if name is ""                                                    $e1
   return "Tokimimo" if name is "nico"                                        $e2
   return "" if name is a number                                              $e3
   return "Tokimimotakaari Mikarukatatamo" if name is "Nicolas Cavallo"       $e4
                                                        """

  def e1 = NinjaNameGenerator.generate("") must beEqualTo("")
  def e2 = NinjaNameGenerator.generate("nico") must beEqualTo("Tokimimo")
  def e3 = NinjaNameGenerator.generate("1234") must beEqualTo("")
  def e4 = NinjaNameGenerator.generate("Nicolas Cavallo") must beEqualTo("Tokimimotakaari Mikarukatatamo")

} 
开发者ID:nicocavallo,项目名称:ninja-name-generator-api,代码行数:20,代码来源:NinjaNameGeneratorTest.scala


示例13: RegularizationTest

//设置package包名称以及导入依赖的类
package neuroflow.nets

import breeze.linalg.DenseVector
import neuroflow.core.Activator.Linear
import neuroflow.core.EarlyStoppingLogic.CanAverage
import neuroflow.core._
import neuroflow.core.FFN.WeightProvider.oneWeights
import neuroflow.core.Network.Vector
import neuroflow.nets.DefaultNetwork._
import org.specs2.Specification
import org.specs2.specification.core.SpecStructure
import shapeless._
import breeze.numerics._
import breeze.stats._

import scala.collection.Seq


class RegularizationTest extends Specification {

  def is: SpecStructure =
    s2"""

    This spec will test the regularization techniques.

    It should:
      - Check the early stopping logic                           $earlyStopping

  """

  def earlyStopping = {

    import neuroflow.common.VectorTranslation._

    val (xs, ys) = (Vector(Vector(1.0), Vector(2.0), Vector(3.0)), Vector(Vector(3.2), Vector(5.8), Vector(9.2)))

    val net = Network(Input(1) :: Hidden(3, Linear) :: Output(1, Linear) :: HNil,
      Settings(regularization = Some(EarlyStopping(xs, ys, 0.8))))

    implicit object KBL extends CanAverage[DefaultNetwork] {
      def averagedError(xs: Seq[Vector], ys: Seq[Vector]): Double = {
        val errors = xs.map(net.evaluate).zip(ys).toVector.map {
          case (a, b) => mean(abs(a.dv - b.dv))
        }.dv
        mean(errors)
      }
    }

    net.evaluate(Vector(1.0)) must be equalTo Vector(3.0)
    net.evaluate(Vector(2.0)) must be equalTo Vector(6.0)
    net.evaluate(Vector(3.0)) must be equalTo Vector(9.0)

    net.shouldStopEarly must be equalTo false
    net.shouldStopEarly must be equalTo true

  }

} 
开发者ID:zenecture,项目名称:neuroflow,代码行数:59,代码来源:RegularizationTest.scala


示例14: DefaultNetworkNumTest

//设置package包名称以及导入依赖的类
import neuroflow.core.Activator._
import neuroflow.core._
import org.specs2.Specification
import org.specs2.specification.core.SpecStructure
import shapeless._



class DefaultNetworkNumTest extends Specification {

  def is: SpecStructure =
    s2"""

    This spec will test the gradients from DefaultNetwork by comparison of the derived values with
    the approximated ones.

      - Check the gradients                                $gradCheck

  """

  def gradCheck = {
    import neuroflow.core.FFN.WeightProvider.oneWeights
    import neuroflow.nets.DefaultNetwork._

    val layout =
        Input(2)           ::
        Hidden(3, Sigmoid) ::
        Hidden(4, Sigmoid) ::
        Hidden(5, Sigmoid) ::
        Hidden(6, Sigmoid) ::
        Hidden(5, Sigmoid) ::
        Hidden(4, Sigmoid) ::
        Hidden(3, Sigmoid) ::
        Output(2, Sigmoid) :: HNil

    val netA = Network(layout, Settings(learningRate = { case _ => 1.0 }, iterations = 1, approximation = Some(Approximation(1E-5))))
    val netB = Network(layout, Settings(learningRate = { case _ => 1.0 }, iterations = 1))

    val xs = Seq(Vector(0.5, 0.5), Vector(1.0, 1.0))

    netA.train(xs, xs)
    netB.train(xs, xs)

    println(netA)
    println(netB)

    val tolerance = 1E-3

    val equal = netA.weights.zip(netB.weights).map {
      case (a, b) =>
        (a - b).forall { (w, v) =>
          println(s"dw($w) - approx(dw($w)): " + v.abs)
          v.abs < tolerance
        }
    }.reduce { (l, r) => l && r }

    if (equal) success else failure
  }

} 
开发者ID:zenecture,项目名称:neuroflow,代码行数:61,代码来源:DefaultNetworkNumTest.scala


示例15: IoTest

//设置package包名称以及导入依赖的类
import neuroflow.application.plugin.IO.{File, Json}
import neuroflow.core.Activator.Sigmoid
import neuroflow.core._
import neuroflow.nets.DefaultNetwork.constructor
import org.specs2.Specification
import org.specs2.specification.core.SpecStructure
import shapeless._


class IoTest extends Specification {

  sequential // IO race conditions will occur otherwise

  def is: SpecStructure = s2"""

    This spec will test IO related functionality.

    It should:
      - Serialize a net                       $serialize
      - Deserialize a net                     $deserialize

  """

  val layers = Input(2) :: Hidden(3, Sigmoid) :: Output(2, Sigmoid) :: HNil
  val measure = {
    import neuroflow.core.FFN.WeightProvider.zeroWeights
    Network(layers)
  }
  val asJson = "[{\"rows\":2,\"cols\":3,\"data\":[0.0,0.0,0.0,0.0,0.0,0.0]},{\"rows\":3,\"cols\":2,\"data\":[0.0,0.0,0.0,0.0,0.0,0.0]}]"

  def serialize = {
    val serialized = Json.write(measure)
    serialized === asJson
  }

  def deserialize = {
    implicit val wp = Json.read(asJson)
    val deserialized = Network(layers)
    deserialized.weights.toArray.map(_.toArray) === measure.weights.toArray.map(_.toArray)
  }

} 
开发者ID:zenecture,项目名称:neuroflow,代码行数:43,代码来源:IoTest.scala


示例16: ArgParserSpec

//设置package包名称以及导入依赖的类
package net.white_azalea.models.parsers.arguments

import net.white_azalea.datas.arguments.Config
import org.specs2.Specification
import org.specs2.matcher.MatchResult


class ArgParserSpec extends Specification {
  def is =
    s2"""
This specification check argument parser.

The 'parse' method should
  parse 2 arguments as File[file] and File[dir]:     $simple
  javadoc file arg must be exists:                   $arg1exists
  javadoc file arg must be file:                     $arg1dir
  javadoc file arg must be xml extension:            $arg1txt
  junitDir arg must not be empty:                    $arg2empty
  junitDir arg must be exists:                       $arg2exists
  junitDir arg must be directory:                    $arg2file
  default template option is null:                   $defaultTemplate
                                                 """

  def parse(args: Seq[String]) =
    new ArgParser().parse(args, Config(null, null, null))

  val testJavadocXmlFile = "src/test/resources/javadoc/javadoc.xml"
  val testUtResultDir = "src/test/resources/ut"
  val dummyTextFile = "src/test/resources/javadoc/not_xml.txt"

  def simple: MatchResult[Any] =
    parse(Seq(testJavadocXmlFile, testUtResultDir))
      .map(v => v.javaDocXml.exists() && v.junitResultDir.exists()) must_== Some(true)

  def arg1exists = parse(Seq("nothing/file/path.xml", testUtResultDir)) must_== None

  def arg1dir = parse(Seq(testUtResultDir, testUtResultDir)) must_== None

  def arg1txt = parse(Seq(dummyTextFile, testUtResultDir)) must_== None

  def arg2empty = parse(Seq(dummyTextFile)) must_== None

  def arg2exists = parse(Seq(testJavadocXmlFile, "nothing/dir")) must_== None

  def arg2file = parse(Seq(testJavadocXmlFile, dummyTextFile)) must_== None

  def defaultTemplate = parse(Seq("-t", "src/main/resources/template.mustache", testJavadocXmlFile, testUtResultDir))
    .map(_.template != null) must_== Some(true)
} 
开发者ID:Sunao-Yoshii,项目名称:JUnitDocMarge,代码行数:50,代码来源:ArgParserSpec.scala


示例17: beforeAll

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

import org.specs2.Specification
import org.specs2.specification.BeforeAll

trait SpecCommon
extends BeforeAll
with Logging
with ValidatedMatchers
{
  def beforeAll() = {}

  override def loggerName = List("spec", this.className.stripSuffix("Spec").toLowerCase)
}

trait Spec
extends Specification
with SpecCommon 
开发者ID:tek,项目名称:pulsar,代码行数:20,代码来源:spec.scala


示例18: GraphicsMagickServiceSpecification

//设置package包名称以及导入依赖的类
package io.alphard.graphicsmagick

import org.specs2.Specification
import org.specs2.specification.Step

object GraphicsMagickServiceSpecification
  extends Specification
  with GraphicsMagickServiceModule {

  final lazy val is = {
    "This is a specification to check the GraphicsMagickService" ^
      p ^
      "The GraphicsMagick service should" ^
      Step() ^
      "initialize correctly" ! initializeCorrectly ^
      Step() ^
      end
  }

  protected def initializeCorrectly = {
    graphicsMagickService must not(throwA[Throwable])
  }

  protected final def graphicsMagickMaxActiveProcesses = Runtime.getRuntime.availableProcessors()
} 
开发者ID:hydra-technologies,项目名称:alphard-jvm-graphicsmagick,代码行数:26,代码来源:GraphicsMagickServiceSpecification.scala


示例19: CodecTest

//设置package包名称以及导入依赖的类
package at.hazm.quebic

import org.specs2.Specification
import org.specs2.execute.Result
import org.specs2.specification.core.SpecStructure

import scala.util.Random

class CodecTest extends Specification {
  override def is:SpecStructure =
    s2"""
none codec: ${randomDecode(53, 1024, Codec.PLAIN)}
gzip codec: ${randomDecode(53, 1024, Codec.GZIP)}
"""

  def randomDecode(seed:Long, length:Int, codec:Codec):Result = {
    val random = new Random(seed)
    val binary1 = new Array[Byte](length)
    random.nextBytes(binary1)
    val encoded = codec.encode(binary1)
    val binary2 = codec.decode(encoded)
    System.out.println(f"${codec.name.toUpperCase}: ${binary1.length}%,dB -> ${encoded.length}%,dB")
    binary1 === binary2
  }

} 
开发者ID:torao,项目名称:quebic,代码行数:27,代码来源:CodecTest.scala


示例20: ApplicativeSpec

//设置package包名称以及导入依赖的类
package uscala.cats.result

import cats.std.all._
import cats.syntax.cartesian._
import org.specs2.{ScalaCheck, Specification}
import uscala.cats.syntax.result._
import applicative._
import org.scalacheck.{Gen, Prop}
import uscala.result.Result
import uscala.result.specs2.ResultMatchers

class ApplicativeSpec extends Specification with ResultMatchers with ScalaCheck  {
  import ApplicativeSpec._

  override def is =
    s2"""
        Can collect multiple failures on the left of a result $test
      """

  def test = Prop.forAllNoShrink(list)(errs =>
    errs.foldLeft(ResultNel.ok[String, String](new String))((acc, v) =>
      (acc |@| Result.fail[String, String](v).toResultNel).map(_ + _)
    ) must beFail.like { case a => a.unwrap must containTheSameElementsAs(errs) }
  )
}

object ApplicativeSpec {
  val stringGen = Gen.alphaStr.suchThat(_.nonEmpty)
  val list = Gen.listOf(stringGen).suchThat(_.nonEmpty)
} 
开发者ID:janstenpickle,项目名称:uscala-cats,代码行数:31,代码来源:ApplicativeSpec.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala ServerConnector类代码示例发布时间:2022-05-23
下一篇:
Scala BigDecimal类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap