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

Scala ShouldMatchers类代码示例

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

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



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

示例1: HuffmanSuite

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

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, ShouldMatchers}
import patmat.Huffman._

@RunWith(classOf[JUnitRunner])
class HuffmanSuite extends FunSuite with ShouldMatchers {
	trait TestTrees {
		val t1 = Fork(Leaf('a',2), Leaf('b',3), List('a','b'), 5)
		val t2 = Fork(Fork(Leaf('a',2), Leaf('b',3), List('a','b'), 5), Leaf('d',4), List('a','b','d'), 9)
	}


  test("weight of a larger tree") {
    new TestTrees {
      weight(t1) should be(5)
    }
  }


  test("chars of a larger tree") {
    new TestTrees {
      chars(t2) should be(List('a', 'b', 'd'))
    }
  }


  test("string2chars(\"hello, world\")") {
    string2Chars("hello, world") should be(List('h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd'))
  }


  test("makeOrderedLeafList for some frequency table") {
    makeOrderedLeafList(List(('t', 2), ('e', 1), ('x', 3))) should be(List(Leaf('e', 1), Leaf('t', 2), Leaf('x', 3)))
  }


  test("combine of some leaf list") {
    val leaflist = List(Leaf('e', 1), Leaf('t', 2), Leaf('x', 4))
    combine(leaflist) should be(List(Fork(Leaf('e', 1), Leaf('t', 2), List('e', 't'), 3), Leaf('x', 4)))
  }


  test("decode and encode a very short text should be identity") {
    val fc = Huffman.frenchCode
    decode(fc, encode(fc)("letsmakeitmorecomplicated".toList)) should be("letsmakeitmorecomplicated".toList)
  }

} 
开发者ID:letalvoj,项目名称:progfun_assignments,代码行数:52,代码来源:HuffmanSuite.scala


示例2: CountChangeSuite

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

import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
import org.scalatest.{FunSuite, ShouldMatchers}

@RunWith(classOf[JUnitRunner])
class CountChangeSuite extends FunSuite with ShouldMatchers {

  import Week1.countChange

  test("countChange: example given in instructions") {
    countChange(4, List(1, 2)) should be(3)
  }

  test("countChange: sorted CHF") {
    countChange(300, List(5, 10, 20, 50, 100, 200, 500)) should be(1022)
  }

  test("countChange: no pennies") {
    countChange(301, List(5, 10, 20, 50, 100, 200, 500)) should be(0)
  }

  test("countChange: unsorted CHF") {
    countChange(300, List(500, 5, 50, 100, 20, 200, 10)) should be(1022)
  }
} 
开发者ID:letalvoj,项目名称:progfun_assignments,代码行数:28,代码来源:CountChangeSuite.scala


示例3: DomainStructureTest

//设置package包名称以及导入依赖的类
package org.dele.text.lapa.patterns

import DomainStructure._
import org.scalatest.ShouldMatchers
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class DomainStructureTest extends TestNGSuite with ShouldMatchers with TableDrivenPropertyChecks {

  import org.dele.text.lapa.TestHelper._
  @Test
  def t1 = {
    val ds = domainStructure.children
    ds.size shouldBe(3)
  }

  @Test
  def t2 = {
    val d = engDomainMgr.queryDomainId("cyber-attack", "entity-list-connector-words")
    d shouldBe(Option("_root_"))
  }

  @Test
  def t3 = {
    val ds = load(domainTree, List("cyber-attack"))
    ds.children.size shouldBe 2
    ds.children.exists(_.id == "cyber-attack") shouldBe false

    val ds2 = load(domainTree, List("military-maneuver", "-online-attack"))
    ds2.children.size shouldBe 2
    ds2.children.exists(_.id == "-online-attack") shouldBe false
  }

} 
开发者ID:new2scala,项目名称:text-util,代码行数:37,代码来源:DomainStructureTest.scala


示例4: StoppedByMatcherManagerTest

