2018-11-04 20:33:37 +00:00
|
|
|
using Roadie.Library.Imaging;
|
2018-11-04 15:16:52 +00:00
|
|
|
using System;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Roadie.Library.Tests
|
|
|
|
{
|
|
|
|
public class ImageHasherTests
|
|
|
|
{
|
|
|
|
[Fact]
|
2018-11-04 20:33:37 +00:00
|
|
|
public void Generate_Image_Hash()
|
2018-11-04 15:16:52 +00:00
|
|
|
{
|
2018-11-04 20:33:37 +00:00
|
|
|
var imageFilename = @"C:\temp\image_tests\1.jpg";
|
|
|
|
var secondImagFilename = @"C:\temp\image_tests\2.jpg";
|
|
|
|
var resizedFirstImageFilename = @"C:\temp\image_tests\1-resized.jpg";
|
|
|
|
var thirdImageFilename = @"C:\temp\image_tests\3.jpg";
|
2018-11-04 15:16:52 +00:00
|
|
|
|
2018-11-04 20:33:37 +00:00
|
|
|
var hash = ImageHasher.AverageHash(imageFilename);
|
|
|
|
Assert.True(hash > 0);
|
|
|
|
|
|
|
|
var secondHash = ImageHasher.AverageHash(imageFilename);
|
|
|
|
Assert.True(secondHash > 0);
|
|
|
|
Assert.Equal(hash, secondHash);
|
|
|
|
|
|
|
|
secondHash = ImageHasher.AverageHash(secondImagFilename);
|
|
|
|
Assert.True(secondHash > 0);
|
|
|
|
Assert.Equal(hash, secondHash);
|
|
|
|
|
|
|
|
var similiar = ImageHasher.Similarity(imageFilename, secondImagFilename);
|
|
|
|
Assert.Equal(100d, similiar);
|
|
|
|
|
|
|
|
Assert.True(ImageHasher.ImagesAreSame(imageFilename, secondImagFilename));
|
|
|
|
|
|
|
|
|
|
|
|
secondHash = ImageHasher.AverageHash(resizedFirstImageFilename);
|
|
|
|
Assert.True(secondHash > 0);
|
|
|
|
Assert.Equal(hash, secondHash);
|
|
|
|
|
|
|
|
Assert.False(ImageHasher.ImagesAreSame(imageFilename, thirdImageFilename));
|
2018-11-04 15:16:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|