//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp.Tests.Common
{
using System;
using Xunit;
public class Fast2DArrayTests
{
private static readonly float[,] FloydSteinbergMatrix =
{
{ 0, 0, 7 },
{ 3, 5, 1 }
};
[Fact]
public void Fast2DArrayThrowsOnNullInitializer()
{
Assert.Throws(() =>
{
Fast2DArray fast = new Fast2DArray(null);
});
}
[Fact]
public void Fast2DArrayThrowsOnEmptyZeroWidth()
{
Assert.Throws(() =>
{
Fast2DArray fast = new Fast2DArray(0, 10);
});
}
[Fact]
public void Fast2DArrayThrowsOnEmptyZeroHeight()
{
Assert.Throws(() =>
{
Fast2DArray fast = new Fast2DArray(10, 0);
});
}
[Fact]
public void Fast2DArrayThrowsOnEmptyInitializer()
{
Assert.Throws(() =>
{
Fast2DArray fast = new Fast2DArray(new float[0, 0]);
});
}
[Fact]
public void Fast2DArrayReturnsCorrectDimensions()
{
Fast2DArray fast = new Fast2DArray(FloydSteinbergMatrix);
Assert.True(fast.Width == FloydSteinbergMatrix.GetLength(1));
Assert.True(fast.Height == FloydSteinbergMatrix.GetLength(0));
}
[Fact]
public void Fast2DArrayGetReturnsCorrectResults()
{
Fast2DArray fast = FloydSteinbergMatrix;
for (int row = 0; row < fast.Height; row++)
{
for (int column = 0; column < fast.Width; column++)
{
Assert.True(Math.Abs(fast[row, column] - FloydSteinbergMatrix[row, column]) < Constants.Epsilon);
}
}
}
[Fact]
public void Fast2DArrayGetSetReturnsCorrectResults()
{
Fast2DArray fast = new Fast2DArray(4, 4);
const float Val = 5F;
fast[3, 3] = Val;
Assert.True(Math.Abs(Val - fast[3, 3]) < Constants.Epsilon);
}
}
}