//设置package包名称以及导入依赖的类
package org.dele.text.maen.matchers

import org.scalatest.ShouldMatchers
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class StoppedByMatcherManagerTest extends TestNGSuite with ShouldMatchers with TableDrivenPropertyChecks {
  import StoppedByMatcherManager._

  val testData = Table(
    ("stoppedByMap", "reverseMap"),

    (Iterable("l1" -> List(StoppedByConfig("sl1", true), StoppedByConfig("sl2", true))), Map("sl1" -> (true -> List("l1")), "sl2" -> (true -> List("l1")))),
    (
      Iterable("l1" -> List(StoppedByConfig("sl1", true), StoppedByConfig("sl2", true)), ("l1" -> List(StoppedByConfig("sl3", false)))),
      Map("sl1" -> (true -> List("l1")), "sl2" -> (true -> List("l1")), "sl3" -> (false -> List("l1")))
    )
  )

  @Test
  def t1 = {
    forAll(testData) {
      (stoppedByMap, reverseMap) => {
        val m = new StoppedByMatcherManager(stoppedByMap)
        reverseMap.foreach(
          p => {
            val k = p._1
            val expected = p._2
            m.getListsStopBy(k).get shouldBe expected
          }
        )
      }
    }
  }

} 
开发者ID:new2scala,项目名称:text-util,代码行数:39,代码来源:StoppedByMatcherManagerTest.scala


示例5: CompositeMatcherTest

//设置package包名称以及导入依赖的类
package org.dele.text.maen.matchers

import TMatcher._
import org.scalatest.ShouldMatchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class CompositeMatcherTest extends TestNGSuite with ShouldMatchers {
  import org.dele.text.maen.AtomPropMatcherLib._
  import org.dele.text.maen.TestHelper._
  val idWord = "atom-matcher-f-word"
  val idPhrase = "atom-matcher-f-phrase"
  val idSentence = "atom-matcher-f-sentence"
  val idGroup = Option("atom-matchers")

  implicit val smlib = EmptySubMatchCheckerLib
  import SubMatchCheckerLib._
  @Test
  def t1 = {
    val matchers = Array(
      fromAtomMatcher(FExact("word"), EmptyCheckerIds, Option(idWord)),
      fromAtomMatcher(FExact("phrase"), EmptyCheckerIds, Option(idPhrase))
    )
    val compMatcher = matchersOrderedAllPositive(matchers, EmptyCheckerIds, idGroup)

    val testInput = inputFrom("word and Word phrase , Phrase")
    var result = compMatcher.matchFrom(DummyResultPool(testInput), 0)
    result.size shouldBe(4)

    val noMatchers = Array(
      fromAtomMatcher(FExact("vord")),
      fromAtomMatcher(FExact("frase"))
    )
    val noCompMatcher = matchersOrderedAllPositive(noMatchers, EmptyCheckerIds, idGroup)
    result = noCompMatcher.matchFrom(DummyResultPool(testInput), 0)
    result.size shouldBe(0)

    val noMatchers2 = Array(
      fromAtomMatcher(FExact("word")),
      fromAtomMatcher(FExact("frase"))
    )
    val noCompMatcher2 = matchersOrderedAllPositive(noMatchers2, EmptyCheckerIds, idGroup)
    result = noCompMatcher2.matchFrom(DummyResultPool(testInput), 0)
    result.size shouldBe(0)
  }
} 
开发者ID:new2scala,项目名称:text-util,代码行数:48,代码来源:CompositeMatcherTest.scala


示例6: MatcherTmplTest

//设置package包名称以及导入依赖的类
package org.dele.text.maen.matchers

