Skip to content

Instantly share code, notes, and snippets.

@HusseinMorsy
Created January 30, 2015 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HusseinMorsy/cdcf9b0147ac4128f785 to your computer and use it in GitHub Desktop.
Save HusseinMorsy/cdcf9b0147ac4128f785 to your computer and use it in GitHub Desktop.
class Account
def initialize(value = 0)
@deposit = value
@history = ['Account created with 0 deposit']
end
def deposit
@deposit
end
def increase_deposit_by(value)
@deposit += value
@history << "deposit increased by #{value}"
end
def decrease_deposit_by(value)
@deposit -= value
@history << "deposit decreases by #{value}"
end
def reset_deposit
@deposit = 0
@history << 'deposit reseted'
end
def deposit_history
@history
end
end
require 'minitest/autorun'
class TestAccount < MiniTest::Unit::TestCase
def test_addition
assert_equal 3, 15 % 6
end
def test_initial_deposit
account = Account.new
assert_equal 0, account.deposit
# expect(account.deposit).to eq(0)
end
def test_initial_deposit_with_given_value
account = Account.new(3)
assert_equal 3, account.deposit
end
def test_increase_deposit_by
account = Account.new(0)
account.increase_deposit_by(2)
assert_equal 2, account.deposit
account.increase_deposit_by(1)
assert_equal 3, account.deposit
end
def test_decrease_deposit_by
account = Account.new(5)
account.decrease_deposit_by(2)
assert_equal 3, account.deposit
account.decrease_deposit_by(-3)
assert_equal 6, account.deposit
end
def test_reset
account=Account.new(10)
account.reset_deposit
assert_equal 0, account.deposit
end
def test_deposit_history
account = Account.new(0)
account.increase_deposit_by(3)
account.decrease_deposit_by(2)
account.reset_deposit
account.increase_deposit_by(1)
expected = ['Account created with 0 deposit', 'deposit increased by 3', 'deposit decreases by 2', 'deposit reseted', 'deposit increased by 1']
assert_equal expected, account.deposit_history
end
end
# Regeln für TDD
# 1. Erst den Test schreiben
# 2. Nur minimal implentieren, was die Fehlermeldung erwartet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment