@ -1,10 +1,12 @@
package com.sothr.imagetools.hash
import java.io.File
import java.util.NoSuchElementException
import javax.imageio.ImageIO
import com.sothr.imagetools.hash. `type` . DHash
import com.sothr.imagetools.hash.dto. { HashSettingDTO , ImageHashDTO }
import com.sothr.imagetools.hash.HashService.getHash
import com.sothr.imagetools.hash. `type` . { AHash , DHash , PHash }
import com.sothr.imagetools.hash.util.ImageUtil
import scala.collection.mutable
@ -13,453 +15,127 @@ import scala.collection.mutable
*
* Created by dev on 1 / 23 / 14.
*/
class HashServiceTest extends BaseTest {
// Define the number of runs the benchmarking tests should use
val benchmarkRuns = 10
val ahashSetting = new HashSettingDTO ( true , 8 , 8 , 0.75f )
val dhashSetting = new HashSettingDTO ( true , 8 , 8 , 0.85f )
val phashSetting = new HashSettingDTO ( true , 32 , 8 , 1.0f )
def dhashTestCase ( filePath : String ) : Long = {
val sample = new File ( filePath )
val image = ImageIO . read ( sample )
HashService . getDhash ( dhashSetting , image )
}
test ( "Benchmark DHash" ) {
info ( "Benchmarking DHash" )
info ( "DHash Large Image 3684x2736" )
val time = new mutable . MutableList [ Long ] ( )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
dhashTestCase ( TestParams . LargeSampleImage1 )
}
}
val largeMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for large was: $largeMean ms " )
time . clear ( )
info ( "DHash Medium Image 1824x1368" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
dhashTestCase ( TestParams . MediumSampleImage1 )
}
}
val mediumMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for medium was: $mediumMean ms " )
time . clear ( )
info ( "DHash Small Image 912x684" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
dhashTestCase ( TestParams . SmallSampleImage1 )
}
}
val smallMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for small was: $smallMean ms " )
time . clear ( )
assert ( true )
}
test ( "Confirm Largest DHash Output " ) {
val testData : Array [ Array [ Int ] ] = Array (
Array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ) ,
Array ( 16 , 15 , 14 , 13 , 12 , 11 , 10 , 9 ) ,
Array ( 17 , 18 , 19 , 20 , 21 , 22 , 23 , 24 ) ,
Array ( 32 , 31 , 30 , 29 , 28 , 27 , 26 , 25 ) ,
Array ( 33 , 34 , 35 , 36 , 37 , 38 , 39 , 40 ) ,
Array ( 48 , 47 , 46 , 45 , 44 , 43 , 42 , 41 ) ,
Array ( 49 , 50 , 51 , 52 , 53 , 54 , 55 , 56 ) ,
Array ( 64 , 63 , 62 , 61 , 60 , 59 , 58 , 57 ) )
val hash = DHash . getHash ( testData )
debug ( s" Hash of test array: $hash " )
assert ( hash == Long . MaxValue )
}
test ( "Calculate DHash Large Sample Image 1" ) {
debug ( "Starting 'Calculate DHash Large Sample Image 1' test" )
val sample = new File ( TestParams . LargeSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getDhash ( dhashSetting , image )
debug ( s" Testing that $hash = 4004374827879799635L " )
assert ( hash == 4004374827879799635L )
}
test ( "Calculate DHash Medium Sample Image 1" ) {
debug ( "Starting 'Calculate DHash Medium Sample Image 1' test" )
val sample = new File ( TestParams . MediumSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getDhash ( dhashSetting , image )
debug ( s" Testing that $hash = 4004374827879799635L " )
assert ( hash == 4004374827879799635L )
}
test ( "Calculate DHash Small Sample Image 1" ) {
debug ( "Starting 'Calculate DHash Small Sample Image 1' test" )
val sample = new File ( TestParams . SmallSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getDhash ( dhashSetting , image )
debug ( s" Testing that $hash = 4004383623972821843L " )
assert ( hash == 4004383623972821843L )
}
test ( "DHash Of Large, Medium, And Small Sample 1 Must Be Similar" ) {
val largeHash = dhashTestCase ( TestParams . LargeSampleImage1 )
val mediumHash = dhashTestCase ( TestParams . MediumSampleImage1 )
val smallHash = dhashTestCase ( TestParams . SmallSampleImage1 )
assert ( HashService . areHashSimilar ( dhashSetting , largeHash , mediumHash ) )
assert ( HashService . areHashSimilar ( dhashSetting , largeHash , smallHash ) )
assert ( HashService . areHashSimilar ( dhashSetting , mediumHash , smallHash ) )
}
def ahashTestCase ( filePath : String ) : Long = {
val sample = new File ( filePath )
val image = ImageIO . read ( sample )
HashService . getAhash ( ahashSetting , image )
}
test ( "Benchmark AHash" ) {
info ( "Benchmarking AHash" )
info ( "AHash Large Image 3684x2736" )
val time = new mutable . MutableList [ Long ] ( )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
ahashTestCase ( TestParams . LargeSampleImage1 )
}
}
val largeMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for large was: $largeMean ms " )
time . clear ( )
info ( "AHash Medium Image 1824x1368" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
ahashTestCase ( TestParams . MediumSampleImage1 )
}
}
val mediumMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for medium was: $mediumMean ms " )
time . clear ( )
info ( "AHash Small Image 912x684" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
ahashTestCase ( TestParams . SmallSampleImage1 )
}
}
val smallMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for small was: $smallMean ms " )
time . clear ( )
assert ( true )
}
test ( "Calculate AHash Large Sample Image 1" ) {
debug ( "Starting 'Calculate AHash Large Sample Image 1' test" )
val sample = new File ( TestParams . LargeSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getAhash ( ahashSetting , image )
debug ( s" Testing that $hash = 36070299219713907L " )
assert ( hash == 36070299219713907L )
}
test ( "Calculate AHash Medium Sample Image 1" ) {
debug ( "Starting 'Calculate AHash Medium Sample Image 1' test" )
val sample = new File ( TestParams . MediumSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getAhash ( ahashSetting , image )
debug ( s" Testing that $hash = 36070299219713907L " )
assert ( hash == 36070299219713907L )
}
test ( "Calculate AHash Small Sample Image 1" ) {
debug ( "Starting 'Calculate AHash Small Sample Image 1' test" )
val sample = new File ( TestParams . SmallSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getAhash ( ahashSetting , image )
debug ( s" Testing that $hash = 36070299219713907L " )
assert ( hash == 36070299219713907L )
}
test ( "AHash Of Large, Medium, And Small Sample 1 Must Be Similar" ) {
val largeHash = ahashTestCase ( TestParams . LargeSampleImage1 )
val mediumHash = ahashTestCase ( TestParams . MediumSampleImage1 )
val smallHash = ahashTestCase ( TestParams . SmallSampleImage1 )
assert ( HashService . areHashSimilar ( ahashSetting , largeHash , mediumHash ) )
assert ( HashService . areHashSimilar ( ahashSetting , largeHash , smallHash ) )
assert ( HashService . areHashSimilar ( ahashSetting , mediumHash , smallHash ) )
}
def phashTestCase ( filePath : String ) : Long = {
val sample = new File ( filePath )
val image = ImageIO . read ( sample )
HashService . getPhash ( phashSetting , image )
}
test ( "Benchmark PHash" ) {
info ( "Benchmarking PHash" )
info ( "PHash Large Image 3684x2736" )
val time = new mutable . MutableList [ Long ] ( )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
phashTestCase ( TestParams . LargeSampleImage1 )
}
}
val largeMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for large was: $largeMean ms " )
time . clear ( )
info ( "PHash Medium Image 1824x1368" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
phashTestCase ( TestParams . MediumSampleImage1 )
}
}
val mediumMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for medium was: $mediumMean ms " )
time . clear ( )
info ( "PHash Small Image 912x684" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
phashTestCase ( TestParams . SmallSampleImage1 )
}
}
val smallMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for small was: $smallMean ms " )
time . clear ( )
assert ( true )
}
test ( "Calculate PHash Large Sample Image 1" ) {
debug ( "Starting 'Calculate PHash Large Sample Image 1' test" )
val sample = new File ( TestParams . LargeSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getPhash ( phashSetting , image )
debug ( s" Testing that $hash = -9154554603604154117L " )
assert ( hash == - 9154554603604154117L )
}
test ( "Calculate PHash Medium Sample Image 1" ) {
debug ( "Starting 'Calculate PHash Medium Sample Image 1' test" )
val sample = new File ( TestParams . MediumSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getPhash ( phashSetting , image )
debug ( s" Testing that $hash = -9154589787976242949L " )
assert ( hash == - 9154589787976242949L )
}
test ( "Calculate PHash Small Sample Image 1" ) {
debug ( "Starting 'Calculate PHash Small Sample Image 1' test" )
val sample = new File ( TestParams . SmallSampleImage1 )
debug ( s" Testing File: ${ sample . getAbsolutePath } exists: ${ sample . exists } " )
val image = ImageIO . read ( sample )
debug ( s" Image: width: ${ image . getWidth } height: ${ image . getHeight } " )
val hash = HashService . getPhash ( phashSetting , image )
debug ( s" Testing that $hash = -9154589787976242949L " )
assert ( hash == - 9154589787976242949L )
}
test ( "PHash Of Large, Medium, And Small Sample 1 Must Be Similar" ) {
val largeHash = phashTestCase ( TestParams . LargeSampleImage1 )
val mediumHash = phashTestCase ( TestParams . MediumSampleImage1 )
val smallHash = phashTestCase ( TestParams . SmallSampleImage1 )
assert ( HashService . areHashSimilar ( phashSetting , largeHash , mediumHash ) )
assert ( HashService . areHashSimilar ( phashSetting , largeHash , smallHash ) )
assert ( HashService . areHashSimilar ( phashSetting , mediumHash , smallHash ) )
}
def md5TestCase ( filePath : String ) : String = {
HashService . getMD5 ( filePath )
}
test ( "Benchmark MD5" ) {
info ( "Benchmarking MD5" )
info ( "MD5 Large Image 3684x2736" )
val time = new mutable . MutableList [ Long ] ( )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
md5TestCase ( TestParams . LargeSampleImage1 )
}
}
val largeMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for large was: $largeMean ms " )
time . clear ( )
info ( "MD5 Medium Image 1824x1368" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
md5TestCase ( TestParams . MediumSampleImage1 )
}
}
val mediumMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for medium was: $mediumMean ms " )
time . clear ( )
info ( "MD5 Small Image 912x684" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
md5TestCase ( TestParams . SmallSampleImage1 )
}
}
val smallMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for small was: $smallMean ms " )
time . clear ( )
assert ( true )
}
test ( "Calculate MD5 Large Sample Image 1" ) {
debug ( "Starting 'Calculate MD5 Large Sample Image 1' test" )
val hash = HashService . getMD5 ( TestParams . LargeSampleImage1 )
debug ( s" Testing that $hash = 3fbccfd5faf3f991435b827ee5961862 " )
assert ( hash == "3fbccfd5faf3f991435b827ee5961862" )
}
test ( "Calculate MD5 Medium Sample Image 1" ) {
debug ( "Starting 'Calculate MD5 Medium Sample Image 1' test" )
val hash = HashService . getMD5 ( TestParams . MediumSampleImage1 )
debug ( s" Testing that $hash = a95e2cc4610307eb957e9c812429c53e " )
assert ( hash == "a95e2cc4610307eb957e9c812429c53e" )
}
test ( "Calculate MD5 Small Sample Image 1" ) {
debug ( "Starting 'Calculate MD5 Small Sample Image 1' test" )
val hash = HashService . getMD5 ( TestParams . SmallSampleImage1 )
debug ( s" Testing that $hash = b137131bd55896c747286e4d247b845e " )
assert ( hash == "b137131bd55896c747286e4d247b845e" )
}
def sha1TestCase ( filePath : String ) : String = {
HashService . getSHA1 ( filePath )
}
test ( "Benchmark SHA1" ) {
info ( "Benchmarking SHA1" )
info ( "SHA1 Large Image 3684x2736" )
val time = new mutable . MutableList [ Long ] ( )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
sha1TestCase ( TestParams . LargeSampleImage1 )
}
}
val largeMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for large was: $largeMean ms " )
time . clear ( )
info ( "SHA1 Medium Image 1824x1368" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
sha1TestCase ( TestParams . MediumSampleImage1 )
}
}
val mediumMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for medium was: $mediumMean ms " )
time . clear ( )
info ( "SHA1 Small Image 912x684" )
for ( _ <- 0 until benchmarkRuns ) {
time += getTime {
sha1TestCase ( TestParams . SmallSampleImage1 )
}
}
val smallMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for small was: $smallMean ms " )
time . clear ( )
assert ( true )
}
test ( "Calculate SHA1 Large Sample Image 1" ) {
debug ( "Starting 'Calculate SHA1 Large Sample Image 1' test" )
val hash = HashService . getSHA1 ( TestParams . LargeSampleImage1 )
debug ( s" Testing that $hash = 4beb6f2d852b75a313863916a1803ebad13a3196 " )
assert ( hash == "4beb6f2d852b75a313863916a1803ebad13a3196" )
}
test ( "Calculate SHA1 Medium Sample Image 1" ) {
debug ( "Starting 'Calculate SHA1 Medium Sample Image 1' test" )
val hash = HashService . getSHA1 ( TestParams . MediumSampleImage1 )
debug ( s" Testing that $hash = edc718ce8e3556a39592ffdc214d0f636529be9f " )
assert ( hash == "edc718ce8e3556a39592ffdc214d0f636529be9f" )
}
test ( "Calculate SHA1 Small Sample Image 1" ) {
debug ( "Starting 'Calculate SHA1 Small Sample Image 1' test" )
val hash = HashService . getSHA1 ( TestParams . SmallSampleImage1 )
debug ( s" Testing that $hash = 1a91d2b5327f0aad258419f76b87d4c0bc343443 " )
assert ( hash == "1a91d2b5327f0aad258419f76b87d4c0bc343443" )
}
def imageHashTestCase ( filePath : String ) : ImageHashDTO = {
HashService . getImageHashes ( ahashSetting , dhashSetting , phashSetting , filePath )
}
test ( "Benchmark getImageHashes" ) {
info ( "Benchmarking getImageHashes" )
info ( "getImageHashes Large Image 3684x2736" )
val time = new mutable . MutableList [ Long ] ( )
for ( runNum <- 0 until benchmarkRuns ) {
time += getTime {
imageHashTestCase ( TestParams . LargeSampleImage1 )
}
}
val largeMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for large was: $largeMean ms " )
time . clear ( )
info ( "getImageHashes Medium Image 1824x1368" )
for ( runNum <- 0 until benchmarkRuns ) {
time += getTime {
imageHashTestCase ( TestParams . MediumSampleImage1 )
}
}
val mediumMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for medium was: $mediumMean ms " )
time . clear ( )
info ( "getImageHashes Small Image 912x684" )
for ( runNum <- 0 until benchmarkRuns ) {
time += getTime {
imageHashTestCase ( TestParams . SmallSampleImage1 )
}
}
val smallMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for small was: $smallMean ms " )
time . clear ( )
assert ( true )
}
test ( "ImageHash Of Large, Medium, And Small Sample 1 Must Be Similar" ) {
val largeHash = imageHashTestCase ( TestParams . LargeSampleImage1 )
val mediumHash = imageHashTestCase ( TestParams . MediumSampleImage1 )
val smallHash = imageHashTestCase ( TestParams . SmallSampleImage1 )
assert ( HashService . areImageHashesSimilar ( ahashSetting , dhashSetting , phashSetting , largeHash , mediumHash ) )
assert ( HashService . areImageHashesSimilar ( ahashSetting , dhashSetting , phashSetting , largeHash , smallHash ) )
assert ( HashService . areImageHashesSimilar ( ahashSetting , dhashSetting , phashSetting , mediumHash , smallHash ) )
}
test ( "Calculate ImageHash Large Sample Image 1" ) {
debug ( "Starting 'Calculate ImageHash Large Sample Image 1' test" )
val hash = HashService . getImageHashes ( ahashSetting , dhashSetting , phashSetting , TestParams . LargeSampleImage1 )
debug ( s" Testing that ${ hash . hashCode ( ) } = -812844858 " )
assert ( hash . hashCode == - 812844858 )
}
test ( "Calculate ImageHash Medium Sample Image 1" ) {
debug ( "Starting 'Calculate ImageHash Medium Sample Image 1' test" )
val hash = HashService . getImageHashes ( ahashSetting , dhashSetting , phashSetting , TestParams . MediumSampleImage1 )
debug ( s" Testing that ${ hash . hashCode ( ) } = -812836666 " )
assert ( hash . hashCode == - 812836666 )
}
test ( "Calculate ImageHash Small Sample Image 1" ) {
debug ( "Starting 'Calculate ImageHash Small Sample Image 1' test" )
val hash = HashService . getImageHashes ( ahashSetting , dhashSetting , phashSetting , TestParams . SmallSampleImage1 )
debug ( s" Testing that ${ hash . hashCode ( ) } = -812840762 " )
assert ( hash . hashCode == - 812840762 )
}
}
class HashServiceTest extends HashServiceBaseTest {
def imageHashTestCase ( filePath : String ) : ImageHash = {
HashService . getImageHashes ( ahashSetting , dhashSetting , phashSetting , filePath )
}
test ( "ImageHash Of Large, Medium, And Small Sample 1 Must Be Similar" ) {
val largeHash = imageHashTestCase ( LargeSampleImage1 )
val mediumHash = imageHashTestCase ( MediumSampleImage1 )
val smallHash = imageHashTestCase ( SmallSampleImage1 )
assert ( HashService . areImageHashesSimilar ( ahashSetting , dhashSetting , phashSetting , largeHash , mediumHash ) )
assert ( HashService . areImageHashesSimilar ( ahashSetting , dhashSetting , phashSetting , largeHash , smallHash ) )
assert ( HashService . areImageHashesSimilar ( ahashSetting , dhashSetting , phashSetting , mediumHash , smallHash ) )
}
test ( "Calculate ImageHash Large Sample Image 1" ) {
debug ( "Starting 'Calculate ImageHash Large Sample Image 1' test" )
val hash = HashService . getImageHashes ( ahashSetting , dhashSetting , phashSetting , LargeSampleImage1 )
debug ( s" Testing that ${ hash . hashCode ( ) } = -812844858 " )
assert ( hash . hashCode == - 812844858 )
}
test ( "Calculate ImageHash Medium Sample Image 1" ) {
debug ( "Starting 'Calculate ImageHash Medium Sample Image 1' test" )
val hash = HashService . getImageHashes ( ahashSetting , dhashSetting , phashSetting , MediumSampleImage1 )
debug ( s" Testing that ${ hash . hashCode ( ) } = -812836666 " )
assert ( hash . hashCode == - 812836666 )
}
test ( "Calculate ImageHash Small Sample Image 1" ) {
debug ( "Starting 'Calculate ImageHash Small Sample Image 1' test" )
val hash = HashService . getImageHashes ( ahashSetting , dhashSetting , phashSetting , SmallSampleImage1 )
debug ( s" Testing that ${ hash . hashCode ( ) } = -812840762 " )
assert ( hash . hashCode == - 812840762 )
}
test ( "Benchmark getImageHashes" ) {
info ( "Benchmarking getImageHashes" )
info ( "getImageHashes Large Image 3684x2736" )
val time = new mutable . MutableList [ Long ] ( )
for ( runNum <- 0 until benchmarkRuns ) {
time += getTime {
imageHashTestCase ( LargeSampleImage1 )
}
}
val largeMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for large was: $largeMean ms " )
time . clear ( )
info ( "getImageHashes Medium Image 1824x1368" )
for ( runNum <- 0 until benchmarkRuns ) {
time += getTime {
imageHashTestCase ( MediumSampleImage1 )
}
}
val mediumMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for medium was: $mediumMean ms " )
time . clear ( )
info ( "getImageHashes Small Image 912x684" )
for ( runNum <- 0 until benchmarkRuns ) {
time += getTime {
imageHashTestCase ( SmallSampleImage1 )
}
}
val smallMean = getMean ( time . toArray [ Long ] )
info ( s" The mean time of ${ time . size } tests for small was: $smallMean ms " )
time . clear ( )
assert ( true )
}
test ( "GetPrecisionSet - Empty Precision Set" ) {
val emptyPrecisionSet = HashService . getPrecisionSet (
new HashSetting ( "Test1" , false , 8 , 0 , 0 ) ,
new HashSetting ( "Test2" , false , 16 , 0 , 0 ) ,
new HashSetting ( "Test3" , false , 32 , 0 , 0 ) )
assert ( emptyPrecisionSet . isEmpty )
}
test ( "GetPrecisionSet - Overlapping Precision Set" ) {
val precisionSet = HashService . getPrecisionSet (
new HashSetting ( "Test1" , true , 8 , 0 , 0 ) ,
new HashSetting ( "Test2" , true , 8 , 0 , 0 ) ,
new HashSetting ( "Test3" , true , 16 , 0 , 0 ) )
assert ( precisionSet . nonEmpty )
assert ( 2 == precisionSet . size )
}
test ( "GetPrecisionMap - Empty Precision Set" ) {
val emptyPrecisionSet = HashService . getPrecisionSet (
new HashSetting ( "Test1" , false , 8 , 0 , 0 ) ,
new HashSetting ( "Test2" , false , 16 , 0 , 0 ) ,
new HashSetting ( "Test3" , false , 32 , 0 , 0 ) )
val grayImage = ImageUtil . convertToGray ( ImageIO . read ( new File ( SmallSampleImage1 ) ) )
val emptyPrecisionMap = HashService . getPrecisionMap ( emptyPrecisionSet , grayImage )
assert ( emptyPrecisionMap . isEmpty )
}
test ( "GetPrecisionMap - Overlapping Precision Set" ) {
val precisionSet = HashService . getPrecisionSet (
new HashSetting ( "Test1" , true , 8 , 0 , 0 ) ,
new HashSetting ( "Test2" , true , 8 , 0 , 0 ) ,
new HashSetting ( "Test3" , true , 16 , 0 , 0 ) )
val grayImage = ImageUtil . convertToGray ( ImageIO . read ( new File ( SmallSampleImage1 ) ) )
val precisionMap = HashService . getPrecisionMap ( precisionSet , grayImage )
assert ( precisionMap . nonEmpty )
assert ( precisionMap . size == 2 )
}
test ( "getHash - Empty Precision Set" ) {
val emptyPrecisionSet = HashService . getPrecisionSet (
new HashSetting ( "Test1" , false , 8 , 0 , 0 ) ,
new HashSetting ( "Test2" , false , 16 , 0 , 0 ) ,
new HashSetting ( "Test3" , false , 32 , 0 , 0 ) )
val grayImage = ImageUtil . convertToGray ( ImageIO . read ( new File ( SmallSampleImage1 ) ) )
val emptyPrecisionMap = HashService . getPrecisionMap ( emptyPrecisionSet , grayImage )
assertThrows [ NoSuchElementException ] {
val ahash : Long = getHash ( ahashSetting , emptyPrecisionMap ( ahashSetting . precision ) , AHash . getHash )
val dhash : Long = getHash ( dhashSetting , emptyPrecisionMap ( dhashSetting . precision ) , DHash . getHash )
val phash : Long = getHash ( phashSetting , emptyPrecisionMap ( phashSetting . precision ) , PHash . getHash )
}
}
}