-
Notifications
You must be signed in to change notification settings - Fork 0
/
categorytest.ts
167 lines (134 loc) · 4.3 KB
/
categorytest.ts
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { Client, CreateRecurringTransaction } from './react_ui/src/state.ts';
import { Budget } from "./personalfinance.ts"
import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
const product =
(...as: any) => as.reduce((product: any, curr: any) => product.flatMap((currP: any) => curr.map((e: any) => [currP, e].flat())));
type DateRange = {
start: Date,
end: Date,
};
type TestFrame = {
dateRange: DateRange,
recurringTransactions: CreateRecurringTransaction[],
};
function selectMiddleOfDayStart(input: TestFrame) {
input.dateRange.start.setHours(12);
}
function selectEndOfDayStart(input: TestFrame) {
input.dateRange.start.setHours(12);
}
function selectBeginningOfDayStart(input: TestFrame) {
input.dateRange.start.setHours(2);
}
function startTimeOfDayCategory() {
return [selectMiddleOfDayStart, selectEndOfDayStart, selectBeginningOfDayStart];
}
function selectMiddleOfDayEnd(input: TestFrame) {
input.dateRange.end.setHours(12);
}
function selectEndOfDayEnd(input: TestFrame) {
input.dateRange.end.setHours(12);
}
function selectBeginningOfDayEnd(input: TestFrame) {
input.dateRange.end.setHours(2);
}
function endTimeOfDayCategory() {
return [selectMiddleOfDayEnd, selectEndOfDayEnd, selectBeginningOfDayEnd];
}
function selectShortDuration(input: TestFrame) {
input.dateRange.start.setMonth(1);
input.dateRange.end.setMonth(2);
}
function selectMediumDuration(input: TestFrame) {
input.dateRange.start.setMonth(3);
input.dateRange.end.setMonth(6);
}
function selectLongDuration(input: TestFrame) {
input.dateRange.start.setMonth(0);
input.dateRange.end.setMonth(11);
}
function durationCategory() {
return [selectShortDuration, selectMediumDuration, selectLongDuration];
}
function selectSomeMonthlyRule(input: TestFrame) {
const rts: CreateRecurringTransaction[] = [
{
name: "monthlyRt1",
amount: 10.00,
recurrenceRule: { recurrenceType: "monthly", day: 2 },
}
];
for (const rt of rts) {
input.recurringTransactions.push(rt);
}
}
function selectSomeWeeklyRule(input: TestFrame) {
const rts: CreateRecurringTransaction[] = [
{
name: "weeklyRt1",
amount: 10.00,
recurrenceRule: { recurrenceType: "weekly", day: 2, basis: new Date("2022-01-07"), interval: 4 },
}
];
for (const rt of rts) {
input.recurringTransactions.push(rt);
}
}
function selectSomeMixedRules(input: TestFrame) {
const rts: CreateRecurringTransaction[] = [
{
name: "monthlyRt2",
amount: 4.00,
recurrenceRule: { recurrenceType: "monthly", day: 19 },
},
{
name: "weeklyRt2",
amount: 1000.00,
recurrenceRule: { recurrenceType: "weekly", day: 2, basis: null, interval: null },
}
];
for (const rt of rts) {
input.recurringTransactions.push(rt);
}
}
function ruleTypeCategory() {
return [selectSomeMonthlyRule, selectSomeWeeklyRule, selectSomeMixedRules];
}
type SelectionFunc = (i: TestFrame) => void;
const selectionCombinations: SelectionFunc[][] = product(
startTimeOfDayCategory(),
endTimeOfDayCategory(),
durationCategory(),
ruleTypeCategory(),
);
let testFrames: TestFrame[] = [];
console.log(`Generated ${selectionCombinations.length} test frames`);
for (const selectionCombination of selectionCombinations) {
let startDate = new Date();
let endDate = new Date();
let recurringTransactions: CreateRecurringTransaction[] = [];
let frame = { dateRange: { start: startDate, end: endDate }, recurringTransactions };
for (const selection of selectionCombination) {
selection(frame);
}
testFrames.push(frame);
}
Deno.test("Category-partition inputs plus model conformance property", async (t) => {
let i = 0;
for (const frame of testFrames) {
let client = new Client();
let budget = new Budget();
await client.setup();
await t.step(`Frame ${i}`, async (t) => {
for (const crt of frame.recurringTransactions) {
await client.addRecurringTransaction(crt);
budget.addRecurringTransaction(crt);
}
await client.viewScheduledTransactions(frame.dateRange.start, frame.dateRange.end);
budget.viewScheduledTransactions(frame.dateRange.start, frame.dateRange.end);
assertEquals(client.scheduledTransactions, budget.scheduledTransactions);
});
i += 1;
await client.teardown();
}
});