假設我正在編寫一些視頻分析代碼。這裏是一個視頻類的簡化版本:C#中的FsCheck:生成具有相同形狀的二維數組的列表
public class Video
{
public readonly int Width;
public readonly int Height;
public readonly List<int[,]> Frames;
public Video(int width, int height, IEnumerable<int[,]> frames)
{
Width = width;
Height = height;
Frames = new List<int[,]>();
foreach (var frame in frames)
{
if (frame.GetLength(0) != height || frame.GetLength(1) != width)
{
throw new ArgumentException("Incorrect frames dimensions");
}
Frames.Add(frame);
}
}
}
如何使一個Arbitrary<Video>
並註冊了嗎?我如何爲這個任意做一個收縮器?
試過,不明白如何應用工程:
public static Arbitrary<Video> Videos()
{
var videoGen = Arb.Generate<PositiveInt>()
.SelectMany(w => Arb.Generate<PositiveInt>(), (w, h) => new {w, h})
.Apply(/* what is Gen<Func<a,b>> */);
return videoGen.ToArbitrary();
}
想這一點,但在這裏不能堵塞發電機清單:
public static Arbitrary<Video> Videos()
{
var videoGen = Arb.Generate<PositiveInt>()
.SelectMany(w => Arb.Generate<PositiveInt>(), (w, h) => new Video(w, h, /* how to plug generator here? */));
return videoGen.ToArbitrary();
}
我不知道鍵入的xUnit.net屬性,這是一個很好的選擇! –