package com.lingniu.ingest.codec;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class BcdCodecTest {

    @Test
    void roundTripEvenLength() {
        // 偶数位直接等值
        byte[] bcd = BcdCodec.encode("1380013800");
        assertThat(BcdCodec.decode(bcd)).isEqualTo("1380013800");
    }

    @Test
    void roundTripOddLengthPadsLeadingZero() {
        // 奇数位会在高位补 0
        byte[] bcd = BcdCodec.encode("13800138000");
        assertThat(BcdCodec.decode(bcd)).isEqualTo("013800138000");
    }

    @Test
    void checksumMatches() {
        byte[] data = {0x01, 0x02, 0x03, 0x04};
        assertThat(BccChecksum.compute(data, 0, data.length)).isEqualTo((byte) 0x04);
    }
}
