コード例 #1
0
        public virtual void  TestEqualsHashcode()
        {
            Query query = new TermRangeQuery("content", "A", "C", true, true);

            query.SetBoost(1.0f);
            Query other = new TermRangeQuery("content", "A", "C", true, 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 TermRangeQuery("notcontent", "A", "C", true, true);
            Assert.IsFalse(query.Equals(other), "Different fields are not equal");

            other = new TermRangeQuery("content", "X", "C", true, true);
            Assert.IsFalse(query.Equals(other), "Different lower terms are not equal");

            other = new TermRangeQuery("content", "A", "Z", true, true);
            Assert.IsFalse(query.Equals(other), "Different upper terms are not equal");

            query = new TermRangeQuery("content", null, "C", true, true);
            other = new TermRangeQuery("content", null, "C", true, 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 TermRangeQuery("content", "C", null, true, true);
            other = new TermRangeQuery("content", "C", null, true, true);
            Assert.AreEqual(query, other, "equivalent queries with null upperterms are equal()");
            Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode returns same value");

            query = new TermRangeQuery("content", null, "C", true, true);
            other = new TermRangeQuery("content", "C", null, true, true);
            Assert.IsFalse(query.Equals(other), "queries with different upper and lower terms are not equal");

            query = new TermRangeQuery("content", "A", "C", false, false);
            other = new TermRangeQuery("content", "A", "C", true, true);
            Assert.IsFalse(query.Equals(other), "queries with different inclusive are not equal");

            query = new TermRangeQuery("content", "A", "C", false, false);
            other = new TermRangeQuery("content", "A", "C", false, false, System.Globalization.CultureInfo.CurrentCulture.CompareInfo);
            Assert.IsFalse(query.Equals(other), "a query with a collator is not equal to one without");
        }
コード例 #2
0
		public virtual void  TestEqualsHashcode()
		{
			Query query = new TermRangeQuery("content", "A", "C", true, true);
			
			query.SetBoost(1.0f);
			Query other = new TermRangeQuery("content", "A", "C", true, 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 TermRangeQuery("notcontent", "A", "C", true, true);
			Assert.IsFalse(query.Equals(other), "Different fields are not equal");
			
			other = new TermRangeQuery("content", "X", "C", true, true);
			Assert.IsFalse(query.Equals(other), "Different lower terms are not equal");
			
			other = new TermRangeQuery("content", "A", "Z", true, true);
			Assert.IsFalse(query.Equals(other), "Different upper terms are not equal");
			
			query = new TermRangeQuery("content", null, "C", true, true);
			other = new TermRangeQuery("content", null, "C", true, 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 TermRangeQuery("content", "C", null, true, true);
			other = new TermRangeQuery("content", "C", null, true, true);
			Assert.AreEqual(query, other, "equivalent queries with null upperterms are equal()");
			Assert.AreEqual(query.GetHashCode(), other.GetHashCode(), "hashcode returns same value");
			
			query = new TermRangeQuery("content", null, "C", true, true);
			other = new TermRangeQuery("content", "C", null, true, true);
			Assert.IsFalse(query.Equals(other), "queries with different upper and lower terms are not equal");
			
			query = new TermRangeQuery("content", "A", "C", false, false);
			other = new TermRangeQuery("content", "A", "C", true, true);
			Assert.IsFalse(query.Equals(other), "queries with different inclusive are not equal");
			
			query = new TermRangeQuery("content", "A", "C", false, false);
			other = new TermRangeQuery("content", "A", "C", false, false, System.Globalization.CultureInfo.CurrentCulture.CompareInfo);
			Assert.IsFalse(query.Equals(other), "a query with a collator is not equal to one without");
		}
コード例 #3
0
 /// <summary>Returns a hash code value for this object.</summary>
 public override int GetHashCode()
 {
     return(delegate_Renamed.GetHashCode());
 }