Example #1
0
        public IEnumerable <TraceHeader> ReadTraceHeaders(long startTraceIndex, long traceCount)
        {
            if (startTraceIndex > TraceCount)
            {
                throw new ArgumentException($"Cannot read a trace header with trace index: {startTraceIndex}, when file only contains {TraceCount} traces");
            }
            var streamLen = binaryReader.BaseStream.Length;

            int traceDataBytesSz   = BinaryFileHeader.SamplesPerTraceOfFile * dataSampleSize;
            var dataStartIndex     = TextHeaderBytesCount + BinaryHeaderBytesCount + TextHeaderBytesCount * (TextHeaders.Count() - 1);
            var initStreamPosition = dataStartIndex + (240 + BinaryFileHeader.SamplesPerTraceOfFile * dataSampleSize) * startTraceIndex;

            binaryReader.BaseStream.Seek(initStreamPosition, SeekOrigin.Begin);
            var streamPosition = initStreamPosition;

            BigArray <TraceHeader> traceHeaders = new BigArray <TraceHeader>(traceCount);

            for (long tid = 0; tid < traceCount && (streamPosition < streamLen); tid++)
            {
                var traceHeaderByteArr = binaryReader.ReadBytes(TraceHeaderBytesCount);
                var trHeader           = TraceHeader.From(traceHeaderByteArr, BitConverter);
                binaryReader.BaseStream.Seek(traceDataBytesSz, SeekOrigin.Current);
                streamPosition   += 240 + traceDataBytesSz;
                traceHeaders[tid] = trHeader;
            }
            return(traceHeaders);
        }
 private void ResolveSortedSet()
 {
     if (sortedSet == null)
     {
         sortedSet = index.SelectAll().ToBigArray();
     }
 }
Example #3
0
        static void StopwatchEstimation()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            //Write some test code here

            BigArray <int> array = new BigArray <int>();

            for (int i = 0; i < 64 * 1024; i++)
            {
                array.Add(i);
            }

            for (int i = 0; i < 100; i++)
            {
                for (int j = 0; j < 64 * 1024; j++)
                {
                    var a = array[j];
                }
            }

            Console.WriteLine(stopwatch.ElapsedMilliseconds);
        }
Example #4
0
        public void GetDefaultOnEmptyArray()
        {
            BigArray<int> array = new BigArray<int>(10);

            for (int k = 0; k < 20; k++)
                Assert.AreEqual(0, array[(ulong)k]);
        }
Example #5
0
        public void TestGetEnumerator()
        {
            BigArray <int> bigArray = new BigArray <int>(10);

            bigArray[0] = 1;
            bigArray[1] = 2;
            bigArray[2] = 1;
            bigArray[3] = 3;
            bigArray[4] = 4;
            bigArray[5] = 5;
            bigArray[6] = 1;
            bigArray[7] = 6;
            bigArray[8] = 7;
            bigArray[9] = 8;

            int index = 0;

            foreach (int val in bigArray)
            {
                if (bigArray[index++] != val)
                {
                    Assert.Fail();
                }
            }
        }
Example #6
0
        public static void RemoveLast()
        {
            var distributedArray = new BigArray <int>();
            int size             = 4 * MaxBlockSize;

            var checkList = new List <int>(size);

            //Add
            for (int i = 0; i < size; i++)
            {
                distributedArray.Add(i);
                checkList.Add(i);
            }

            //Remove
            for (int i = 0; i < size; i++)
            {
                distributedArray.RemoveLast();
                checkList.RemoveAt(checkList.Count - 1);

                Assert.AreEqual(distributedArray.Count, checkList.Count);
            }

            CheckEqual(distributedArray, checkList);
        }
Example #7
0
        public static void Reverse()
        {
            var distributedArray = new BigArray <int>();

            for (int i = 0; i < MaxBlockSize * 2; i++)
            {
                distributedArray.Add(i);
            }
            distributedArray.Reverse();

            //Check
            int count = distributedArray.Count;

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual(i, distributedArray[count - 1 - i]);
            }

            //Empty array
            var newArray = new BigArray <int>();

            newArray.Reverse();

            newArray.Add(0); // This items are in the
            newArray.Add(1); // insuring block

            newArray.Reverse();

            Assert.AreEqual(newArray[0], 1);
            Assert.AreEqual(newArray[1], 0);
        }
