yeg
2026-09-28 9c93934b70ccfca081102944a47f3baafad3c218
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
package com.battery.device.neware;
 
import static org.junit.jupiter.api.Assertions.assertEquals;
 
import org.junit.jupiter.api.Test;
import com.battery.device.api.StepDirectionResolver.Direction;
 
/** 工步类型数字到方向的映射:已知取值照映射,未确认取值保持未知,不按电流符号猜。 */
class NewareStepDirectionResolverTest
{
    private final NewareStepDirectionResolver resolver = new NewareStepDirectionResolver();
 
    @Test
    void mapsTheConfirmedNumericStepTypes()
    {
        // 现场实测:1 充电、2 放电、4 搁置;空白按未知处理。
        assertEquals(Direction.CHARGE, resolver.resolve("1"));
        assertEquals(Direction.DISCHARGE, resolver.resolve("2"));
        assertEquals(Direction.REST, resolver.resolve(" 4 "));
    }
 
    @Test
    void keepsUnconfirmedNumericTypesUnknown()
    {
        // cap_step 里还出现过 3、5、7、13,语义未确认;未知就是未知,不能按数值或电流方向推断。
        for (String type : new String[] { "3", "5", "7", "13", "0", "99", "abc", "cc", "rest", " " })
            assertEquals(Direction.UNKNOWN, resolver.resolve(type), type);
        assertEquals(Direction.UNKNOWN, resolver.resolve(null));
    }
}