public void DontAddExisted()
        {
            var dim = new TableDimension <int>(1, 2);

            Assert.AreEqual(new AutoCreateIndexer <int>(dim).Touch(2), 2);
            CollectionAssert.AreEqual(new[] { 1, 2 }, dim.Values);
        }
        public void AddNonExisted()
        {
            var dim = new TableDimension <int>(1, 2);

            Assert.AreEqual(3, new AutoCreateIndexer <int>(dim).Touch(3));
            CollectionAssert.AreEqual(new[] { 1, 2, 3 }, dim.Values);
        }
        public static BinSearchReply BinSearch <T>(this TableDimension <T> dim, T element)
            where T : IComparable
        {
            if (dim.Values.Count == 0)
            {
                return new BinSearchReply {
                           ExactMatch = false, Index = 0
                }
            }
            ;
            var array = dim.Values;
            var left  = 0;
            var right = array.Count;

            while (left < right)
            {
                var middle = (right + left) / 2;

                if (element.CompareTo(array[middle]) <= 0)
                {
                    right = middle;
                }
                else
                {
                    left = middle + 1;
                }
            }
            var result = new BinSearchReply();

            result.ExactMatch = array.Count > right && array[right].CompareTo(element) == 0;
            result.Index      = right;
            return(result);
        }
    }
        public void NotAddWhenNotNesessary()
        {
            var dim = new TableDimension <int>(1, 3, 5, 7);
            var ind = new SortedAutoCreateIndexer <int>(dim);

            ind.Touch(3);
            CollectionAssert.AreEqual(new[] { 1, 3, 5, 7 }, dim.Values);
        }
        public void WorkWithOneElement2()
        {
            var dim   = new TableDimension <int>(1);
            var index = dim.BinSearch(2);

            Assert.AreEqual(1, index.Index);
            Assert.False(index.ExactMatch);
        }
        public void Works()
        {
            var dim   = new TableDimension <int>(1, 2, 3);
            var index = dim.BinSearch(2);

            Assert.AreEqual(1, index.Index);
            Assert.AreEqual(true, index.ExactMatch);
        }
        public void NotFindNonExisted()
        {
            var dim = new TableDimension <int>(1, 2);

            Assert.Throws(
                typeof(ArgumentException),
                () => new OnlyExistedIndexer <int>(dim).Touch(3));
        }
Exemple #8
0
        public void AddToRight()
        {
            var values = new int[] { 1, 2, 3 };
            var dim    = new TableDimension <int>(values);

            new SortedContinousIndexer <int>(dim, z => z + 1).Touch(5);
            CollectionAssert.AreEqual(new[] { 1, 2, 3, 4, 5 }, dim.Values);
        }
Exemple #9
0
        public void NotModifyIfValueExists()
        {
            var values = new int[] { 1, 2, 3 };
            var dim    = new TableDimension <int>(values);

            new SortedContinousIndexer <int>(dim, z => z + 1).Touch(2);
            CollectionAssert.AreEqual(values, dim.Values);
        }
Exemple #10
0
        public void NotAddToMiddle()
        {
            var values = new int[] { 1, 3 };
            var dim    = new TableDimension <int>(values);

            Assert.Throws(
                typeof(ArgumentException),
                () => new SortedContinousIndexer <int>(dim, z => z + 2).Touch(2));
        }
        public void WorkInNonExactSituations()
        {
            var dim   = new TableDimension <int>(1, 3, 5, 7);
            var index = dim.BinSearch(6);

            Assert.AreEqual(3, index.Index);
            Assert.AreEqual(false, index.ExactMatch);
            dim.Insert(6, index.Index);
            CollectionAssert.AreEqual(new[] { 1, 3, 5, 6, 7 }, dim.Values);
        }
Exemple #12
0
 public SortedContinousIndexer(TableDimension <T> dim, Func <T, T> getNext)
 {
     this.dim     = dim;
     this.getNext = getNext;
 }
        public void TouchExisted()
        {
            var dim = new TableDimension <string>("A", "B", "C");

            Assert.AreEqual("B", new IntIndexer <string>(dim).Touch(1));
        }
        public void DontTouchNegative()
        {
            var dim = new TableDimension <int>(0, 1, 2, 3);

            Assert.Throws(typeof(ArgumentException), () => new IntIndexer <int>(dim).Touch(-5));
        }
        public void FindExisted()
        {
            var dim = new TableDimension <int>(1, 2);

            Assert.AreEqual(2, new OnlyExistedIndexer <int>(dim).Touch(2));
        }
 public OnlyExistedIndexer(TableDimension <T> dim)
 {
     this.dim = dim;
 }
Exemple #17
0
 public IntIndexer(TableDimension <T> dim)
 {
     this.dim = dim;
 }
 public SortedAutoCreateIndexer(TableDimension <T> dim)
 {
     this.dim = dim;
 }
Exemple #19
0
 public DimensionIndexerFactory(TableDimension <T> dim)
 {
     this.dim = dim;
 }