Example #8
0
        public static void GetRange()
        {
            var distributedArray = new BigArray <int>();
            int size             = 4 * MaxBlockSize;
            int rangeCount       = DefaultBlockSize;

            //Fill array
            for (int i = 0; i < size; i++)
            {
                distributedArray.Add(i);
            }

            for (int i = 0; i < size / rangeCount; i++)
            {
                var range = distributedArray.GetRange(i * rangeCount, rangeCount);
                for (int j = 0; j < rangeCount; j++)
                {
                    Assert.IsTrue(range[j] == i * rangeCount + j);
                }
            }

            var emptyArray = new BigArray <int>();

            Assert.IsEmpty(emptyArray.GetRange(0, 0));

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, BigArray <int> >
                              (distributedArray.GetRange, -1, 1));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, BigArray <int> >
                              (distributedArray.GetRange, 0, distributedArray.Count + 1));
        }
Example #9
0
        public void AddElementOne()
        {
            BigArray <int> array = new BigArray <int>();

            array[1] = 1;

            Assert.AreEqual(1, array[1]);
        }
Example #10
0
        public void AddElementOne()
        {
            BigArray<int> array = new BigArray<int>();

            array[1] = 1;

            Assert.AreEqual(1, array[1]);
        }
Example #11
0
        /// <summary>
        /// Appends a set of traces to the end of the file or trace series.
        /// </summary>
        /// <param name="traces">Traces to write</param>
        /// <param name="progress">A progress handler</param>
        /// <param name="ct">Cancellation token</param>
        public void Write(IEnumerable <SegyTrace> traces, IProgress <int> progress = null, CancellationToken ct = default(CancellationToken))
        {
            CodeContract.Requires <NullReferenceException>(traces != null, "Traces cannot be null.");

            if (ct.IsCancellationRequested)
            {
                return;
            }

            BigArray <SegyTrace> segyTraces = traces as BigArray <SegyTrace> ?? traces.ToBigArray();

            CodeContract.Assume(segyTraces.Any(), "There must be at least one trace to write.");

            // get "traces" statistics.
            var distinctTraceSampleCounts = traces.Select(tr => tr.Data.Length).Distinct();
            int numTraceLengths           = distinctTraceSampleCounts.Count();

            // assume number of trace lengths is 1.
            CodeContract.Assume(numTraceLengths == 1, "There are traces to write with inconsistent lengths.  All traces must have the same length");
            _stream.Seek(0, SeekOrigin.End);

            if (TraceSampleCount == 0)
            {
                TraceSampleCount = distinctTraceSampleCounts.FirstOrDefault();
            }
            else
            {
                CodeContract.Assume(TraceSampleCount == distinctTraceSampleCounts.FirstOrDefault(), "Trace lengths to write is not consistent with the rest of the trace lengths in this file.");
            }

            var  currProgress = 0;
            long traceCount   = segyTraces.LongCount();
            long ctr          = 0;

            foreach (var sgyTrace in traces)
            {
                _writer.Write(sgyTrace.GetBytes());
                ctr++;

                // report progress and cancel if requested
                if (ct.IsCancellationRequested)
                {
                    break;
                }
                if (progress == null)
                {
                    continue;
                }
                var progPercent = (int)(100 * (double)ctr / traceCount);
                if (currProgress == progPercent)
                {
                    continue;
                }

                progress?.Report(progPercent);
                currProgress++;
            }
        }
Example #12
0
        public static ContainsOperation <T> GetContainsOperation <T>(BigArray <T> source, bool isJITOTurnOn)
        {
            if (isJITOTurnOn)
            {
                return(ContainsResolver.GetOperation(source));
            }

            return(new ContainsOperationWithIndexOf <T>(source));
        }
Example #13
0
        public MemoryDataSet(Value[] values)
        {
            this.values = new BigArray <Value>((ulong)values.Length);

            for (int i = 0; i < values.Length; i++)
            {
                this.values[(ulong)i] = values[i];
            }
        }
