Giả sử tôi đang viết một số mã để phân tích video. Đây là phiên bản đơn giản của lớp Video:FsCheck trong C#: tạo danh sách hai mảng thứ nguyên có cùng hình dạng
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);
}
}
}
Làm cách nào để tạo Arbitrary<Video>
và đăng ký? Làm thế nào để tôi làm cho một shrinker cho rằng tùy ý?
Cố gắng này, không thể hiểu cách áp dụng các công trình:
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();
}
Cố gắng này, nhưng không thể cắm máy phát điện cho danh sách ở đây:
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();
}
Tôi không biết thuộc tính xUnit.net đã nhập, đó là một lựa chọn tuyệt vời! –