Sha256: 8142171e73ea97afe35c722506c9e02ce61e6b2c60d6d3f7d3e82e3f8f716c18

Contents?: true

Size: 1.76 KB

Versions: 222

Compression:

Stored size: 1.76 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") {
    Bank.openAccount().getBalance should be (Some(0))
  }

  test("incrementing and checking balance") {
    pending
    val acct = Bank.openAccount()
    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 = Bank.openAccount()
    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 = Bank.openAccount()

    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 = Bank.openAccount()

    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

222 entries across 222 versions & 1 rubygems

Version Path
trackler-2.0.8.48 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.47 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.46 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.45 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.44 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.43 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.42 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.41 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.40 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.39 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.38 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.37 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.36 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.35 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.34 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.33 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.32 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.31 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.30 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala
trackler-2.0.8.29 tracks/scala/exercises/bank-account/src/test/scala/BankAccountTest.scala