本文整理汇总了Scala中scala.language.postfixOps类的典型用法代码示例。如果您正苦于以下问题:Scala postfixOps类的具体用法?Scala postfixOps怎么用?Scala postfixOps使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了postfixOps类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: MidiPlayerSpec
//设置package包名称以及导入依赖的类
package de.htwg.scalala.midi
import de.htwg.scalala.music.Key
import org.scalatest.WordSpec
import org.scalatest.Matchers
import scala.language.postfixOps
import de.htwg.scalala.music._
import scala.concurrent.duration._
import scala.language.postfixOps
class MidiPlayerSpec extends WordSpec {
"A MidiPlayer" should {
val midiplayer = new MidiPlayer
"play Keys encoded in midiKeys (0-127, c is key 60) for a duration in milliseconds" in {
midiplayer.play(key = 60, duration = 100 milliseconds)
Thread.sleep(100)
}
"play a set of Keys simultaneously, needed for chords" in {
val set = Set(new Key(60), new Key(64), new Key(67))
midiplayer.play(set, 75)
}
"start and stop a key with some delay inbetween. This is needed to play several keys at once." in {
midiplayer.start(60)
Thread.sleep(100)
midiplayer.stop(60)
}
"be able to change instrument" in {
midiplayer.changeToInstrument(40)
midiplayer.play(60, 100 milliseconds)
Thread.sleep(200)
}
}
}
示例2: DiscoveryRepositorySpec
//设置package包名称以及导入依赖的类
package com.socialthingy.plusf.p2p.discovery
import java.net.InetSocketAddress
import akka.actor.ActorSystem
import org.scalatest.{FlatSpec, Matchers}
import scala.language.postfixOps
import scala.concurrent.duration._
import scala.language.postfixOps
class DiscoveryRepositorySpec extends FlatSpec with Matchers {
val testAddr1 = new InetSocketAddress("localhost", 7000)
val testAddr2 = new InetSocketAddress("localhost", 7001)
"DiscoveryRepository" should "create a new session under a session ID it hasn't seen before" in new TestDiscoveryRepository {
connectToSession("newId", testAddr1) shouldBe None
}
it should "return the session initiator's address when a new client connects to a prior session" in new TestDiscoveryRepository {
connectToSession("newId", testAddr1)
connectToSession("newId", testAddr2) shouldBe Some(testAddr1)
}
it should "do nothing when the initiator attempts to connect to a session it has already initiated" in new TestDiscoveryRepository {
connectToSession("newId", testAddr1)
connectToSession("newId", testAddr1) shouldBe None
}
it should "clean out a session once two peers have connected" in new TestDiscoveryRepository {
connectToSession("newId", testAddr1)
connectToSession("newId", testAddr2)
connectToSession("newId", testAddr2) shouldBe None
}
it should "clean out expired sessions when scheduled cleanup takes place" in new TestDiscoveryRepository {
scheduleCleanup(1 second, 5 seconds)
connectToSession("newId", testAddr1) shouldBe None
Thread.sleep(6000)
connectToSession("newId", testAddr2) shouldBe None
}
it should "clean out a session when told to cancel it" in new TestDiscoveryRepository {
connectToSession("toBeCancelled", testAddr1) shouldBe None
cancelSession("toBeCancelled", testAddr1)
connectToSession("toBeCancelled", testAddr2) shouldBe None
}
trait TestDiscoveryRepository extends DiscoveryRepository {
val system = ActorSystem()
}
}