-
Notifications
You must be signed in to change notification settings - Fork 0
/
instruction_test.go
49 lines (42 loc) · 1.56 KB
/
instruction_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
package main
import (
"fmt"
"reflect"
"testing"
"time"
)
func TestInstructionsAreAlwaysSettledOnAWorkingDay(t *testing.T) {
var tests = []struct{
Currency string
DaysDiff []int // Number of days to add to get to the next working day for each day of the week
}{
{"AED", aedSarDaysDiff},
{"SAR", aedSarDaysDiff},
{"GBP", othersDaysDiff},
}
for _, test := range tests {
day := time.Date(2016, time.January, 3, 0, 0, 0, 0, time.UTC) // January 3rd 2016 was a Sunday
end := day.AddDate(0, 0, 7) // A week later
for day.Before(end) {
subTestName := fmt.Sprintf("%s:%s", test.Currency, day.Weekday())
t.Run(subTestName, func(t *testing.T) {
instruction := buildTestInstruction("", "", 1.0, test.Currency, "", day.Format(inputDateFormat), 1, 1.0)
instruction.processSettlementDate()
days := test.DaysDiff[int(day.Weekday())]
expected := day.AddDate(0, 0, days)
if !reflect.DeepEqual(instruction.SettlementDate, expected) {
t.Errorf("Expected: %s; Got: %s", expected, instruction.SettlementDate)
}
})
day = day.AddDate(0, 0, 1)
}
}
}
func TestGettingInstructionsUsdAMount(t *testing.T) {
instruction := buildTestInstruction("", "", 2.0, "", "", "", 100, 1.5)
amount := instruction.getUsdAmount()
expected := float32(300)
if amount != expected {
t.Errorf("Expected: %v; Got: %v", expected, amount)
}
}