-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreference_lookup_test.go
59 lines (50 loc) · 1.31 KB
/
reference_lookup_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
package main
import (
"testing"
"github.com/shopspring/decimal"
)
func TestIdentifyMembers(t *testing.T) {
txns := []*bankTxn{
{"JOE BLOGGS", decimal.New(15, 1)},
{"NO MATCH", decimal.New(30, 1)},
{"JOE BLOGGS", decimal.New(15, 1)},
}
refs := map[string][]string{
"JOE BLOGGS": {"A123456", "A789012"},
}
expectedMemberIds := []string{
"A123456",
"A789012",
}
expectedUnmatchedTxns := []*bankTxn{
{"NO MATCH", decimal.New(30, 1)},
}
actualMemberIds, actualUnmatchedTxns := identifyMembers(txns, refs)
if actualMemberIds == nil || actualUnmatchedTxns == nil {
t.Fatalf("One or more return values are nil!")
}
if len(actualMemberIds) != len(expectedMemberIds) {
t.Fatalf(
"MemberId lengths don't match (%v, %v)",
len(actualMemberIds),
len(expectedMemberIds),
)
}
if len(actualUnmatchedTxns) != len(expectedUnmatchedTxns) {
t.Fatalf(
"UnmatchedTxn lengths don't match (%v, %v)",
len(actualUnmatchedTxns),
len(expectedUnmatchedTxns),
)
}
for i := range expectedMemberIds {
if expectedMemberIds[i] != actualMemberIds[i] {
t.Fatalf("%v != %v", expectedMemberIds[i], actualMemberIds[i])
}
}
for i := range expectedUnmatchedTxns {
if !expectedUnmatchedTxns[i].equal(actualUnmatchedTxns[i]) {
t.Fatalf("%v != %v", expectedUnmatchedTxns[i], actualUnmatchedTxns[i])
}
}
}