c# - 如果列表小于 8,则未检测到突变
问题描述
最近我开始做一些 C#,来自 PHP。我玩语言和学习的方式是做一些 TDD。因此,我获取了一些 RFC 规范并编写了一些测试(此处为 RFC 规范)。
我现在正在使用 NUnit,并使用 Stryker 来检查测试质量。
情况如下:我有一个抽象的 Uuid 类,它有一个获取版本、时间戳字节、时钟序列字节和节点字节的构造函数。由于 RFC 确定了它们的大小,我编写了一些测试:
[Test]
public void Expects8TimestampBytes()
{
// given an invalid count of timestamp bytes
var timestampBytes = new List<byte>
{
0x00,
};
// when trying to create an Uuid from it
TestDelegate instanciation = () => ConcreteUuid.Constructor2(timestamp: timestampBytes);
// then an exception should be thrown
Assert.That(instanciation, Throws.ArgumentException);
}
测试为绿色,抛出异常:
protected Uuid(int version, List<byte> timestamp, List<byte> clockSequence, List<byte> node)
{
if (timestamp.Count != 8)
{
throw new ArgumentException($"Timestamp bytes count must be 8, got {timestamp.Count}");
}
// more code ...
}
使用 NUnit 进行的测试报告一切都很好,但使用 Stryker 的突变仍然存在,并且条件显示为红色,而 clockSequence.Count 和 node.Count 上的突变为绿色。
问题似乎来自值 8,可能是因为分配的项目(这没有意义,因为 .Count 与 .Capacity 无关),TrimExcess() 没有解决问题。杀死突变的方法是将timestampBytes设置为9+的列表,小于8会使突变存活,我不明白为什么节点和时钟序列的突变被杀死的大小小于8(尝试重新排序条件)。
数字 8 有什么特别之处吗?
解决方案
推荐阅读
- r - 检查 R 中按两列分组的变量的重叠
- protractor - 有没有办法在动态数据(不断变化)上运行 BDD(自动化测试),而且以前的数据每 2 周都会被清除一次?
- java - 了解 Java 9+ 上的部署
- c# - 如何创建类类型对象的数组?
- php - 将不同结构的数组合并为一个,无需重新排列键或值
- html - 我们如何让 pandoc 从 markdown 生成漂亮的、人类可读的 HTML?
- symfony - Symmfony & Sonata:如何从 AbstractAdmin 扩展访问 EntityManagerInterface?
- json - Firebase 在创建用户后使用自定义字段更新用户数据
- r - 找到条件 = T 时,我需要 R 开始过滤行
- c# - 在 C# 中使用 Deedle 进行成对匹配和窗口化