import org.dele.text.maen.ConfValueStringParser.Parsed
import org.dele.text.maen.TestHelper._
import SubMatchCheckerLib._
import org.dele.text.maen.test.TestAtom._
import org.dele.text.maen.AtomPropMatcherLib
import org.dele.text.maen.test.{TestAtom, TestInput}
import org.dele.text.maen.TInput
import org.scalatest.ShouldMatchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class MatcherTmplTest extends TestNGSuite with ShouldMatchers {
  @Test
  def t1 = {
    import MatcherTmpl._
    import TSubMatchChecker._
    import TMatcher._
    import org.dele.text.maen.AtomPropMatcherLib._
    import org.dele.text.maen.test.TestInput._
    val lngChecker = "lngChecker"
    implicit val checkerLib = new SubMatchCheckerLib(Map(lngChecker -> Parsed("Lng", Array())), List()) //SubMatchCheckerLib.c(Map(lngChecker -> ListNGramChecker))
    val tmplId = "id1"
    val tlib = new MatcherTmplLib(
      List(new MatcherTmplDef(tmplId, "MTL_RepetitionAll", lngChecker)), List()
    )
    val matcherId = "orgCompanyMatcher"
    val matcher = fromAtomMatcher(E(EmptyRegexDict, Array("Organization", "Company")), EmptyCheckerIds, Option(matcherId))
    val mm = MatcherManager.create
    mm.add(matcher)

    val id2 = "orgCompanySeq"
    val m2 = tlib.spawn(tmplId, Array(Array(matcherId)), EmptyRegexDict, Option(id2))
    mm.add(m2)

    val input:TInput = fromAtomArrayEng(IndexedSeq(
      textAtom("Now"),
      entityAtom("FBI", "Organization", "OrgEntity"),
      entityAtom("Microsoft", "Company", "OrgEntity"),
      textAtom("and"),
      entityAtom("IBM", "Company", "OrgEntity")
    ))

    val rp = mm.m(input, EmptySubMatchCheckerLib, MatcherManager.EmptyMIdFilters)
    val r = rp.query(id2)
    r.size shouldBe >(0)
  }
} 
开发者ID:new2scala,项目名称:text-util,代码行数:51,代码来源:MatcherTmplTest.scala


示例7: FromAtomMatcherTest

//设置package包名称以及导入依赖的类
package org.dele.text.maen

import org.dele.text.maen.test.TestAtom.Atom
import org.dele.text.maen.matchers.TMatcher
import org.scalatest.ShouldMatchers
import org.scalatest.testng.TestNGSuite
import org.testng.annotations.Test


class FromAtomMatcherTest extends TestNGSuite with ShouldMatchers {
  import TMatcher._
  import TestHelper._
  import AtomPropMatcherLib._
  import org.dele.text.maen.test.TestInput._
  @Test
  def t1 = {
    implicit val subMatchCheckerLib = EmptySubMatchCheckerLib
    val seqMatcher = fromAtomMatcher(F(EmptyRegexDict, "word"))
    val input = fromAtomArrayEng(IndexedSeq(
      Atom("Word", Map()),
      Atom("to", Map()),
      Atom("word", Map())
    ))

    val matches = seqMatcher.m(
      DummyResultPool(input)
    )

    matches.size shouldBe(2)

  }

} 
开发者ID:new2scala,项目名称:text-util,代码行数:34,代码来源:FromAtomMatcherTest.scala


示例8: AbbrevListSpec

//设置package包名称以及导入依赖的类
// src/test/scala/progscala2/typesystem/bounds/list/AbbrevListSpec.scala
package progscala2.typesystem.bounds.list
import org.scalatest.{ FunSpec, ShouldMatchers }


class AbbrevListSpec extends FunSpec with ShouldMatchers {

  describe ("AbbrevNil") {
    it ("item :: AbbrevNil == AbbrevList(item)") {
      val list = (1 :: AbbrevNil)
      list.head shouldEqual 1
      list.tail shouldEqual AbbrevNil
    }
    it ("AbbrevNil.foreach(...) does nothing") {
      var failed = false
      AbbrevNil.foreach { x => failed = true }
      failed shouldEqual false
    }
  }

