-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbank_requests_test.go
75 lines (67 loc) · 1.24 KB
/
bank_requests_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package bank_account_processor
import (
"testing"
)
func getRequestData() ([][]string, [][]int, [][]int) {
requestsMap := [][]string{
{
"giveMeAHuge 1 3",
},
{
"transfer 1 4 10",
"deposit 3 10",
"withdraw 5 15",
},
{
"transfer 1 4 40",
"deposit 3 10",
"withdraw 5 65",
},
{
"transfer 2 4 50",
"transfer 5 8 580",
"deposit 3 10",
"deposit 8 10",
"withdraw 5 65",
"withdraw 11 65",
"withdraw 2 10",
},
{
"transfer 1 3 35",
},
{
"transfer 1 3 35",
"deposit 12 1200",
},
}
balancesMap := [][]int{
{},
{20, 30, 10, 90, 60},
{20, 30, 10, 90, 60},
{10, 50, 200, 85, 15, 50, 45, 65, 70, 90},
{45},
{45, 10, 10},
}
exp := [][]int{
{0}, {10, 30, 20, 100, 45}, {0}, {-1}, {0}, {-1},
}
return requestsMap, balancesMap, exp
}
func compareSlices(s1 []int, s2 []int) bool {
for i, s := range s1 {
if s != s2[i] {
return false
}
}
return true
}
func TestBankRequests(t *testing.T) {
requests, balances, exp := getRequestData()
for i, request := range requests {
res := bankRequests(request, balances[i])
equal := compareSlices(exp[i], res)
if !equal {
t.Errorf("Failed: Wrong Answer - r: %v i: %v e: %v, a: %v", request, balances[i], exp[i], res)
}
}
}