| 37167 |
amit |
1 |
package com.spice.profitmandi.service;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.dao.enumuration.dtr.AgendaType;
|
|
|
4 |
import org.junit.Test;
|
|
|
5 |
|
|
|
6 |
import java.util.HashMap;
|
|
|
7 |
import java.util.Map;
|
|
|
8 |
|
|
|
9 |
import static org.junit.Assert.assertEquals;
|
|
|
10 |
|
|
|
11 |
public class AgendaRuleDecisionTest {
|
|
|
12 |
|
|
|
13 |
private static Map<String, Double> params(Object... kv) {
|
|
|
14 |
Map<String, Double> m = new HashMap<>();
|
|
|
15 |
for (int i = 0; i < kv.length; i += 2) {
|
|
|
16 |
m.put((String) kv[i], ((Number) kv[i + 1]).doubleValue());
|
|
|
17 |
}
|
|
|
18 |
return m;
|
|
|
19 |
}
|
|
|
20 |
|
|
|
21 |
private static Map<String, Double> salesDefaults() {
|
|
|
22 |
return params("flagPct", 40, "clearPct", 75, "baselineDays", 90, "windowDays", 30);
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
private static AgendaRuleDecider.Inputs baseInputs() {
|
|
|
26 |
AgendaRuleDecider.Inputs in = new AgendaRuleDecider.Inputs();
|
|
|
27 |
in.fofoId = 1;
|
|
|
28 |
in.revival = false;
|
|
|
29 |
in.storeActivatedRecently = false;
|
|
|
30 |
in.minInvestment = 300000;
|
|
|
31 |
in.shortPercentage = 10d;
|
|
|
32 |
in.baselineAmt = 300000; // monthlyBaseline = 100000
|
|
|
33 |
in.currentAmt = 100000;
|
|
|
34 |
in.lastBillDaysAgo = 3;
|
|
|
35 |
in.oldestLoanAgeDays = null;
|
|
|
36 |
in.pendingLoanAmt = 0;
|
|
|
37 |
return in;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
private static Map<AgendaType, AgendaRuleDecider.Decision> decide(AgendaRuleDecider.Inputs in) {
|
|
|
41 |
return AgendaRuleDecider.decide(in,
|
|
|
42 |
params("shortPct", 50), salesDefaults(), params("gapDays", 15), params("loanAgeDays", 20));
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
@Test
|
|
|
46 |
public void salesHysteresisHoldsBetweenBarriers() {
|
|
|
47 |
AgendaRuleDecider.Inputs in = baseInputs();
|
|
|
48 |
in.currentAmt = 60000; // 60% of baseline: between 40 and 75
|
|
|
49 |
assertEquals(AgendaRuleDecider.Action.LEAVE, decide(in).get(AgendaType.LOW_SALES).action);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
@Test
|
|
|
53 |
public void salesFlagsBelow40AndClearsAbove75() {
|
|
|
54 |
AgendaRuleDecider.Inputs in = baseInputs();
|
|
|
55 |
in.currentAmt = 39999;
|
|
|
56 |
assertEquals(AgendaRuleDecider.Action.OPEN, decide(in).get(AgendaType.LOW_SALES).action);
|
|
|
57 |
in.currentAmt = 75001;
|
|
|
58 |
assertEquals(AgendaRuleDecider.Action.CLOSE, decide(in).get(AgendaType.LOW_SALES).action);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
@Test
|
|
|
62 |
public void salesSkipsOnZeroBaselineAndYoungStores() {
|
|
|
63 |
AgendaRuleDecider.Inputs in = baseInputs();
|
|
|
64 |
in.baselineAmt = 0;
|
|
|
65 |
in.currentAmt = 0;
|
|
|
66 |
assertEquals(AgendaRuleDecider.Action.LEAVE, decide(in).get(AgendaType.LOW_SALES).action);
|
|
|
67 |
AgendaRuleDecider.Inputs young = baseInputs();
|
|
|
68 |
young.storeActivatedRecently = true;
|
|
|
69 |
young.currentAmt = 0;
|
|
|
70 |
assertEquals(AgendaRuleDecider.Action.LEAVE, decide(young).get(AgendaType.LOW_SALES).action);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
@Test
|
|
|
74 |
public void purchaseSkippedForRevivalStores() {
|
|
|
75 |
AgendaRuleDecider.Inputs in = baseInputs();
|
|
|
76 |
in.revival = true;
|
|
|
77 |
in.lastBillDaysAgo = 200;
|
|
|
78 |
assertEquals(AgendaRuleDecider.Action.CLOSE, decide(in).get(AgendaType.LOW_PURCHASE).action);
|
|
|
79 |
assertEquals(AgendaRuleDecider.Action.OPEN, decide(in).get(AgendaType.REVIVAL).action);
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
@Test
|
|
|
83 |
public void purchaseFlagsAtGapAndNeverBilled() {
|
|
|
84 |
AgendaRuleDecider.Inputs in = baseInputs();
|
|
|
85 |
in.lastBillDaysAgo = 15; // exactly gapDays
|
|
|
86 |
assertEquals(AgendaRuleDecider.Action.OPEN, decide(in).get(AgendaType.LOW_PURCHASE).action);
|
|
|
87 |
in.lastBillDaysAgo = null; // never billed, non-revival
|
|
|
88 |
assertEquals(AgendaRuleDecider.Action.OPEN, decide(in).get(AgendaType.LOW_PURCHASE).action);
|
|
|
89 |
in.lastBillDaysAgo = 14;
|
|
|
90 |
assertEquals(AgendaRuleDecider.Action.CLOSE, decide(in).get(AgendaType.LOW_PURCHASE).action);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
@Test
|
|
|
94 |
public void creditFlagsAtExactThreshold() {
|
|
|
95 |
AgendaRuleDecider.Inputs in = baseInputs();
|
|
|
96 |
in.oldestLoanAgeDays = 20;
|
|
|
97 |
in.pendingLoanAmt = 50000;
|
|
|
98 |
assertEquals(AgendaRuleDecider.Action.OPEN, decide(in).get(AgendaType.CREDIT_DUES).action);
|
|
|
99 |
in.oldestLoanAgeDays = 19;
|
|
|
100 |
assertEquals(AgendaRuleDecider.Action.CLOSE, decide(in).get(AgendaType.CREDIT_DUES).action);
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
@Test
|
|
|
104 |
public void investmentUsesFiftyTriggerAndSkipsWhenUncomputable() {
|
|
|
105 |
AgendaRuleDecider.Inputs in = baseInputs();
|
|
|
106 |
in.shortPercentage = 51d;
|
|
|
107 |
assertEquals(AgendaRuleDecider.Action.OPEN, decide(in).get(AgendaType.LOW_INVESTMENT).action);
|
|
|
108 |
in.shortPercentage = 50d;
|
|
|
109 |
assertEquals(AgendaRuleDecider.Action.CLOSE, decide(in).get(AgendaType.LOW_INVESTMENT).action);
|
|
|
110 |
in.shortPercentage = null;
|
|
|
111 |
assertEquals(AgendaRuleDecider.Action.LEAVE, decide(in).get(AgendaType.LOW_INVESTMENT).action);
|
|
|
112 |
}
|
|
|
113 |
}
|