  describe ("::") {
    it ("item :: nonEmptyAbbrevList == AbbrevList(item, ...)") {
      val list  = 1 :: 2 :: AbbrevNil
      val list2 = 3 :: list
      list2.head shouldEqual 3
      list2.tail.head shouldEqual 1
      list2.tail.tail.head shouldEqual 2
      list2.tail.tail.tail shouldEqual AbbrevNil
    }
    it ("nonEmptyAbbrevList.foreach(...) does something for each element") {
      var count = 0
      (1 :: 2 :: AbbrevNil).foreach { x => count += 1 }
      count shouldEqual 2
    }
  }
} 
开发者ID:vr1090,项目名称:scala-ing,代码行数:37,代码来源:AbbrevListSpec.scala


示例9: ComplexSpec

//设置package包名称以及导入依赖的类
// src/test/scala/progscala2/toolslibs/ComplexSpec.scala
package progscala2.toolslibs
import org.scalatest.{ FunSpec, ShouldMatchers }

class ComplexSpec extends FunSpec with ShouldMatchers {
  describe ("Complex addition with (0.0, 0.0)") {
    it ("returns a number N' that is identical to original number N") {
      val c1 = Complex(1.2, 3.4)
      (c1 + Complex(0.0, 0.0)) shouldEqual c1
    }
  }
  describe ("Complex subtraction with (0.0, 0.0)") {
    it ("returns a number N' that is identical to original number N") {
      val c1 = Complex(1.2, 3.4)
      (c1 - Complex(0.0, 0.0)) shouldEqual c1
    }
  }
  describe ("Complex addition") {
    it ("returns a new number where the real and imaginary parts are the sums of the input values' real and imaginary parts, respectively.") {
      val c1 = Complex(1.2, 3.4)
      val c2 = Complex(5.6, 7.8)
      (c1 + c2).real shouldEqual (c1.real + c2.real)
      (c1 + c2).imaginary shouldEqual (c1.imaginary + c2.imaginary)
    }
  }
  describe ("Complex subtraction") {
    it ("return a new number where the real and imaginary parts are the differences of the input values' real and imaginary parts, respectively.") {
      val c1 = Complex(1.2, 3.4)
      val c2 = Complex(5.6, 7.8)
      (c1 - c2).real shouldEqual (c1.real - c2.real)
      (c1 - c2).imaginary shouldEqual (c1.imaginary - c2.imaginary)
    }
  }
} 
开发者ID:vr1090,项目名称:scala-ing,代码行数:35,代码来源:ComplexSpec.scala


示例10: ReaperUTest

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

import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import com.example.StopSystemAfterAll
import org.scalatest.{FlatSpecLike, ShouldMatchers}

class ReaperUTest
  extends TestKit(ActorSystem("testsystem"))
  with FlatSpecLike
  with ShouldMatchers
  with StopSystemAfterAll
  with ImplicitSender {

  import Reaper._

  override def afterAll(): Unit = {
    system.shutdown()
    super.afterAll()
  }

  trait ReaperFixture {
    val reaper = system.actorOf(Props(new TestReaper(testActor)))
    val actor1 = TestProbe()
    val actor2 = TestProbe()
    val actor3 = TestProbe()
    val actor4 = TestProbe()
  }

  "The Reaper" should "call the allSoulsReaped method after all watched actors are dead" in new ReaperFixture {
    reaper ! WatchMe(actor3.ref)
    reaper ! WatchMe(actor1.ref)

    system.stop(actor1.ref)
    system.stop(actor3.ref)

    expectMsg("Dead")
  }

  it should "fail to call the allSoulsReaped method if not all watched actors are dead" in new ReaperFixture {
    reaper ! WatchMe(actor3.ref)
    reaper ! WatchMe(actor1.ref)

    system.stop(actor1.ref)
    expectNoMsg()
  }

} 
开发者ID:shafiquejamal,项目名称:akka-scala-reaper-seed,代码行数:49,代码来源:ReaperUTest.scala


示例11: ComputationStrategyTest

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