Example #14
0
        public void GetDefaultOnEmptyArray()
        {
            BigArray <int> array = new BigArray <int>(10);

            for (int k = 0; k < 20; k++)
            {
                Assert.AreEqual(0, array[(ulong)k]);
            }
        }
 protected virtual BigArray <TValue> GetArray(bool readOnly)
 {
     if (readOnly)
     {
         var newArray = new BigArray <TValue>(BaseArray.Length);
         BaseArray.CopyTo(0, newArray, 0, BaseArray.Length);
         return(newArray);
     }
     return(BaseArray);
 }
Example #16
0
        public void AddLastSixteenElementsNodeSizeSixteen()
        {
            BigArray<int> array = new BigArray<int>(16);

            for (int k = 0; k < 16; k++)
                array[(ulong)(ulong.MaxValue - (uint)k)] = k;

            for (int k = 0; k < 16; k++)
                Assert.AreEqual(k, array[(ulong)(ulong.MaxValue - (uint)k)]);
        }
Example #17
0
        public void AddFirstTwentyElementsNodeSizeTen()
        {
            BigArray<int> array = new BigArray<int>(10);

            for (int k = 0; k < 20; k++)
                array[(ulong)k] = k;

            for (int k = 0; k < 20; k++)
                Assert.AreEqual(k, array[(ulong)k]);
        }
Example #18
0
        unsafe public ECL.BigArray <float> ReadBigList(long count)
        {
            // Процедура аналогична ReadIntList

            BigArray <float> list = new BigArray <float>(count);

            byte[] nums_const = new byte[2 * 4 + 4000];

            long index  = 0;
            long bindex = 0;
            long block  = (count / 1000);
            int  mod    = (int)(count - (long)(block * 1000));

            long buflen = 0;

            if (block > 0)
            {
                buflen = (2 * 4 + 4000) * block;
            }
            if (mod > 0)
            {
                buflen += 2 * 4 + 4 * mod;
            }

            Position += buflen;
            int local;

            while (block > 0)
            {
                nums_const = br.ReadBytes(2 * 4 + 4000);
                bindex     = 4;

                for (int iw = 0; iw < 1000; ++iw)
                {
                    local         = (nums_const[bindex + 3]) | (nums_const[bindex + 2] << 8) | (nums_const[bindex + 1] << 0x10) | (nums_const[bindex] << 0x18);
                    list[index++] = *(float *)(&local);
                    bindex       += 4;
                }
                block--;
            }

            if (mod > 0)
            {
                nums_const = br.ReadBytes(2 * 4 + 4 * mod);
                bindex     = 4;
                while (mod > 0)
                {
                    local         = (nums_const[bindex + 3]) | (nums_const[bindex + 2] << 8) | (nums_const[bindex + 1] << 0x10) | (nums_const[bindex] << 0x18);
                    list[index++] = *(float *)(&local);
                    bindex       += 4;
                    mod--;
                }
            }
            return(list);
        }
        private BigArray <int> GetTestInstance()
        {
            BigArray <int> array = new BigArray <int>();

            for (int i = 0; i < TEST_SIZE; i++)
            {
                array.Add(i);
            }

            return(array);
        }
Example #20
0
        private BigArray<int> GetTestInstance()
        {
            BigArray<int> array = new BigArray<int>();

            for (int i = 0; i < TEST_SIZE; i++)
            {
                array.Add(i);
            }

            return array;
        }
Example #21
0
        public static void ToArray()
        {
            var distributedArray = new BigArray <int>();

            for (int i = 0; i < MaxBlockSize * 2; i++)
            {
                distributedArray.Add(i);
            }

            CheckEqual(distributedArray, distributedArray.ToArray());
        }
                protected override BigArray <long> GetArray(bool readOnly)
                {
                    // We must synchronize this entire block because otherwise we could
                    // return a partially loaded array.
                    lock (blockLock) {
                        if (BaseArray != null)
                        {
                            PrepareMutate(readOnly);

                            return(BaseArray);
                        }

                        // Create the int array
                        BaseArray = new BigArray <long>(maxBlockSize);

                        // The number of bytes per entry
                        int entrySize = CompactType;

                        // The total size of the entry.
                        var areaSize = (Count * entrySize);

                        // Read in the byte array
                        byte[] buf = new byte[areaSize];

                        try {
                            Store.GetArea(BlockPointer).Read(buf, 0, (int)areaSize);
                        } catch (IOException e) {
                            throw new InvalidOperationException("IO Error: " + e.Message);
                        }

                        // Uncompact it into the int array
                        int p = 0;

                        for (int i = 0; i < Count; ++i)
                        {
                            int v = (((int)buf[p]) << ((entrySize - 1) * 8));
                            ++p;

                            for (int n = entrySize - 2; n >= 0; --n)
                            {
                                v = v | ((((int)buf[p]) & 0x0FF) << (n * 8));
                                ++p;
                            }

                            BaseArray[i] = v;
                        }

                        mutableBlock = false;
                        PrepareMutate(readOnly);

                        return(BaseArray);
                    }
                }
