Files
go-learning/exercises/01-core/03-structs-pointers/pointers_test.go
T

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)
}
}