//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageSharp.Tests
{
using System.Linq;
using Xunit;
///
/// Tests the class.
///
public class PixelPoolTests
{
[Fact]
public void PixelPoolRentsMinimumSize()
{
Color[] pixels = PixelPool.RentPixels(1024);
Assert.True(pixels.Length >= 1024);
}
[Fact]
public void PixelPoolRentsEmptyArray()
{
for (int i = 16; i < 1024; i += 16)
{
Color[] pixels = PixelPool.RentPixels(i);
Assert.True(pixels.All(p => p == default(Color)));
PixelPool.ReturnPixels(pixels);
}
for (int i = 16; i < 1024; i += 16)
{
Color[] pixels = PixelPool.RentPixels(i);
Assert.True(pixels.All(p => p == default(Color)));
PixelPool.ReturnPixels(pixels);
}
}
[Fact]
public void PixelPoolDoesNotThrowWhenReturningNonPooled()
{
Color[] pixels = new Color[1024];
PixelPool.ReturnPixels(pixels);
Assert.True(pixels.Length >= 1024);
}
[Fact]
public void PixelPoolCleansRentedArray()
{
Color[] pixels = PixelPool.RentPixels(256);
for (int i = 0; i < pixels.Length; i++)
{
pixels[i] = Color.Azure;
}
Assert.True(pixels.All(p => p == Color.Azure));
PixelPool.ReturnPixels(pixels);
Assert.True(pixels.All(p => p == default(Color)));
}
}
}