Example #23
0
        private void MergeIn(ITable outsideTable)
        {
            outerRows = new BigArray <long> [Rows.Length];
            var rawTableInfo = outsideTable.GetRawTableInfo(new RawTableInfo());

            // Get the base information,
            var baseTables = Tables;

            // The tables and rows being merged in.
            var tables = rawTableInfo.Tables;
            var rows   = rawTableInfo.Rows;

            // The number of rows being merged in.
            outerRowCount = rows[0].Count;

            for (int i = 0; i < baseTables.Length; ++i)
            {
                var btable = baseTables[i];
                int index  = -1;

                for (int n = 0; n < tables.Length && index == -1; ++n)
                {
                    if (tables[n].Equals(btable))
                    {
                        index = n;
                    }
                }

                // If the table wasn't found, then set 'NULL' to this base_table
                if (index == -1)
                {
                    outerRows[i] = null;
                }
                else
                {
                    outerRows[i] = new BigArray <long>(outerRowCount);

                    // Merge in the rows from the input table,
                    var toMerge = rows[index];

                    if (toMerge.Count != outerRowCount)
                    {
                        throw new InvalidOperationException("Wrong size for rows being merged in.");
                    }

                    for (long j = 0; j < toMerge.Count; j++)
                    {
                        outerRows[i][j] = toMerge[j];
                    }
                }
            }
        }
Example #24
0
        public void AddFirstTwentyElementsNodeSizeTen()
        {
            BigArray <int> array = new BigArray <int>(10);

            for (int k = 0; k < 20; k++)
            {
                array[(ulong)k] = k;
            }

            for (int k = 0; k < 20; k++)
            {
                Assert.AreEqual(k, array[(ulong)k]);
            }
        }
Example #25
0
        public static void Indexer()
        {
            var distributedArray = new BigArray <int>();

            for (int i = 0; i < MaxBlockSize * 2; i++)
            {
                distributedArray.Add(i);
            }

            for (int i = 0; i < distributedArray.Count; i++)
            {
                Assert.AreEqual(distributedArray[i], i);
            }
        }
Example #26
0
        public void GetDefaultOnUndefinedValuesTwoNodeLevels()
        {
            BigArray <int> array = new BigArray <int>(10);

            for (int k = 0; k < 20; k++)
            {
                array[(ulong)k] = k;
            }

            for (int k = 100; k < 120; k++)
            {
                Assert.AreEqual(0, array[(ulong)k]);
            }
        }
Example #27
0
        public void AddLastSixteenElementsNodeSizeSixteen()
        {
            BigArray <int> array = new BigArray <int>(16);

            for (int k = 0; k < 16; k++)
            {
                array[(ulong)(ulong.MaxValue - (uint)k)] = k;
            }

            for (int k = 0; k < 16; k++)
            {
                Assert.AreEqual(k, array[(ulong)(ulong.MaxValue - (uint)k)]);
            }
        }
Example #28
0
        public void TestCreatingBigArrayWithZeroLength()
        {
            BigArray<int> bigArray = null;
            try
            {
                bigArray = new BigArray<int>(0);
            }
            catch
            {
                Assert.Fail();
            }

            Assert.IsNotNull(bigArray);
        }
Example #29
0
        public static void Contains()
        {
            var distributedArray = new BigArray <int> {
                1
            };

            Assert.IsFalse(distributedArray.Contains(0));
            Assert.IsTrue(distributedArray.Contains(1));
            Assert.IsFalse(distributedArray.Contains(2));

            var emptyArray = new BigArray <int>();

            Assert.AreEqual(emptyArray.Contains(0), false);
        }
