Sha256: a23392324d1eeb37a4b74a65c9ec793c441edc254d1b2eb7a539ddf88e7a5cc1

Contents?: true

Size: 1.71 KB

Versions: 138

Compression:

Stored size: 1.71 KB

Contents

if !System.get_env("EXERCISM_TEST_EXAMPLES") do
  Code.load_file("account.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true

# The BankAccount module should support four calls:
#
# open_bank()
#   Called at the start of each test. Returns an account handle.
#
# close_bank(account)
#   Called at the end of each test.
#
# balance(account)
#   Get the balance of the bank account.
#
# update(account, amount)
#   Increment the balance of the bank account by the given amount.
#   The amount may be negative for a withdrawal.
#
# The initial value of the bank account should be 0.

defmodule BankAccountTest do
  use ExUnit.Case

  setup do
    account = BankAccount.open_bank
    { :ok, account: account }
  end

  # @tag :pending
  test "initial balance is 0", %{account: account} do
    assert BankAccount.balance(account) == 0
  end

  @tag :pending
  test "incrementing and checking balance", %{account: account} do
    assert BankAccount.balance(account) == 0
    BankAccount.update(account, 10)
    assert BankAccount.balance(account) == 10
  end

  @tag :pending
  test "amount is added to balance", %{account: account} do
    assert BankAccount.balance(account) == 0
    BankAccount.update(account, 10)
    BankAccount.update(account, 10)
    assert BankAccount.balance(account) == 20
  end

  @tag :pending
  test "incrementing balance from another process then checking it from test process", %{account: account} do
    assert BankAccount.balance(account) == 0
    this = self()
    spawn(fn ->
      BankAccount.update(account, 20)
      send(this, :continue)
    end)
    receive do
      :continue -> :ok
    after
      1000 -> flunk("Timeout")
    end
    assert BankAccount.balance(account) == 20
  end
end

Version data entries

138 entries across 138 versions & 1 rubygems

Version Path
trackler-2.0.8.39 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.38 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.37 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.36 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.35 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.34 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.33 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.32 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.31 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.30 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.29 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.28 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.27 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.26 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.24 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.23 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.22 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.21 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.20 tracks/elixir/exercises/bank-account/bank_account_test.exs
trackler-2.0.8.19 tracks/elixir/exercises/bank-account/bank_account_test.exs