public void ReverseSortBy() { ArrayList arrayList = new ArrayList(); arrayList.Add(new BELInteger(1)); arrayList.Add(new BELInteger(2)); arrayList.Add(new BELInteger(3)); arrayList.Add(new BELInteger(0)); BELArray unsorted = new BELArray(arrayList); // Create a simple arithmetic mapping for the sort BehaviorParser parser = new BehaviorParser(""); ExposableParseTreeNode block = parser.Parse("4.Subtract(e)"); ArrayList parameters = new ArrayList(); BlockParameter parameter = new BlockParameter(null, "e"); parameters.Add(parameter); BELArray sorted = unsorted.ReverseSortBy(new ExecutionContext(), new Block(block, parameters, null)); Assert.AreEqual(4, sorted.Count, "Checking that the length was preserved."); for (int i = 0; i < 4; ++i) { Assert.AreEqual(i, ((BELInteger)sorted.Item(i)).Value, "Checking that sort order was correct."); } }
public void BELArrayUniqueAllSameTest() { BELArray sourceArray = new BELArray(); sourceArray.Add("one"); sourceArray.Add("one"); sourceArray.Add("one"); sourceArray.Add("one"); sourceArray.Add("one"); ArrayList expectedArray = new ArrayList(); expectedArray.Add("one"); ArrayList resultArray = sourceArray.Unique(); Assert.AreEqual(expectedArray.Count, resultArray.Count, "Checking that the resulting array has a single element"); Assert.AreEqual(expectedArray[0].GetHashCode(), resultArray[0].GetHashCode(), "Checking that the result element has the correct hash code"); }
public void BELArrayUniqueAllUniqueTest() { BELArray sourceArray = new BELArray(); sourceArray.Add("one"); sourceArray.Add("two"); sourceArray.Add("three"); sourceArray.Add("four"); sourceArray.Add("five"); ArrayList resultArray = sourceArray.Unique(); Assert.AreEqual(sourceArray.Count, resultArray.Count, "Checking that the resulting array is the correct size"); for (int i = 0; i < resultArray.Count; i++) { Assert.AreEqual(sourceArray.Array[i].GetHashCode(), resultArray[i].GetHashCode(), "Checking the element value hash codes are correct"); } }
public void ArraySnip() { ArrayList arrayList = new ArrayList(); arrayList.Add(new BELInteger(0)); arrayList.Add(new BELInteger(1)); arrayList.Add(new BELInteger(2)); arrayList.Add(new BELInteger(3)); BELArray original = new BELArray(arrayList); BELArray snipped = original.Snip(2); Assert.AreEqual(4, original.Count, "Checking that the length was preserved."); Assert.AreEqual(2, snipped.Count, "Checking that the snipped length was correct."); Assert.AreEqual(0, ((BELInteger) snipped.Item(0)).Value, "Checking that the contents of the snipped array are correct."); Assert.AreEqual(1, ((BELInteger) snipped.Item(1)).Value, "Checking that the contents of the snipped array are correct."); }
public void ReverseSortByEmpty() { BELArray unsorted = new BELArray(); // Create a simple arithmetic mapping for the sort BehaviorParser parser = new BehaviorParser(""); ExposableParseTreeNode block = parser.Parse("4.Subtract(e)"); ArrayList parameters = new ArrayList(); BlockParameter parameter = new BlockParameter(null, "e"); parameters.Add(parameter); BELArray sorted = unsorted.ReverseSortBy(new ExecutionContext(), new Block(block, parameters, null)); Assert.IsNotNull(sorted, "Checking that result was returned for an empty array."); Assert.AreEqual(0, sorted.Count, "Checking that the result array was empty."); }
public void ArrayReverse() { ArrayList arrayList = new ArrayList(); arrayList.Add(new BELInteger(0)); arrayList.Add(new BELInteger(1)); arrayList.Add(new BELInteger(2)); arrayList.Add(new BELInteger(3)); BELArray original = new BELArray(arrayList); BELArray reversed = original.Reverse(); Assert.AreEqual(4, reversed.Count, "Checking that the length was preserved."); for (int i = 0; i < 4; ++i) { Assert.AreEqual(3 - i, ((BELInteger)reversed.Item(i)).Value, "Checking that order was reversed."); } }
public void ReverseSort() { ArrayList arrayList = new ArrayList(); arrayList.Add(new BELInteger(1)); arrayList.Add(new BELInteger(2)); arrayList.Add(new BELInteger(3)); arrayList.Add(new BELInteger(0)); BELArray unsorted = new BELArray(arrayList); BELArray sorted = unsorted.ReverseSort(); Assert.AreEqual(4, sorted.Count, "Checking that the length was preserved."); for (int i = 0; i < 4; ++i) { Assert.AreEqual(3 - i, ((BELInteger)sorted.Item(i)).Value, "Checking that sort order was correct."); } }
public void ArrayItems() { ArrayList arrayList = new ArrayList(); arrayList.Add(new BELInteger(0)); arrayList.Add(new BELString("array")); arrayList.Add(BELBoolean.True); arrayList.Add(new BELInteger(3)); BELArray original = new BELArray(arrayList); //int item0 = 0; string item1 = "array"; bool item2 = true; int item3 = 3; Assert.AreEqual(4, original.Count, "Checking that the length was preserved."); Assert.AreEqual(0, ((BELInteger) original.Item(0)).Value, "Checking that the Item outputs are correct."); Assert.AreEqual(item1, ((BELString) original.Item(1)).Value, "Checking that the Item outputs are correct."); Assert.AreEqual(item2, ((BELBoolean) original.Item(2)).Value, "Checking that the Item outputs are correct."); Assert.AreEqual(item3, ((BELInteger) original.Item(3)).Value, "Checking that the Item outputs are correct."); }
public void BELArrayUniqueArrayOfSingleElementArraysTest() { // This test reflects a common scenario under WikiTalk where an arrays members are // single element arrays in themselves. BELArray oneElement = new BELArray(); oneElement.Add("*****@*****.**"); BELArray anotherElement = new BELArray(); anotherElement.Add("*****@*****.**"); BELArray sourceArray = new BELArray(); sourceArray.Add(oneElement); sourceArray.Add(oneElement); sourceArray.Add(anotherElement); sourceArray.Add(anotherElement); ArrayList expectedArray = new ArrayList(); expectedArray.Add(oneElement); expectedArray.Add(anotherElement); ArrayList resultArray = sourceArray.Unique(); Assert.AreEqual(expectedArray.Count, resultArray.Count, "Checking that the resulting array is the correct size"); for (int i = 0; i < resultArray.Count; i++) { Assert.AreEqual(((BELArray)expectedArray[i]).Array[0].GetHashCode(), ((BELArray)resultArray[i]).Array[0].GetHashCode(), "Checking the element value hash codes are correct"); } }
public void BELArrayUniqueMixedTypesTest() { BELArray sourceArray = new BELArray(); sourceArray.Add(1); sourceArray.Add("one"); sourceArray.Add("one"); sourceArray.Add(1); sourceArray.Add(2); sourceArray.Add("two"); ArrayList expectedArray = new ArrayList(); expectedArray.Add(new BELInteger(1)); expectedArray.Add(new BELString("one")); expectedArray.Add(new BELInteger(2)); expectedArray.Add(new BELString("two")); ArrayList resultArray = sourceArray.Unique(); Assert.AreEqual(expectedArray.Count, resultArray.Count, "Checking that the resulting array is the correct size"); for (int i = 0; i < resultArray.Count; i++) { Assert.AreEqual(expectedArray[i].GetHashCode(), resultArray[i].GetHashCode(), "Checking the element value hash codes are correct"); } }
public void BELArrayUniqueEmptyTest() { BELArray sourceArray = new BELArray(); ArrayList resultArray = sourceArray.Unique(); Assert.AreEqual(0, resultArray.Count, "Checking that the result array is empty"); }
public void ArrayToString() { ArrayList arrayList = new ArrayList(); arrayList.Add(new BELInteger(0)); arrayList.Add(new BELInteger(1)); arrayList.Add(new BELInteger(2)); arrayList.Add(new BELInteger(3)); BELArray original = new BELArray(arrayList); string result = original.ToOneString; Assert.AreEqual(4, original.Count, "Checking that the length was preserved."); Assert.AreEqual("0123", result, "Checking that the string outputs are correct."); }