Example #30
0
        public static void FindLastIndex()
        {
            var distributedArray = new BigArray <int>();

            for (int i = 0; i < MaxBlockSize * 2; i++)
            {
                distributedArray.Add(i);
            }
            for (int i = 0; i < MaxBlockSize * 2; i++) //For mistakes with duplicate elements
            {
                distributedArray.Add(i);
            }

            //If MaxBlockSize is change, we need to change this code
            Assert.AreEqual(MaxBlockSize, MaxBlockSize);

            Assert.AreEqual(distributedArray.FindLastIndex(IsEqual5000), 13192);
            Assert.AreEqual(distributedArray.FindLastIndex(4999, 5000, IsEqual5000), -1);
            Assert.AreEqual(distributedArray.FindLastIndex(IsEqual128000), -1);
            Assert.AreEqual(distributedArray.FindLastIndex(5001, 1000, IsEqual5000), 5000);

            var emptyArray = new BigArray <int>();

            Assert.AreEqual(emptyArray.FindLastIndex(IsEqual0), -1);

            //Exceptions
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentNullException, Predicate <int>, int>
                              (distributedArray.FindLastIndex, null));

            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, distributedArray.Count, IsEqual0));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, -1, IsEqual0));

            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, distributedArray.Count - 1
                              , distributedArray.Count + 1, IsEqual0));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, distributedArray.Count + 1
                              , 1, IsEqual0));
            Assert.IsTrue(ExceptionManager.IsThrowFuncException
                          <ArgumentOutOfRangeException, int, int, Predicate <int>, int>
                              (distributedArray.FindLastIndex, 1, -1, IsEqual0));
        }
Example #31
0
        public void TestCreatingBigArrayWithZeroLength()
        {
            BigArray <int> bigArray = null;

            try
            {
                bigArray = new BigArray <int>(0);
            }
            catch
            {
                Assert.Fail();
            }

            Assert.IsNotNull(bigArray);
        }
        /// <summary>
        /// Add incoming samples to the buffer
        /// </summary>
        public void AddSamples(BigArray <float> incomingSamples)
        {
            int writeIndex = samples.Count * 4;
            int newLength  = samples.Count + incomingSamples.Length;
            int writeBytes = incomingSamples.Length * 4;

            samples.EnsureCapacity(newLength);
            samples.ForceCount(newLength);
            incomingSamples.CopyTo(0, samples.Items, writeIndex, writeBytes);

            //for( int i = 0; i < incomingSamples.Length; i++ )
            //{
            //	samples[ writeIndex + i ] = incomingSamples[ i ];
            //}
        }
Example #33
0
        public void TestCreatingBigArrayWithNonZeroLength()
        {
            int size = 100;
            BigArray<int> bigArray = null;
            try
            {
                bigArray = new BigArray<int>(size);
            }
            catch
            {
                Assert.Fail();
            }

            Assert.IsNotNull(bigArray);
            Assert.IsTrue(bigArray.Length == size);
        }
Example #34
0
        public void Evaluate_Between_2()
        {
            BigArray <MemoryDataSet.Value> values = new BigArray <MemoryDataSet.Value>(3);

            values[0] = new MemoryDataSet.Value(1, 2);
            values[1] = new MemoryDataSet.Value(2, 4);
            values[2] = new MemoryDataSet.Value(3, 6);

            MemoryDataSet sds = new MemoryDataSet(values);

            for (uint i = 1; i < values.Length; i++)
            {
                double y = sds.Evaluate((values[i - 1].X + values[i].X) / 2);
                Assert.AreEqual(values[i - 1].Y, y);
            }
        }
Example #35
0
        public static void Find()
        {
            var distributedArray = new BigArray <int> {
                1, 2, 3, 4
            };

            Assert.AreEqual(distributedArray.Find(IsEqual0), 0);
            Assert.AreEqual(distributedArray.Find(IsEqual2), 2);

            var emptyArray = new BigArray <int>();

            Assert.AreEqual(emptyArray.Find(IsEqual0), 0);

            //Exceptions
            ExceptionManager.IsThrowFuncException <ArgumentNullException, Predicate <int>, int>
                (distributedArray.Find, null);
        }
