【发布时间】:2021-10-02 06:15:06
【问题描述】:
我正在尝试使用 Fluent Assertions 来测试置换生成算法。该算法生成一个List<int[]>,其中List 的顺序无关紧要,但每个int[] 的元素都可以。
[Fact]
public void Are_all_permutations_generated()
{
// Arrange
var expected = new List<int[]>
{
new[] { 1, 2, 3 },
new[] { 1, 3, 2 },
new[] { 2, 1, 3 },
new[] { 2, 3, 1 },
new[] { 3, 1, 2 },
new[] { 3, 2, 1 }
};
// Act
var result = new List<int[]>
{
new[] { 3, 2, 1 },
new[] { 1, 3, 2 },
new[] { 2, 3, 1 },
new[] { 2, 1, 3 },
new[] { 3, 1, 2 },
new[] { 1, 2, 3 }
};
// Assert
result.Should().BeEquivalentTo(expected);
}
如果我在上面的代码块中使用result.Should().BeEquivalentTo(expected),即使result 是,它也会通过
var result = new List<int[]>
{
new[] { 1, 2, 3 },
new[] { 1, 2, 3 },
new[] { 1, 2, 3 },
new[] { 1, 2, 3 },
new[] { 1, 2, 3 },
new[] { 1, 2, 3 }
};
我如何编写 Fluent Assertions 以允许列表的任何顺序,但对数组有严格的顺序,以便它可以断言所有排列都已找到?有没有办法在BeEquivalentTo 中写options 来做到这一点?
【问题讨论】:
标签: c# unit-testing fluent-assertions