|
@ -3,6 +3,9 @@ |
|
|
// Licensed under the MIT license<LICENSE-MIT or http://opensource.org/licenses/MIT>.
|
|
|
// Licensed under the MIT license<LICENSE-MIT or http://opensource.org/licenses/MIT>.
|
|
|
// This file may not be copied, modified, or distributed except according to those terms.
|
|
|
// This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mod hash;
|
|
|
|
|
|
|
|
|
pub fn hello(mut result: String) -> String {
|
|
|
pub fn hello(mut result: String) -> String {
|
|
|
let helloworld = "Hello, World!";
|
|
|
let helloworld = "Hello, World!";
|
|
|
result.push_str(helloworld);
|
|
|
result.push_str(helloworld);
|
|
@ -18,6 +21,7 @@ mod tests { |
|
|
use super::*;
|
|
|
use super::*;
|
|
|
use std::fs;
|
|
|
use std::fs;
|
|
|
use std::path;
|
|
|
use std::path;
|
|
|
|
|
|
use hash;
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
#[test]
|
|
|
fn can_get_test_images() {
|
|
|
fn can_get_test_images() {
|
|
@ -29,8 +33,8 @@ mod tests { |
|
|
match ext {
|
|
|
match ext {
|
|
|
Some(_) => {
|
|
|
Some(_) => {
|
|
|
if ext.unwrap() == "jpg" {
|
|
|
if ext.unwrap() == "jpg" {
|
|
|
println!("Is a image {}: {:?}", num_paths, orig_path) ;
|
|
|
|
|
|
num_paths += 1;
|
|
|
num_paths += 1;
|
|
|
|
|
|
println!("Is a image {}: {:?}", num_paths, orig_path) ;
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
_ => {
|
|
|
_ => {
|
|
@ -44,4 +48,63 @@ mod tests { |
|
|
assert!(num_paths == 12);
|
|
|
assert!(num_paths == 12);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Simple function for the unit tests to succinctly test a set of images
|
|
|
|
|
|
// that are organized in the fashion of large->medium->small
|
|
|
|
|
|
fn test_image_set_ahash(
|
|
|
|
|
|
large_path: &str,
|
|
|
|
|
|
medium_path: &str,
|
|
|
|
|
|
small_path: &str,
|
|
|
|
|
|
expected_large_hash: u64,
|
|
|
|
|
|
expected_medium_hash: u64,
|
|
|
|
|
|
expected_small_hash: u64,
|
|
|
|
|
|
expected_large_medium_hamming: u64,
|
|
|
|
|
|
expected_large_small_hamming: u64,
|
|
|
|
|
|
expected_medium_small_hamming: u64) {
|
|
|
|
|
|
|
|
|
|
|
|
let large_prepared_image = hash::prepare_image(path::Path::new(large_path));
|
|
|
|
|
|
let medium_prepared_image = hash::prepare_image(path::Path::new(medium_path));
|
|
|
|
|
|
let small_prepared_image = hash::prepare_image(path::Path::new(small_path));
|
|
|
|
|
|
|
|
|
|
|
|
let large_ahash = hash::get_ahash(large_prepared_image);
|
|
|
|
|
|
let medium_ahash = hash::get_ahash(medium_prepared_image);
|
|
|
|
|
|
let small_ahash = hash::get_ahash(small_prepared_image);
|
|
|
|
|
|
|
|
|
|
|
|
println!("./test_images/sample_01_large.jpg: {}", large_ahash);
|
|
|
|
|
|
println!("./test_images/sample_01_medium.jpg: {}", medium_ahash);
|
|
|
|
|
|
println!("./test_images/sample_01_small.jpg: {}", small_ahash);
|
|
|
|
|
|
|
|
|
|
|
|
assert!(large_ahash == expected_large_hash);
|
|
|
|
|
|
assert!(medium_ahash == expected_medium_hash);
|
|
|
|
|
|
assert!(small_ahash == expected_small_hash);
|
|
|
|
|
|
|
|
|
|
|
|
let large_medium_hamming = hash::calculate_hamming_distance(large_ahash, medium_ahash);
|
|
|
|
|
|
let large_small_hamming = hash::calculate_hamming_distance(large_ahash, small_ahash);
|
|
|
|
|
|
let medium_small_hamming = hash::calculate_hamming_distance(medium_ahash, small_ahash);
|
|
|
|
|
|
|
|
|
|
|
|
println!("Large-Medium Hamming Distance: {}", large_medium_hamming);
|
|
|
|
|
|
println!("Large-Small Hamming Distance: {}", large_small_hamming);
|
|
|
|
|
|
println!("Medium-Small Hamming Distance: {}", medium_small_hamming);
|
|
|
|
|
|
|
|
|
|
|
|
assert!(large_medium_hamming == expected_large_medium_hamming);
|
|
|
|
|
|
assert!(large_small_hamming == expected_large_small_hamming);
|
|
|
|
|
|
assert!(medium_small_hamming == expected_medium_small_hamming);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
|
fn confirm_ahash_results() {
|
|
|
|
|
|
// Sample_01 tests
|
|
|
|
|
|
test_image_set_ahash(
|
|
|
|
|
|
"./test_images/sample_01_large.jpg",
|
|
|
|
|
|
"./test_images/sample_01_medium.jpg",
|
|
|
|
|
|
"./test_images/sample_01_small.jpg",
|
|
|
|
|
|
18446744073709551615u64,
|
|
|
|
|
|
18446744073709551615u64,
|
|
|
|
|
|
9223372036854775807u64,
|
|
|
|
|
|
0u64,
|
|
|
|
|
|
1u64,
|
|
|
|
|
|
1u64
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|