import com.socrata.computation_strategies.StrategyType._
import org.scalatest.{ShouldMatchers, FunSuite}

class ComputationStrategyTest extends FunSuite with ShouldMatchers {
  import TestData._

  val strategies = StrategyType.allStrategyTypes - Test // Don't care to test Test strategy

  def forStrategyData(test: StrategyData => Unit): Unit = {
    strategies.foreach { typ =>
      test(data(typ))
    }
  }

  test("Should map strategy types to the correct computation strategy") {
    val strategies = ComputationStrategy.strategies

    var count = 0
    def testStrategies(typ: StrategyType, strategy: ComputationStrategy): Unit = {
      strategies.get(typ) should be (Some(strategy))
      count += 1
    }

    testStrategies(GeoRegionMatchOnPoint, GeoRegionMatchOnPointComputationStrategy)
    testStrategies(GeoRegion, GeoRegionMatchOnPointComputationStrategy)
    testStrategies(GeoRegionMatchOnString, GeoRegionMatchOnStringComputationStrategy)
    testStrategies(Geocoding, GeocodingComputationStrategy)
    testStrategies(Test, TestComputationStrategy)

    strategies.size should be (count) // force people to update this test if they add new strategies
    strategies.size should be (StrategyType.allStrategyTypes.size)
  }

  test("Should be able to validate all strategy types") {
    forStrategyData { data =>
      ComputationStrategy.validate(data.fullDefinition) should be (None)
    }
  }

  test("Should be able to validate all strategy types with column types") {
    forStrategyData { data =>
      ComputationStrategy.validate(data.fullDefinition, columnTypes) should be (None)
    }
  }

  test("Should be able to transform all strategy types") {
    forStrategyData { data =>
      ComputationStrategy.transform(data.fullDefinition, columnIds) should be (data.fullDefinitionTransformed)
    }
  }
} 
开发者ID:socrata-platform,项目名称:computation-strategies,代码行数:54,代码来源:ComputationStrategyTest.scala


示例12: GeocodingComputationStrategyTest

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

import com.socrata.computation_strategies.GeocodingComputationStrategy.GeocodingSourcesDoNotMatchSourceColumns
import org.scalatest.{ShouldMatchers, FunSuite}

class GeocodingComputationStrategyTest extends FunSuite with ShouldMatchers {
  import TestData._
  import TestData.GeocodingData._

  def testValidate(definition: StrategyDefinition[String], expected: Option[ValidationError] = None): Unit = {
    GeocodingComputationStrategy.validate(definition) should be (expected)
  }

  def testTransform(definition: StrategyDefinition[String],
                    columns: Map[String, Int],
                    expected: Either[ValidationError, StrategyDefinition[Int]]): Unit = {
    GeocodingComputationStrategy.transform(definition, columns) should be (expected)
  }

  test("Definition with full sources and parameters should be invalid") {
    testValidate(fullDefinition)
  }

  test("Definition with no sources should be invalid") {
    val expected = Some(GeocodingSourcesDoNotMatchSourceColumns(List(), Some(GeocodingSources(Some(address),Some(city),
      Some(county),Some(state),Some(zip),Some(country)))))
    testValidate(noSourcesDefinition, expected)
  }

  test("Definition with no parameters should be invalid") {
    testValidate(noParamsDefinition, Some(MissingParameters(GeocodingParameterSchema)))
  }

  test("Definition with an unknown source column should fail to transform") {
    testTransform(fullDefinition, columnIds - address, Left(UnknownSourceColumn(address)))
  }

} 
开发者ID:socrata-platform,项目名称:computation-strategies,代码行数:39,代码来源:GeocodingComputationStrategyTest.scala


示例13: MatchingAlgorithmsUTest

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

import com.sjsortablecodingchallenge.TestFixtures
import com.sjsortablecodingchallenge.listing.Listing
import com.sjsortablecodingchallenge.matching.MatchingAlgorithms._
import org.scalatest.{FlatSpec, ShouldMatchers}

