Files

46 lines
2.1 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//=======================================================================
// FaultMapTest: 锂电池/配电故障码表的完整性(码值唯一、级别正确)
// 不改动生产代码;仅验证 faultCode.h 中的静态表。
//=======================================================================
#include <gtest/gtest.h>
#include <set>
#include "faultCode.h"
TEST(FaultMapTest, BatteryFaultMap)
{
const size_t n = sizeof(batfaultMap) / sizeof(batfaultMap[0]);
ASSERT_EQ(n, 54u) << "batfaultMap 应有 54 条";
std::set<uint8_t> codes;
for (size_t i = 0; i < n; ++i) {
EXPECT_EQ(batfaultMap[i].id, (int)i + 1) << "id 必须从 1 连续";
EXPECT_GE(batfaultMap[i].level, 1);
EXPECT_LE(batfaultMap[i].level, 4);
EXPECT_TRUE(batfaultMap[i].desc != nullptr && batfaultMap[i].desc[0] != '\0')
<< "desc 不能为空, id=" << i + 1;
EXPECT_TRUE(codes.insert(batfaultMap[i].code).second)
<< "重复故障码 0x" << std::hex << (int)batfaultMap[i].code;
}
// 抽样:4级故障码在 0xCx,3级在 0x8x,1级在 0x0x-0x1x
EXPECT_EQ(batfaultMap[0].code, 0xC1); // id1 四级 MBMS绝缘故障
EXPECT_EQ(batfaultMap[9].code, 0x81); // id10 三级
EXPECT_EQ(batfaultMap[40].code, 0x01); // id41 一级
}
TEST(FaultMapTest, DistributionFaultMap)
{
const size_t n = sizeof(disfaultMap) / sizeof(disfaultMap[0]);
ASSERT_EQ(n, 45u) << "disfaultMap 应有 45 条";
std::set<int> codes;
for (size_t i = 0; i < n; ++i) {
EXPECT_EQ(disfaultMap[i].id, (int)i + 1) << "id 必须从 1 连续";
EXPECT_GE(disfaultMap[i].level, 1);
EXPECT_LE(disfaultMap[i].level, 4);
EXPECT_TRUE(disfaultMap[i].desc != nullptr && disfaultMap[i].desc[0] != '\0');
EXPECT_TRUE(codes.insert(disfaultMap[i].code).second)
<< "重复故障码 " << disfaultMap[i].code;
}
// 断路器脱扣基本是 4 级故障
EXPECT_EQ(disfaultMap[0].level, 3); // id1 燃料电池断路器 3级
EXPECT_EQ(disfaultMap[1].level, 4); // id2 动力锂电池断路器 4级
}