コード例 #1
0
		public virtual void  TestEqualsHashcode()
		{
			Query query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
			query.SetBoost(1.0f);
			Query other = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
			other.SetBoost(1.0f);
			
			Assert.AreEqual(query, query, "query equals itself is true");
			Assert.AreEqual(query, other, "equivalent queries are equal");
			Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode must return same value when equals is true");
			
			other.SetBoost(2.0f);
			Assert.IsFalse(query.Equals(other), "Different boost queries are not equal");
			
			other = new RangeQuery(new Term("notcontent", "A"), new Term("notcontent", "C"), true);
			Assert.IsFalse(query.Equals(other), "Different fields are not equal");
			
			other = new RangeQuery(new Term("content", "X"), new Term("content", "C"), true);
			Assert.IsFalse(query.Equals(other), "Different lower terms are not equal");
			
			other = new RangeQuery(new Term("content", "A"), new Term("content", "Z"), true);
			Assert.IsFalse(query.Equals(other), "Different upper terms are not equal");
			
			query = new RangeQuery(null, new Term("content", "C"), true);
			other = new RangeQuery(null, new Term("content", "C"), true);
			Assert.AreEqual(query, other, "equivalent queries with null lowerterms are equal()");
			Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode must return same value when equals is true");
			
			query = new RangeQuery(new Term("content", "C"), null, true);
			other = new RangeQuery(new Term("content", "C"), null, true);
			Assert.AreEqual(query, other, "equivalent queries with null upperterms are equal()");
			Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode returns same value");
			
			query = new RangeQuery(null, new Term("content", "C"), true);
			other = new RangeQuery(new Term("content", "C"), null, true);
			Assert.IsFalse(query.Equals(other), "queries with different upper and lower terms are not equal");
			
			query = new RangeQuery(new Term("content", "A"), new Term("content", "C"), false);
			other = new RangeQuery(new Term("content", "A"), new Term("content", "C"), true);
			Assert.IsFalse(query.Equals(other), "queries with different inclusive are not equal");
		}