Пример #1
0
        protected static IIntervalCollection <IInterval <int>, int> CreateIntervalCollection(
            Type implementation,
            TestFactoryHelper.DataSet dataset = null,
            int size = 0)
        {
            var data = dataset.IntervalsFactory(size);

            // We need some logic to deal with static interval trees since they do not have parameterless constructors.
            var hasParameterlessConstructor = implementation.Constructor(Type.EmptyTypes) != null;

            IIntervalCollection <IInterval <int>, int> dataStructure = null;

            if (hasParameterlessConstructor)
            {
                dataStructure = CreateIntervalCollectionInstance(implementation);
                if (data != null && size != 0)
                {
                    dataStructure.AddAll(data);
                }
            }
            else
            {
                dataStructure = CreateIntervalCollectionInstanceWithData(implementation, data);
            }

            return(dataStructure);
        }
Пример #2
0
        protected static string GetIdentifier(IIntervalCollection <IInterval <int>, int> intervals, Type implementation)
        {
            var dynamicOrStatic     = intervals.IsReadOnly ? "Static" : "Dynamic";
            var overlapOrNoOverlaps = intervals.AllowsOverlaps ? "Overlaps" : "NoOverlaps";
            var identifier          = string.Format("{0}:({1}-{2})", implementation.GetFriendlyName(), dynamicOrStatic,
                                                    overlapOrNoOverlaps);

            return(identifier);
        }
Пример #3
0
        protected override void PutMany(IIntervalCollection <int, string> collection, params string[] values)
        {
            var pairs = new List <KeyValuePair <Interval <int>, string> >(values.Length);

            foreach (var value in values)
            {
                var interval = Interval.Create(Interlocked.Increment(ref _lastId));
                pairs.Add(new KeyValuePair <Interval <int>, string>(interval, value));
            }
            collection.PutMany(pairs);
        }
Пример #4
0
        protected QueryRange CreateQueryRange(string name, IIntervalCollection <IInterval <int>, int> dataStructure)
        {
            var span = dataStructure.Span.High - dataStructure.Span.Low;

            switch (name)
            {
            case "FirstHalf":
                return(new QueryRange(name, new IntervalBase <int>(dataStructure.Span.Low, span / 2)));

            case "FirstTenth":
                return(new QueryRange(name, new IntervalBase <int>(dataStructure.Span.Low, span / 10)));

            case "MiddleTenth":
                return(new QueryRange(name, new IntervalBase <int>((span / 2) - span / 20, (span / 2) + span / 20)));

            case "LastTenth":
                return(new QueryRange(name,
                                      new IntervalBase <int>(dataStructure.Span.High - span / 10, dataStructure.Span.High)));
            }
            throw new ArgumentException("name");
        }
Пример #5
0
 /// <summary> Add another <see cref="IIntervalCollection"/> to this <see cref="IIntervalCollection"/> </summary>
 /// <param name="other">The other <see cref="IIntervalCollection"/></param>
 void IIntervalCollection.Add(IIntervalCollection other) => intervals.UnionWith(other);
Пример #6
0
 protected override void RemoveLastPutValue(IIntervalCollection <int, string> collection)
 {
     collection.Remove(_lastId);
 }
Пример #7
0
 protected override void Put(IIntervalCollection <int, string> collection, string value)
 {
     collection.Put(Interval.Create(Interlocked.Increment(ref _lastId)), value);
 }