Beispiel #1
0
        public void GetLastValueSmallerThanShouldBeFast()
        {
            int           amount = 1000000;
            List <double> values = new List <double>(amount);

            for (int i = 0; i < amount; i++)
            {
                values.Add(i);
            }

            var array = new MultiDimensionalArray();

            array.AddRange(values);

            TestHelper.AssertIsFasterThan(500, () =>
            {
                for (int i = 0; i < 100000; i++)
                {
                    FunctionHelper.GetLastValueSmallerThan(55555.0, array);
                }
            });
            //orig: 2100ms
        }
Beispiel #2
0
        public void MinAndMaxValue()
        {
            IMultiDimensionalArray array = new MultiDimensionalArray <int>();

            array.AddRange(new[] { 1, 2, 3 });
            Assert.AreEqual(1, array.MinValue);
            Assert.AreEqual(3, array.MaxValue);

            array = new MultiDimensionalArray <double>();
            array.AddRange(new[] { 1.0d, 2.0d, 3.0d });
            Assert.AreEqual(1.0d, array.MinValue);
            Assert.AreEqual(3.0d, array.MaxValue);

            array = new MultiDimensionalArray <float>();
            array.AddRange(new[] { 1.0f, 2.0f, 3.0f });
            Assert.AreEqual(1.0f, array.MinValue);
            Assert.AreEqual(3.0f, array.MaxValue);

            array       = new MultiDimensionalArray(2, 2);
            array[0, 0] = -2;
            array[0, 1] = 5;
            Assert.AreEqual(-2, array.MinValue);
            Assert.AreEqual(5, array.MaxValue);
        }
Beispiel #3
0
        public void GetLastValueSmallerThanShouldBeFast()
        {
            int amount = 1000000;
            List<double> values = new List<double>(amount);
            for (int i = 0; i < amount; i++)
                values.Add(i);

            var array = new MultiDimensionalArray();
            array.AddRange(values);

            TestHelper.AssertIsFasterThan(500, () =>
            {
                for (int i = 0; i < 100000; i++)
                    FunctionHelper.GetLastValueSmallerThan(55555.0, array);
            });
            //orig: 2100ms
        }
        public void MinAndMaxValue()
        {
            IMultiDimensionalArray array = new MultiDimensionalArray<int>();
            array.AddRange(new[] { 1, 2, 3 });
            Assert.AreEqual(1, array.MinValue);
            Assert.AreEqual(3, array.MaxValue);

            array = new MultiDimensionalArray<double>();
            array.AddRange(new[] { 1.0d, 2.0d, 3.0d });
            Assert.AreEqual(1.0d, array.MinValue);
            Assert.AreEqual(3.0d, array.MaxValue);

            array = new MultiDimensionalArray<float>();
            array.AddRange(new[] { 1.0f, 2.0f, 3.0f });
            Assert.AreEqual(1.0f, array.MinValue);
            Assert.AreEqual(3.0f, array.MaxValue);

            array = new MultiDimensionalArray(2, 2);
            array[0, 0] = -2;
            array[0, 1] = 5;
            Assert.AreEqual(-2, array.MinValue);
            Assert.AreEqual(5, array.MaxValue);
        }
        public void AddUnsortedRangeGivesException()
        {
            IMultiDimensionalArray<double> array = new MultiDimensionalArray<double>()
                                                       {IsAutoSorted = true};
            //not sorted..should throw
            array.AddRange(new[] {5.0, 2.0, 3.0});

        }
 public void AddRangeToSortedArrayThrowsExceptionIfRangeContainsValuesSmallerThenMaxValue()
 {
     IMultiDimensionalArray<double> array = new MultiDimensionalArray<double>(new[] {1.0, 2.0, 3.0}, new[] {3}){IsAutoSorted = true};
     array.AddRange(new[]{0.0,2.0,3.0});
 }
        public void PerformanceRemoveValues()
        {
            IMultiDimensionalArray<double> array = new MultiDimensionalArray<double>();

            const int valuesToRemove = 200000;
            var values = Enumerable.Range(1, valuesToRemove).Select(Convert.ToDouble).ToArray();
            array.AddRange(values);

            TestHelper.AssertIsFasterThan(95000, () => values.ForEach(d => array.Remove(d))); //too slow
        }
        public void PerformanceAddValues()
        {
            IMultiDimensionalArray<double> array = new MultiDimensionalArray<double>();

            const int valuesToAdd = 200000;
            var valuesToAddArray = Enumerable.Range(1, valuesToAdd).Select(Convert.ToDouble).ToArray();

            array.AddRange(valuesToAddArray); //warmup caches
            array.Clear();

            TestHelper.AssertIsFasterThan(110, () =>
                                              array.AddRange(valuesToAddArray));
        }