29 lines
627 B
Go
29 lines
627 B
Go
package pointers
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestBankAccount(t *testing.T) {
|
|
acc := NewBankAccount(100)
|
|
acc.Deposit(50)
|
|
if acc.Balance() != 150 {
|
|
t.Fatalf("got %d, want 150", acc.Balance())
|
|
}
|
|
if !acc.Withdraw(40) || acc.Balance() != 110 {
|
|
t.Fatalf("withdraw failed, balance=%d", acc.Balance())
|
|
}
|
|
if acc.Withdraw(500) || acc.Balance() != 110 {
|
|
t.Fatalf("expected overdraft rejection, balance=%d", acc.Balance())
|
|
}
|
|
}
|
|
|
|
func TestIncrementAll(t *testing.T) {
|
|
nums := []int{1, 2, 3}
|
|
IncrementAll(nums, 10)
|
|
if !reflect.DeepEqual(nums, []int{11, 12, 13}) {
|
|
t.Fatalf("got %v, want [11 12 13]", nums)
|
|
}
|
|
}
|