class MatchingAlgorithmsUTest extends FlatSpec with ShouldMatchers with TestFixtures {

  "matching on manufacturer and (in title) the model field" should "succeed if the listing title contains the text in " +
  "all fields regardless of case, but not if ' for ' is in the title, and only if the word is not part of a larger word, " +
  "and replace dashes with space, remove dashes, and remove spaces in model" in new Products {
    val matchingListingNoChange = Listing("lastest dsc-W310, brand new", "sOny", "USD", "10.99")
    val matchingListingWithSpace = Listing("lastest dsc W310, brand new", "sOny", "USD", "10.99")
    val matchingListingRemoveDash = Listing("lastest dscW310, brand new", "sOny", "USD", "10.99")
    val matchingListingButWithFor = Listing(" for sale! lastest dsc-W310, brand new", "Sony", "USD", "10.99")
    val matchingListingButWithForeignFor =
      Listing(" f" + "\u00FC" + "r sale! lastest dsc-W310, brand new", "Sony", "USD", "10.99")
    val matchingListingButWithMaybeFor = Listing(" f?r sale! lastest dsc-W310, brand new", "Sony", "USD", "10.99")
    val nonMatchingModel = Listing("sOnY sale! lastest dsc-W3101, brand new", "Sony", "KZT", "10.99")
    val nonMatchingManufacturer = Listing(" sale! lastest dsc-W310, brand new", "fakeSony", "GBP", "10.99")

    matchUsingRegexsDashesSpaces(sonyCybershot, matchingListingNoChange) shouldBe true
    matchUsingRegexsDashesSpaces(sonyCybershot, matchingListingWithSpace) shouldBe true
    matchUsingRegexsDashesSpaces(sonyCybershot, matchingListingRemoveDash) shouldBe true
    matchUsingRegexsDashesSpaces(sonyCybershot, matchingListingButWithFor) shouldBe false
    matchUsingRegexsDashesSpaces(sonyCybershot, matchingListingButWithForeignFor) shouldBe false
    matchUsingRegexsDashesSpaces(sonyCybershot, matchingListingButWithMaybeFor) shouldBe false
    matchUsingRegexsDashesSpaces(sonyCybershot, nonMatchingModel) shouldBe false
    matchUsingRegexsDashesSpaces(sonyCybershot, nonMatchingManufacturer) shouldBe false

    matchUsingRegexsDashesSpaces(sonyCybershotNoDash, matchingListingNoChange) shouldBe true
    matchUsingRegexsDashesSpaces(sonyCybershotNoDash, matchingListingWithSpace) shouldBe true
    matchUsingRegexsDashesSpaces(sonyCybershotNoDash, matchingListingRemoveDash) shouldBe true
    matchUsingRegexsDashesSpaces(sonyCybershotNoDash, matchingListingButWithFor) shouldBe false
    matchUsingRegexsDashesSpaces(sonyCybershotNoDash, matchingListingButWithForeignFor) shouldBe false
    matchUsingRegexsDashesSpaces(sonyCybershotNoDash, matchingListingButWithMaybeFor) shouldBe false
    matchUsingRegexsDashesSpaces(sonyCybershotNoDash, nonMatchingModel) shouldBe false
    matchUsingRegexsDashesSpaces(sonyCybershotNoDash, nonMatchingManufacturer) shouldBe false
  }

} 
开发者ID:shafiquejamal,项目名称:scc,代码行数:43,代码来源:MatchingAlgorithmsUTest.scala


示例14: closeTo

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

import core.models.{Body, Vector2D}
import org.scalatest.ShouldMatchers

trait Helpers extends ShouldMatchers {
  private val Tolerance = 0.01
  def closeTo(testValue: Double) = testValue +- Tolerance

  def randomScalar = math.random - 0.5

  def randomVector = Vector2D(randomScalar, randomScalar)
  def randomVectors: Stream[Vector2D] = randomVector #:: randomVectors
  def randomVectorPairs: Stream[(Vector2D, Vector2D)] = randomVectors.zip(randomVectors)
  def randomVectorTriplets: Stream[(Vector2D, Vector2D, Vector2D)] =
    (randomVector, randomVector, randomVector) #:: randomVectorTriplets

  def randomBody = Body(
    position = randomVector,
    velocity = randomVector,
    force = randomVector,
    mass = randomScalar)
} 
开发者ID:sumanyu,项目名称:n-body-akka,代码行数:24,代码来源:Helpers.scala


示例15: MessageBrokerMessageDispatcherUTest

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

import akka.actor.ActorSystem
import akka.testkit.TestKit
import org.scalamock.scalatest.MockFactory
import org.scalatest.{FlatSpecLike, ShouldMatchers, Suite, BeforeAndAfterAll}

class MessageBrokerMessageDispatcherUTest
 extends TestKit(ActorSystem("TestSystem"))
  with FlatSpecLike
  with ShouldMatchers
  with StopSystemAfterAll
  with MockFactory {
  
}

trait StopSystemAfterAll extends BeforeAndAfterAll {

  this: TestKit with Suite =>

  override protected def afterAll(): Unit = {
    super.afterAll()
    system.terminate()
  }

} 
开发者ID:shafiquejamal,项目名称:microservice-template-play,代码行数:27,代码来源:MessageBrokerMessageDispatcherUTest.scala


示例16: SearchingServiceSpec

//设置package包名称以及导入依赖的类
package com.github.notyy.service

import com.github.notyy.client.ProductClient
import com.github.notyy.domain.Product
import com.typesafe.scalalogging.slf4j.StrictLogging
import org.scalatest.{FunSpec, ShouldMatchers}

import scala.concurrent.{Await, Future}
import scala.concurrent.duration._

class SearchingServiceSpec extends FunSpec with ShouldMatchers with StrictLogging {

  val searchingService = new SearchingService with ProductClient{
    override protected def host: String = "localhost"
    override protected def port: Int = 1234

    override def findByName(name: String): Future[Option[Product]] = {
      Future(Some(Product("1","router")))
    }
  }

  describe("SearchingService"){
    it("can find product by name"){
      val optProduct = Await.result(searchingService.findByName("router"),1 second)
      optProduct should not be empty
      optProduct.get.id should not be empty
      optProduct.get.name shouldBe "router"
    }
  }
} 
开发者ID:notyy,项目名称:storeBFF,代码行数:31,代码来源:SearchingServiceSpec.scala


示例17: JWTGeneratorSpec

//设置package包名称以及导入依赖的类
package io.really.token.generator

import io.really.jwt.{ JWTResult, JWT }
import org.joda.time.DateTime
import org.scalatest.{ ShouldMatchers, FlatSpec }
import play.api.libs.json.Json

class JWTGeneratorSpec extends FlatSpec with ShouldMatchers {
  val secretKey = "$%^&*)(*&^ddwefdrrewq34543!SDfgg"

  "Really Token" should "return encoded anonymous token when calling `createAnonymousToken`" in {
    val anonyToken = JWTGenerator(secretKey).createAnonymousToken("12234455")
    val JWTResult.JWT(_, payload) = JWT.decode(anonyToken, Some(secretKey))
    payload shouldEqual Json.obj("uid" -> "12234455", "authType" -> "anonymous", "expires" -> 0, "data" -> Json.obj())
  }

  it should "return auth token when sending a valid data" in {
    val authToken = JWTGenerator(secretKey).createAuthToken("/users/12345678987654", AuthType.Password, "12234455")
    val JWTResult.JWT(_, payload) = JWT.decode(authToken, Some(secretKey))
    payload shouldEqual Json.obj("_r" -> "/users/12345678987654", "uid" -> "12234455",
      "authType" -> "password", "expires" -> 0, "data" -> Json.obj())
  }

