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); }
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)); }
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); }
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); }
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)); }
public static void LastIndexOf() { 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, 4096); Assert.AreEqual(distributedArray.LastIndexOf(5000), 13192); Assert.AreEqual(distributedArray.LastIndexOf(5000, 4999, 5000), -1); Assert.AreEqual(distributedArray.LastIndexOf(128000), -1); Assert.AreEqual(distributedArray.LastIndexOf(5000, 5001, 1000), 5000); var emptyArray = new BigArray <int>(); Assert.AreEqual(emptyArray.LastIndexOf(0), -1); //Exceptions Assert.IsTrue(ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, int, int> (distributedArray.LastIndexOf, 0, distributedArray.Count)); Assert.IsTrue(ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, int, int> (distributedArray.LastIndexOf, 0, -1)); Assert.IsTrue(ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, int, int, int> (distributedArray.LastIndexOf, 0, 0, 2)); Assert.IsTrue(ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, int, int, int> (distributedArray.LastIndexOf, 0, distributedArray.Count, 1)); Assert.IsTrue(ExceptionManager.IsThrowFuncException <ArgumentOutOfRangeException, int, int, int, int> (distributedArray.LastIndexOf, 0, 2, -1)); }
public static void AddAndIsert() { var distributedArray = new BigArray <int>(); var size = MaxBlockSize * 2; for (int i = size / 4; i < size / 2; i++) { distributedArray.Add(i); } Assert.AreEqual(distributedArray.Count, size / 4); for (int i = 0; i < size / 4; i++) { distributedArray.Insert(i, i); } Assert.AreEqual(distributedArray.Count, size / 2); for (int i = size / 2; i < size * 3 / 4; i++) { distributedArray.Add(i); } Assert.AreEqual(distributedArray.Count, size * 3 / 4); for (int i = size * 3 / 4; i < size; i++) { distributedArray.Insert(i, i); } Assert.AreEqual(distributedArray.Count, size); //DA must be : 0,1,2,3...,n-1,n for (int i = 0; i < distributedArray.Count - 1; i++) { Assert.IsTrue(distributedArray[i] + 1 == distributedArray[i + 1]); } //Exceptions Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, int, int> (distributedArray.Insert, -1, 0)); Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, int, int> (distributedArray.Insert, distributedArray.Count + 1, 0)); }
private BigArray<int> GetTestInstance() { BigArray<int> array = new BigArray<int>(); for (int i = 0; i < TEST_SIZE; i++) { array.Add(i); } return array; }
public static void ToArray() { var distributedArray = new BigArray <int>(); for (int i = 0; i < MaxBlockSize * 2; i++) { distributedArray.Add(i); } CheckEqual(distributedArray, distributedArray.ToArray()); }
private BigArray <int> GetTestInstance() { BigArray <int> array = new BigArray <int>(); for (int i = 0; i < TEST_SIZE; i++) { array.Add(i); } return(array); }
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); } }
public static void RemoveRange() { var distributedArray = new BigArray <int>(); int size = 4 * MaxBlockSize; var checkList = new List <int>(size); for (int i = 0; i < size; i++) { distributedArray.Add(i); checkList.Add(i); } //Remove elements from different blocks distributedArray.RemoveRange(MaxBlockSize / 2, MaxBlockSize); checkList.RemoveRange(MaxBlockSize / 2, MaxBlockSize); Assert.AreEqual(distributedArray.Count, checkList.Count); distributedArray.RemoveRange(0, 1); checkList.RemoveRange(0, 1); Assert.AreEqual(distributedArray.Count, checkList.Count); distributedArray.RemoveRange(distributedArray.Count - 1, 1); checkList.RemoveRange(checkList.Count - 1, 1); Assert.AreEqual(distributedArray.Count, checkList.Count); CheckEqual(distributedArray, checkList); //Clear distibutedArray distributedArray.RemoveRange(0, distributedArray.Count); Assert.IsTrue(distributedArray.Count == 0); var emptyArray = new BigArray <int>(); emptyArray.RemoveRange(0, 0); Assert.IsEmpty(emptyArray); //Exceptions Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, int, int> (distributedArray.RemoveRange, -1, 1)); Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, int, int> (distributedArray.RemoveRange, distributedArray.Count - 1, 2)); }
public static void BinarySearch() { var distributedArray = new BigArray <int>(); for (int i = 0; i < 512; i += 2) { distributedArray.Add(i); } Assert.AreEqual(distributedArray.BinarySearch(128), 64); Assert.AreEqual(~distributedArray.BinarySearch(0, 64, 130, Comparer <int> .Default), 64); Assert.AreEqual(~distributedArray.BinarySearch(-100), 0); Assert.AreEqual(~distributedArray.BinarySearch(1), 1); var emptyArray = new BigArray <int>(); Assert.AreEqual(~emptyArray.BinarySearch(1), 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; }
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); }
public static void RemoveAt() { var distributedArray = new BigArray <int>(); int size = 4 * MaxBlockSize; var checkList = new List <int>(size); for (int i = 0; i < size; i++) { distributedArray.Add(i); checkList.Add(i); } //Remove last element of first block distributedArray.RemoveAt(MaxBlockSize - 1); checkList.RemoveAt(MaxBlockSize - 1); Assert.AreEqual(distributedArray.Count, checkList.Count); //Remove first element of second block distributedArray.RemoveAt(MaxBlockSize + 1); checkList.RemoveAt(MaxBlockSize + 1); Assert.AreEqual(distributedArray.Count, checkList.Count); distributedArray.RemoveAt(0); checkList.RemoveAt(0); Assert.AreEqual(distributedArray.Count, checkList.Count); distributedArray.RemoveAt(distributedArray.Count - 1); checkList.RemoveAt(checkList.Count - 1); Assert.AreEqual(distributedArray.Count, checkList.Count); CheckEqual(distributedArray, checkList); //Exceptions Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, int> (distributedArray.RemoveAt, -1)); Assert.IsTrue(ExceptionManager.IsThrowActionException <ArgumentOutOfRangeException, int> (distributedArray.RemoveAt, distributedArray.Count)); }
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(); } }
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(); } }
public static void Foreach() { var distributedArray = new BigArray <int>(); int size = 4 * MaxBlockSize; for (int i = 0; i < size; i++) { distributedArray.Add(i); } var newArray = new BigArray <int>(); foreach (var i in distributedArray) { newArray.Add(i); } Assert.IsTrue(distributedArray.Count == newArray.Count); //array must be equal newArray Assert.IsFalse(distributedArray.Where((t, i) => t != newArray[i]).Any()); }
public static void Remove() { var distributedArray = new BigArray <int>(); int size = 4 * MaxBlockSize; var checkList = new List <int>(size); for (int i = 0; i < size; i++) { distributedArray.Add(i); checkList.Add(i); } //Remove last element of first block Assert.IsTrue(distributedArray.Remove(MaxBlockSize - 1)); checkList.Remove(MaxBlockSize - 1); Assert.AreEqual(distributedArray.Count, checkList.Count); //Remove first element of second block Assert.IsTrue(distributedArray.Remove(MaxBlockSize)); checkList.Remove(MaxBlockSize); Assert.AreEqual(distributedArray.Count, checkList.Count); Assert.IsTrue(distributedArray.Remove(0)); checkList.Remove(0); Assert.AreEqual(distributedArray.Count, checkList.Count); Assert.IsTrue(distributedArray.Remove(distributedArray.Count - 1)); checkList.Remove(checkList.Count - 1); Assert.AreEqual(distributedArray.Count, checkList.Count); //Try to remove nonexistent elements Assert.IsFalse(distributedArray.Remove(0)); Assert.IsFalse(distributedArray.Remove(size)); Assert.IsFalse(distributedArray.Remove(MaxBlockSize)); Assert.IsFalse(distributedArray.Remove(-1)); CheckEqual(distributedArray, checkList); }