Example #36
0
        public void TestCreatingBigArrayWithNonZeroLength()
        {
            int            size     = 100;
            BigArray <int> bigArray = null;

            try
            {
                bigArray = new BigArray <int>(size);
            }
            catch
            {
                Assert.Fail();
            }

            Assert.IsNotNull(bigArray);
            Assert.IsTrue(bigArray.Length == size);
        }
Example #37
0
        public void Evaluate_Overflow_2()
        {
            BigArray <MemoryDataSet.Value> values = new BigArray <MemoryDataSet.Value>(2);

            values[0] = new MemoryDataSet.Value(1, 2);
            values[1] = new MemoryDataSet.Value(2, 4);

            MemoryDataSet sds = new MemoryDataSet(values);

            double result1 = sds.Evaluate(values[0].X - 0.00000001f);

            Assert.AreEqual(double.NaN, result1);

            double result2 = sds.Evaluate(values[values.Length - 1].X + 0.00000001f);

            Assert.AreEqual(double.NaN, result2);
        }
Example #38
0
        private static BigArray<string> GetArray(int size)
        {
            // We have to turn off JITO (just in time optimization) for testing because:
            // 1) We can accidentally move to infinite recursive loop (and this is bad)
            // 2) We shouldn't calculate the fastest implementations of all methods
            //    we need to test current one

            var array = new BigArray<string>(new BigArrayConfiguration<string>
            {
                UseJustInTimeOptimization = false
            });

            for (int i = 0; i < size; i++)
            {
                array.Add(i.ToString());
            }

            return array;
        }
Example #39
0
        public void AddMember(string member)
        {
            if (this.members == null)
                this.members = new BigArray<IList<string>>();

            ulong position = GetPosition(member);

            var list = this.members[position];

            if (list == null)
            {
                list = new List<string>();
                this.members[position] = list;
            }

            if (list.Contains(member))
                return;

            list.Add(member);
        }
        public void Test()
        {
            var array = new BigArray<int>();
            int count = (int) Math.Pow(10, 6);

            for (int i = 0; i < count; i++)
            {
                array.Add(i);
            }

            //Checking
            int startIndex = (int)Math.Pow(10, 3);

            BigArray<int>.BigArrayEnumerator enumerator = (BigArray<int>.BigArrayEnumerator) array.GetEnumerator();
            enumerator.MoveToIndex(startIndex);

            for (int i = startIndex; i < count; i++)
            {
                Assert.AreEqual(enumerator.Current, array[i]);
                enumerator.MoveNext();
            }
        }
Example #41
0
        public bool this[ulong index]
        {
            get
            {
                if (this.bytes == null)
                    return false;

                ulong position = index >> 8;
                ushort offset = (ushort)(index & 0x07);
                byte result = this.bytes[position];
                byte bit = (byte)(1 << offset);

                return (result & bit) != 0;
            }

            set
            {
                if (this.bytes == null)
                {
                    if (value == false)
                        return;
                    this.bytes = new BigArray<byte>();
                }

                ulong position = index >> 8;
                ushort offset = (ushort)(index & 0x07);
                byte result = this.bytes[position];
                byte bit = (byte)(1 << offset);
                if (value == false)
                    result &= (byte)(0xff - bit);
                else
                    result |= bit;

                this.bytes[position] = result;
            }
        }
Example #42
0
        public void GetDefaultOnUndefinedValuesOneNodeLevel()
        {
            BigArray<int> array = new BigArray<int>(10);

            for (int k = 0; k < 5; k++)
                array[(ulong)k] = k;

            for (int k = 100; k < 120; k++)
                Assert.AreEqual(0, array[(ulong)k]);
        }
Example #43
0
        public void MiddleElementsAreDefault()
        {
            BigArray<int> array = new BigArray<int>(16);

            for (int k = 0; k < 16; k++)
                array[(ulong)(ulong.MaxValue - (uint)k)] = k;
            for (int k = 0; k < 16; k++)
                array[(ulong)k] = k;

            for (ulong k = long.MaxValue - 16; k < long.MaxValue; k++)
                Assert.AreEqual(0, array[k]);
        }
