gopl-zh.github.com/vendor/gopl.io/ch9/bank2/bank_test.go
github-actions[bot] ca571eb691 deploy: 06a1bdf735
2022-08-04 06:59:33 +00:00

29 lines
524 B
Go

// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
package bank_test
import (
"sync"
"testing"
"gopl.io/ch9/bank2"
)
func TestBank(t *testing.T) {
// Deposit [1..1000] concurrently.
var n sync.WaitGroup
for i := 1; i <= 1000; i++ {
n.Add(1)
go func(amount int) {
bank.Deposit(amount)
n.Done()
}(i)
}
n.Wait()
if got, want := bank.Balance(), (1000+1)*1000/2; got != want {
t.Errorf("Balance = %d, want %d", got, want)
}
}