  "createAnonymousToken" should "set the expires timestamp if the expire data was provided" in {
    val exp = DateTime.now().plusDays(7)
    val anonyToken = JWTGenerator(secretKey).createAnonymousToken("12234455", expires = Some(exp))
    val JWTResult.JWT(_, payload) = JWT.decode(anonyToken, Some(secretKey))
    payload shouldEqual Json.obj("uid" -> "12234455", "authType" -> "anonymous", "expires" -> exp.getMillis, "data" -> Json.obj())
  }

  "createAuthToken" should "set the expires timestamp if the expire data was provided" in {
    val exp = DateTime.now().plusDays(7)
    val authToken = JWTGenerator(secretKey).createAuthToken(
      "/users/12345678987654",
      AuthType.Password, "12234455", expires = Some(exp)
    )
    val JWTResult.JWT(_, payload) = JWT.decode(authToken, Some(secretKey))
    payload shouldEqual Json.obj("_r" -> "/users/12345678987654", "uid" -> "12234455",
      "authType" -> "password", "expires" -> exp.getMillis, "data" -> Json.obj())
  }
} 
开发者ID:radiodb,项目名称:radiodb,代码行数:42,代码来源:JWTGeneratorSpec.scala


示例18: P14Spec

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

import list.P14.duplicate
import org.scalatest.{FlatSpec, ShouldMatchers}

class P14Spec extends FlatSpec with ShouldMatchers {

  "duplicate" must "return an empty list when given an empty list" in {
    val list = List()
    duplicate(list) should be(Nil)
  }

  it must "return a list of two identical elements when given a list with only one element" in {
    val list = List("a")
    duplicate(list) should be(List("a", "a"))
  }

  it must "return a list of two pairs of repeated elements when given a list with two distinct elements" in {
    val list = List("a", "b")
    duplicate(list) should be(List("a", "a", "b", "b"))
  }

  it must "return a list of 4 identical elements when given a list of two identical elements" in {
    val list = List("a", "a")
    duplicate(list) should be(List("a", "a", "a", "a"))
  }

} 
开发者ID:tonyzhoujingtao,项目名称:scala99,代码行数:29,代码来源:P14Spec.scala


示例19: P01EasySpec

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

import list.P01Easy.last
import org.scalatest.{FlatSpec, ShouldMatchers}

class P01EasySpec extends FlatSpec with ShouldMatchers {
  "last" should "return the last element of a non empty list" in {
    val list = List(1, 2, 3, 4, 7)
    last(list) should be(Some(7))
  }

  it should "return None for an empty list" in {
    val list = List()

    last(list) should be(None)
  }
} 
开发者ID:tonyzhoujingtao,项目名称:scala99,代码行数:18,代码来源:P01EasySpec.scala


示例20: P07Spec

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

import list.P07.flatten
import org.scalatest.{FlatSpec, ShouldMatchers}

class P07Spec extends FlatSpec with ShouldMatchers {

  "flatten" must "return an empty list when given an empty list" in {
    val list = List()
    flatten(list) should be(Nil)
  }

  it must "return an empty list when given a list with an embedded empty list" in {
    val list = List(List())
    flatten(list) should be(Nil)
  }

  it must "return flatten list with 1 elements when given a list with one element and an embedded empty list" in {
    val list = List(1, List())
    flatten(list) should be(List(1))
  }

  it must "return flatten list with 2 elements when given a list with one element and an embedded list with one element" in {
    val list = List(1, List(2))
    flatten(list) should be(List(1, 2))
  }

  it must "return flatten list with 3 elements when given a list with two elements and an embedded list with one element" in {
    val list = List(1, 3, List(2))
    flatten(list) should be(List(1, 3, 2))
  }

} 
开发者ID:tonyzhoujingtao,项目名称:scala99,代码行数:34,代码来源:P07Spec.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Status类代码示例发布时间:2022-05-23
下一篇:
Scala TaskContext类代码示例发布时间: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