public void ShouldCalculateEffectivenessWithNoInvertedIndex()
        {
            IDictionary   indexes       = new HashDictionary();
            BetweenFilter filter        = new BetweenFilter(m_extractor, 10, 20);
            var           effectiveness = filter.CalculateEffectiveness(indexes, s_setKeys);

            Assert.AreEqual(ExtractorFilter.EVAL_COST * s_setKeys.Count, effectiveness);
        }
        public void ShouldApplyIndexWhenUpperBoundIsNull()
        {
            IDictionary   indexes = new HashDictionary();
            ICollection   keys    = new HashSet(s_setKeys);
            BetweenFilter filter  = new BetweenFilter(m_extractor, 10, null);
            var           result  = filter.ApplyIndex(indexes, keys);

            Assert.IsNull(result);
            Assert.AreEqual(keys.Count, 0);
        }
        public void ShouldApplyIndexWhenNoMatchingIndexPresent()
        {
            IDictionary   indexes = new HashDictionary();
            ICollection   keys    = new HashSet(s_setKeys);
            BetweenFilter filter  = new BetweenFilter(m_extractor, 10, 20);
            var           result  = filter.ApplyIndex(indexes, keys);

            Assert.AreSame(filter, result);
            Assert.AreEqual(s_setKeys, keys);
        }
        public void ShouldCalculateEffectivenessWhenInvertedIndexIsPlainSet()
        {
            IDictionary indexes = new HashDictionary();

            indexes[m_extractor] = s_sortedIndex;

            BetweenFilter filter        = new BetweenFilter(m_extractor, 10, 20);
            var           effectiveness = filter.CalculateEffectiveness(indexes, s_setKeys);

            Assert.AreEqual(s_sortedIndex.IndexContents.Count, effectiveness);
        }
        public void ShouldApplyIndexWhenUnsortedIndexPresent()
        {
            IDictionary   indexes = new HashDictionary();
            ICollection   keys    = new HashSet(s_setKeys);
            BetweenFilter filter  = new BetweenFilter(m_extractor, 10, 20);

            indexes[m_extractor] = s_unsortedIndex;

            var result = filter.ApplyIndex(indexes, keys);

            Assert.IsNull(result);
            Assert.IsTrue(s_setKeysTenToTwenty.Equals(keys));
        }
        public void ShouldSerializeBetweenFilter()
        {
            BetweenFilter filter = new BetweenFilter(m_extractor, 10, 20, true, true);
            Stream        stream = new MemoryStream();

            m_serializer.Serialize(new DataWriter(stream), filter);
            stream.Position = 0;
            var result = m_serializer.Deserialize(new DataReader(stream));

            Assert.IsInstanceOf(typeof(BetweenFilter), result);
            BetweenFilter resultFilter = (BetweenFilter)result;

            Assert.AreEqual(resultFilter.ValueExtractor, filter.ValueExtractor);
            Assert.AreEqual(resultFilter.LowerBound, filter.LowerBound);
            Assert.AreEqual(resultFilter.UpperBound, filter.UpperBound);
            Assert.AreEqual(resultFilter.IsLowerBoundInclusive, filter.IsLowerBoundInclusive);
            Assert.AreEqual(resultFilter.IsUpperBoundInclusive, filter.IsUpperBoundInclusive);
        }
        public void ShouldEvaluateValueEqualToUpperBoundToFalseIfUpperBoundExclusive()
        {
            BetweenFilter filter = new BetweenFilter(m_extractor, 10, 20, true, false);

            Assert.IsFalse(filter.Evaluate(20));
        }
        public void ShouldEvaluateValueEqualToUpperBoundToTrue()
        {
            BetweenFilter filter = new BetweenFilter(m_extractor, 10, 20);

            Assert.IsTrue(filter.Evaluate(20));
        }
        public void ShouldEvaluateValueHigherThanRangeToFalse()
        {
            BetweenFilter filter = new BetweenFilter(m_extractor, 10, 20);

            Assert.IsFalse(filter.Evaluate(21));
        }
        public void ShouldForceLowerBoundExcludedIfLowerBoundIsNull()
        {
            BetweenFilter filter = new BetweenFilter(m_extractor, null, 20, true, true);

            Assert.IsFalse(filter.IsLowerBoundInclusive);
        }
        public void ShouldEvaluateAsFalseIfUpperBoundIsNull()
        {
            BetweenFilter filter = new BetweenFilter(m_extractor, 10, null, true, false);

            Assert.IsFalse(filter.Evaluate(12));
        }
        public void ShouldEvaluateNullAsFalse()
        {
            BetweenFilter filter = new BetweenFilter(m_extractor, 10, 20, true, false);

            Assert.IsFalse(filter.Evaluate(null));
        }