use crate::core::search::total_hits::Relation::{EqualTo, GreaterThanOrEqualTo};
use crate::core::search::total_hits::TotalHits;
use crate::core::util::CoreHelper;
use crate::test_framework::core::util::lucene_test_case::random;
use crate::test_framework::core::util::test_util::TestUtil;
use rand::Rng;
use rand::prelude::IndexedRandom;
#[allow(dead_code)] struct TestTotalHits;
#[test]
fn test_equals_and_hashcode() {
let mut random = random();
let total_hits1 = random_total_hits(&mut random);
assert_eq!(total_hits1, total_hits1);
assert_eq!(
CoreHelper::calculate_hash(&total_hits1),
CoreHelper::calculate_hash(&total_hits1)
);
let total_hits2 = TotalHits::new(total_hits1.value(), total_hits1.relation());
assert_eq!(total_hits1, total_hits2);
assert_eq!(total_hits2, total_hits1);
assert_eq!(
CoreHelper::calculate_hash(&total_hits1),
CoreHelper::calculate_hash(&total_hits2)
);
let total_hits4 = random_total_hits(&mut random);
if total_hits4.value() == total_hits1.value() && total_hits4.relation() == total_hits1.relation()
{
assert_eq!(total_hits1, total_hits4);
assert_eq!(total_hits2, total_hits4);
assert_eq!(
CoreHelper::calculate_hash(&total_hits1),
CoreHelper::calculate_hash(&total_hits4)
);
assert_eq!(
CoreHelper::calculate_hash(&total_hits2),
CoreHelper::calculate_hash(&total_hits4)
);
} else {
assert_ne!(total_hits1, total_hits4);
assert_ne!(total_hits2, total_hits4);
assert_ne!(
CoreHelper::calculate_hash(&total_hits1),
CoreHelper::calculate_hash(&total_hits4)
);
assert_ne!(
CoreHelper::calculate_hash(&total_hits2),
CoreHelper::calculate_hash(&total_hits4)
);
}
}
fn random_total_hits<R>(random: &mut R) -> TotalHits
where
R: Rng + ?Sized,
{
let value = TestUtil::next_usize(random, 0, i64::MAX as usize);
let relation = *[EqualTo, GreaterThanOrEqualTo].choose(random).unwrap();
TotalHits::new(value, relation)
}