Sha256: a849529875de15b0959c6dd3e18a7eb22efa0422b9ddc42d173432e9433d5b05
Contents?: true
Size: 1.73 KB
Versions: 14
Compression:
Stored size: 1.73 KB
Contents
import org.scalatest.concurrent.{IntegrationPatience, Conductors} import org.scalatest.{Matchers, FunSuite} class BankAccountTest extends FunSuite with Matchers with Conductors with IntegrationPatience { test("open account") { BankAccount().getBalance should be (Some(0)) } test("incrementing and checking balance") { pending val acct = BankAccount() acct.getBalance should be (Some(0)) acct.incrementBalance(10) should be (Some(10)) acct.getBalance should be (Some(10)) acct.incrementBalance(10) should be (Some(20)) acct.getBalance should be (Some(20)) } test("closed account should hold no balance") { pending val acct = BankAccount() acct.closeAccount() acct.incrementBalance(10) acct.incrementBalance(10) acct.getBalance should be (None) } test("incrementing balance from multiple threads") { pending val conductor = new Conductor import conductor._ val acct = BankAccount() thread("t1") { acct.incrementBalance(10) acct.getBalance should be (Some(10)) beat should be (1) waitForBeat(2) acct.getBalance should be (Some(15)) } thread("t2") { waitForBeat(1) acct.getBalance should be (Some(10)) acct.incrementBalance(5) acct.getBalance should be (Some(15)) beat should be (2) } } test("incrementing balance from multiple threads - concurrent updates") { pending val conductor = new Conductor import conductor._ val acct = BankAccount() thread("t1") { for (a <- 1 to 10) acct.incrementBalance(10) } thread("t2") { for (a <- 1 to 10) acct.incrementBalance(5) } whenFinished { acct.getBalance should be (Some(150)) } } }
Version data entries
14 entries across 14 versions & 1 rubygems