/// <summary>Determine if the file ends with a LF ('\n').</summary> /// <remarks>Determine if the file ends with a LF ('\n').</remarks> /// <returns>true if the last line has an LF; false otherwise.</returns> public virtual bool IsMissingNewlineAtEnd() { int end = lines.Get(lines.Size() - 1); if (end == 0) { return(true); } return(content[end - 1] != '\n'); }
/// <summary>Determine if the file ends with a LF ('\n').</summary> /// <remarks>Determine if the file ends with a LF ('\n').</remarks> /// <returns>true if the last line has an LF; false otherwise.</returns> public bool IsMissingNewlineAtEnd() { int end = _lines.Get(_lines.Size() - 1); if (end == 0) { return(true); } return(Content[end - 1] != '\n'); }
public void TestSet() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) { list.Add(j); } for (int j = 0; j < 1001; j++) { try { list.Set(j, j + 1); if (j == 1000) { Assert.Fail("Should have gotten exception"); } Assert.AreEqual(j + 1, list.Get(j)); } catch (IndexOutOfRangeException) { if (j != 1000) { Assert.Fail("premature exception"); } } } }
public void TestGet() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) { list.Add(j); } for (int j = 0; j < 1001; j++) { try { Assert.AreEqual(j, list.Get(j)); if (j == 1000) { Assert.Fail("should have gotten exception"); } } catch (IndexOutOfRangeException) { if (j != 1000) { Assert.Fail("unexpected IndexOutOfBoundsException"); } } } }
private static int FindReverseLine(IntList lines, int idx, int ptr) { while (0 < idx && ptr <= lines.Get(idx)) { idx--; } return(idx); }
public void GivenAnEmptyList_WhenCallAddMultipleTimes_ThenCallGetWithIndexReturnCorrectItemAndMaintainOriginalCount() { IntList l = new IntList(); l.Add(1); l.Add(2); l.Add(3); l.Add(4); l.Add(5); Assert.Equal(5, l.Count); Assert.Equal(1, l.Get(0)); Assert.Equal(2, l.Get(1)); Assert.Equal(3, l.Get(2)); Assert.Equal(4, l.Get(3)); Assert.Equal(5, l.Get(4)); Assert.Equal(5, l.Count); }
public void GivenAPopulatedList_WhenCallWithInvalidIndex_ThenThrowInvalidListIndexException() { IntList l = new IntList(); l.Add(1); l.Add(2); l.Add(3); Assert.Throws <InvalidListIndexException>(() => l.Get(10)); }
private static int FindForwardLine(IntList lines, int idx, int ptr) { int end = lines.Size() - 2; while (idx < end && lines.Get(idx + 2) < ptr) { idx++; } return(idx); }
public void TestToArray() { IntList list = new IntList(); for (int j = 0; j < 1000; j++) { list.Add(j); } int[] a1 = list.ToArray(); Assert.AreEqual(a1.Length, list.Count); for (int j = 0; j < 1000; j++) { Assert.AreEqual(a1[j], list.Get(j)); } int[] a2 = new int[list.Count]; int[] a3 = list.ToArray(a2); Assert.AreSame(a2, a3); for (int j = 0; j < 1000; j++) { Assert.AreEqual(a2[j], list.Get(j)); } int[] ashort = new int[list.Count - 1]; int[] aLong = new int[list.Count + 1]; int[] a4 = list.ToArray(ashort); int[] a5 = list.ToArray(aLong); Assert.IsTrue(a4 != ashort); Assert.IsTrue(a5 != aLong); Assert.AreEqual(a4.Length, list.Count); for (int j = 0; j < 1000; j++) { Assert.AreEqual(a3[j], list.Get(j)); } Assert.AreEqual(a5.Length, list.Count); for (int j = 0; j < 1000; j++) { Assert.AreEqual(a5[j], list.Get(j)); } }
public void TestClear() { IntList list = new IntList(); for (int j = 0; j < 500; j++) { list.Add(j); } Assert.AreEqual(500, list.Count); list.Clear(); Assert.AreEqual(0, list.Count); for (int j = 0; j < 500; j++) { list.Add(j + 1); } Assert.AreEqual(500, list.Count); for (int j = 0; j < 500; j++) { Assert.AreEqual(j + 1, list.Get(j)); } }
public void TestAdd() { IntList list = new IntList(); int[] testArray = { 0, 1, 2, 3, 5 }; for (int j = 0; j < testArray.Length; j++) { list.Add(testArray[j]); } for (int j = 0; j < testArray.Length; j++) { Assert.AreEqual(testArray[j], list.Get(j)); } Assert.AreEqual(testArray.Length, list.Count); // add at the beginning list.Add(0, -1); Assert.AreEqual(-1, list.Get(0)); Assert.AreEqual(testArray.Length + 1, list.Count); for (int j = 0; j < testArray.Length; j++) { Assert.AreEqual(testArray[j], list.Get(j + 1)); } // add in the middle list.Add(5, 4); Assert.AreEqual(4, list.Get(5)); Assert.AreEqual(testArray.Length + 2, list.Count); for (int j = 0; j < list.Count; j++) { Assert.AreEqual(j - 1, list.Get(j)); } // add at the end list.Add(list.Count, 6); Assert.AreEqual(testArray.Length + 3, list.Count); for (int j = 0; j < list.Count; j++) { Assert.AreEqual(j - 1, list.Get(j)); } // add past end try { list.Add(list.Count + 1, 8); Assert.Fail("should have thrown exception"); } catch (IndexOutOfRangeException) { // as expected } // Test growth list = new IntList(0); for (int j = 0; j < 1000; j++) { list.Add(j); } Assert.AreEqual(1000, list.Count); for (int j = 0; j < 1000; j++) { Assert.AreEqual(j, list.Get(j)); } list = new IntList(0); for (int j = 0; j < 1000; j++) { list.Add(0, j); } Assert.AreEqual(1000, list.Count); for (int j = 0; j < 1000; j++) { Assert.AreEqual(j, list.Get(999 - j)); } }
public void TestAddAll() { IntList list = new IntList(); for (int j = 0; j < 5; j++) { list.Add(j); } IntList list2 = new IntList(0); list2.AddAll(list); list2.AddAll(list); Assert.AreEqual(2 * list.Count, list2.Count); for (int j = 0; j < 5; j++) { Assert.AreEqual(list2.Get(j), j); Assert.AreEqual(list2.Get(j + list.Count), j); } IntList empty = new IntList(); int limit = list.Count; for (int j = 0; j < limit; j++) { Assert.IsTrue(list.AddAll(j, empty)); Assert.AreEqual(limit, list.Count); } try { list.AddAll(limit + 1, empty); Assert.Fail("should have thrown an exception"); } catch (IndexOutOfRangeException) { // as expected } // try add at beginning empty.AddAll(0, list); //Assert.AreEqual(empty, list); Assert.IsTrue(empty.Equals(list)); // try in the middle empty.AddAll(1, list); Assert.AreEqual(2 * list.Count, empty.Count); Assert.AreEqual(list.Get(0), empty.Get(0)); Assert.AreEqual(list.Get(0), empty.Get(1)); Assert.AreEqual(list.Get(1), empty.Get(2)); Assert.AreEqual(list.Get(1), empty.Get(6)); Assert.AreEqual(list.Get(2), empty.Get(3)); Assert.AreEqual(list.Get(2), empty.Get(7)); Assert.AreEqual(list.Get(3), empty.Get(4)); Assert.AreEqual(list.Get(3), empty.Get(8)); Assert.AreEqual(list.Get(4), empty.Get(5)); Assert.AreEqual(list.Get(4), empty.Get(9)); // try at the end empty.AddAll(empty.Count, list); Assert.AreEqual(3 * list.Count, empty.Count); Assert.AreEqual(list.Get(0), empty.Get(0)); Assert.AreEqual(list.Get(0), empty.Get(1)); Assert.AreEqual(list.Get(0), empty.Get(10)); Assert.AreEqual(list.Get(1), empty.Get(2)); Assert.AreEqual(list.Get(1), empty.Get(6)); Assert.AreEqual(list.Get(1), empty.Get(11)); Assert.AreEqual(list.Get(2), empty.Get(3)); Assert.AreEqual(list.Get(2), empty.Get(7)); Assert.AreEqual(list.Get(2), empty.Get(12)); Assert.AreEqual(list.Get(3), empty.Get(4)); Assert.AreEqual(list.Get(3), empty.Get(8)); Assert.AreEqual(list.Get(3), empty.Get(13)); Assert.AreEqual(list.Get(4), empty.Get(5)); Assert.AreEqual(list.Get(4), empty.Get(9)); Assert.AreEqual(list.Get(4), empty.Get(14)); }
public int GetDbcellAt(int cellnum) { return(field_5_dbcells.Get(cellnum)); }
public void GivenAnEmptyList_WhenCallGet_ThenThrowEmptyListException() { IntList l = new IntList(); Assert.Throws <EmptyListException>(() => l.Get()); }