Example #44
0
        public void TestGetEnumerator()
        {
            BigArray<int> bigArray = new BigArray<int>(10);
            bigArray[0] = 1;
            bigArray[1] = 2;
            bigArray[2] = 1;
            bigArray[3] = 3;
            bigArray[4] = 4;
            bigArray[5] = 5;
            bigArray[6] = 1;
            bigArray[7] = 6;
            bigArray[8] = 7;
            bigArray[9] = 8;

            int index = 0;
            foreach (int val in bigArray)
            {
                if (bigArray[index++] != val)
                {
                    Assert.Fail();
                }
            }
        }
Example #45
0
        public void TestCopyTo()
        {
            BigArray<int> bigArray = new BigArray<int>(10);
            bigArray[0] = 1;
            bigArray[1] = 2;
            bigArray[2] = 1;
            bigArray[3] = 3;
            bigArray[4] = 4;
            bigArray[5] = 5;
            bigArray[6] = 1;
            bigArray[7] = 6;
            bigArray[8] = 7;
            bigArray[9] = 8;

            int[] array = new int[10];
            try
            {
                int sourceIndex = 0;
                int destIndex = 0;
                int count = 10;
                bigArray.CopyTo(sourceIndex, array, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }

                array = new int[5];
                sourceIndex = 4;
                destIndex = 0;
                count = 5;
                bigArray.CopyTo(sourceIndex, array, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }

                array = new int[10];
                sourceIndex = 4;
                destIndex = 3;
                count = 5;
                bigArray.CopyTo(sourceIndex, array, destIndex, count);
                for (int i = 0; i < count; i++)
                {
                    if (bigArray[i + sourceIndex] != array[i + destIndex])
                    {
                        Assert.Fail();
                    }
                }
            }
            catch
            {
                Assert.Fail();
            }
        }
Example #46
0
 public void TestResize()
 {
     try
     {
         BigArray<int> bigArray = new BigArray<int>(5);
         Assert.IsTrue(bigArray.Length == 5);
         bigArray[0] = 1;
         bigArray[1] = 2;
         bigArray[2] = 1;
         bigArray[3] = 3;
         bigArray[4] = 4;
         bigArray.Resize(10);
         bigArray[5] = 5;
         bigArray[6] = 1;
         bigArray[7] = 6;
         bigArray[8] = 7;
         bigArray[9] = 8;
         Assert.IsTrue(bigArray.Length == 10);
     }
     catch
     {
         Assert.Fail();
     }
 }
Example #47
0
        public void TestIndexOf()
        {
            BigArray<int> bigArray = new BigArray<int>(10);
            bigArray[0] = 1;
            bigArray[1] = 2;
            bigArray[2] = 1;
            bigArray[3] = 3;
            bigArray[4] = 4;
            bigArray[5] = 5;
            bigArray[6] = 1;
            bigArray[7] = 6;
            bigArray[8] = 7;
            bigArray[9] = 8;

            Assert.IsTrue(bigArray.IndexOf(0) == -1);
            Assert.IsTrue(bigArray.IndexOf(1) == 0);
            Assert.IsTrue(bigArray.IndexOf(1, 1) == 2);
            Assert.IsTrue(bigArray.IndexOf(1, 2, 6) == 2);
            Assert.IsTrue(bigArray.IndexOf(1, 3, 4) == 6);
        }
Example #48
0
        public void TestClear()
        {
            BigArray<int> bigArray = new BigArray<int>(10);
            bigArray[0] = 1;
            bigArray[1] = 2;
            bigArray[2] = 1;
            bigArray[3] = 3;
            bigArray[4] = 4;
            bigArray[5] = 5;
            bigArray[6] = 1;
            bigArray[7] = 6;
            bigArray[8] = 7;
            bigArray[9] = 8;

            Assert.IsTrue(bigArray.IndexOf(0) == -1);
            bigArray.Clear(3, 1);
            Assert.IsTrue(bigArray.IndexOf(0) == 3);
            bigArray.Clear();
            for (int i = 0; i < 10; i++)
            {
                Assert.IsTrue(bigArray[i] == 0);
            }
        }