82 lines
2.7 KiB
Java
82 lines
2.7 KiB
Java
package com.goldenchart.service;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
class StrategyConditionThresholdNormalizerTest {
|
|
|
|
private static final ObjectMapper MAPPER = new ObjectMapper();
|
|
|
|
@Test
|
|
void preservesK50DirectInput() throws Exception {
|
|
JsonNode root = MAPPER.readTree("""
|
|
{
|
|
"type": "CONDITION",
|
|
"condition": {
|
|
"indicatorType": "RSI",
|
|
"conditionType": "CROSS_UP",
|
|
"leftField": "RSI_VALUE_9",
|
|
"rightField": "K_50",
|
|
"period": 9,
|
|
"valuePeriodOverride": true,
|
|
"thresholdOverride": true,
|
|
"targetValue": 50
|
|
}
|
|
}
|
|
""");
|
|
|
|
JsonNode cond = StrategyConditionThresholdNormalizer.normalizeTree(root).path("condition");
|
|
|
|
assertEquals("K_50", cond.path("rightField").asText());
|
|
assertTrue(cond.path("thresholdOverride").asBoolean(false));
|
|
assertEquals(50.0, cond.path("targetValue").asDouble(), 0.0001);
|
|
}
|
|
|
|
@Test
|
|
void preservesK55DirectInput() throws Exception {
|
|
JsonNode root = MAPPER.readTree("""
|
|
{
|
|
"type": "CONDITION",
|
|
"condition": {
|
|
"indicatorType": "RSI",
|
|
"conditionType": "CROSS_UP",
|
|
"leftField": "RSI_VALUE",
|
|
"rightField": "K_55",
|
|
"thresholdOverride": true,
|
|
"targetValue": 55
|
|
}
|
|
}
|
|
""");
|
|
|
|
JsonNode cond = StrategyConditionThresholdNormalizer.normalizeTree(root).path("condition");
|
|
|
|
assertEquals("K_55", cond.path("rightField").asText());
|
|
assertTrue(cond.path("thresholdOverride").asBoolean(false));
|
|
assertEquals(55.0, cond.path("targetValue").asDouble(), 0.0001);
|
|
}
|
|
|
|
@Test
|
|
void fillsTargetValueFromKFieldWhenMissing() throws Exception {
|
|
JsonNode root = MAPPER.readTree("""
|
|
{
|
|
"type": "CONDITION",
|
|
"condition": {
|
|
"indicatorType": "RSI",
|
|
"rightField": "K_55",
|
|
"thresholdOverride": false
|
|
}
|
|
}
|
|
""");
|
|
|
|
JsonNode cond = StrategyConditionThresholdNormalizer.normalizeTree(root).path("condition");
|
|
|
|
assertEquals("K_55", cond.path("rightField").asText());
|
|
assertTrue(cond.path("thresholdOverride").asBoolean(false));
|
|
assertEquals(55.0, cond.path("targetValue").asDouble(), 0.0001);
|
|
}
|
|
}
|