public void GapBuffer_RemoveTest() { GapBuffer <int> buf = CreateTestGapBuffer(); Assert.IsFalse(buf.Remove(0)); Assert.AreEqual(16, buf.IndexOf(999)); Assert.IsTrue(buf.Remove(999)); Assert.AreEqual(-1, buf.IndexOf(999)); buf.RemoveAt(1); Assert.AreEqual(1, buf.Gap); buf.RemoveAt(0); Assert.AreEqual(23, buf.Count); Assert.AreEqual(0, buf.Gap); Assert.AreEqual(9, buf.GapCount); Assert.AreEqual(9, buf.AfterGap); buf.RemoveAt(21); Assert.AreEqual(21, buf.Gap); buf.RemoveAt(21); Assert.AreEqual(21, buf.Count); Assert.AreEqual(21, buf.Gap); Assert.AreEqual(11, buf.GapCount); Assert.AreEqual(32, buf.AfterGap); for (int i = 0; i < buf.Count; i++) { Assert.AreEqual(102 + i, buf[i]); } }
public void InsertTest3() { var l = new List <int>(4); var gb = new GapBuffer <int>(4); Fill(gb, l, 1000); var rng = new Random(1); for (int i = 0; i < 500; i++) { var n = rng.Next(i); l.RemoveAt(n); gb.RemoveAt(n); } Assert.Equal(l.Count, gb.Count); for (int i = 0; i < l.Count; i++) { Assert.Equal(l[i], gb[i]); } }
private void Manager_OnTextInput(object sender, TextInputEventArgs e) { bool NewLine = false; //Was a new line created? if (m_HasFocus) { if (m_Mode != TextEditMode.ReadOnly) { if (m_NumLines > 1) { Vector2 MeasuredString = m_Font.MeasureString(GetCurrentLine()); //Check that text doesn't go beyond width of control... if (((Position.X + MeasuredString.X) >= m_Size.X) && !m_RemovingTxt && !m_MovingCursor) { if (m_TextPosition.Y <= Position.Y + ((m_NumLines - 2) * m_Font.LineSpacing)) { m_TextPosition.Y += m_Font.LineSpacing; RenderableText2 RenderTxt = new RenderableText2(); RenderTxt.Position = m_TextPosition; RenderTxt.Text = GetCurrentLine(); RenderTxt.Visible = true; m_Lines.Add(RenderTxt); m_CurrentLine.Clear(); m_Cursor.Position.Y += m_Font.LineSpacing; m_Cursor.LineIndex++; m_Cursor.CharacterIndex = 0; m_Cursor.Position.X = Position.X; NewLine = true; } else //Text went beyond the borders of the control... { RenderableText2 RenderTxt = new RenderableText2(); RenderTxt.Position = m_TextPosition; RenderTxt.Text = GetCurrentLine(); RenderTxt.Visible = true; m_Lines.Add(RenderTxt); m_CurrentLine.Clear(); m_ScrollbarHeight -= m_Font.LineSpacing; //TODO: Resize scrollbar... m_Cursor.LineIndex++; m_Cursor.CharacterIndex = 0; m_Cursor.Position.X = Position.X; NewLine = true; } } } else { //Text went beyond the borders of the control... if (m_Font.MeasureString(Text).X >= (m_Size.X - m_Font.MeasureString(e.Character.ToString()).X) && !m_RemovingTxt) { m_Cursor.Position.X = m_Size.X; m_Renderer.ScrollTextLeft(); } } if (!m_IsUpperCase) { //If the cursor is in the middle of a line, replace the character. if (m_Cursor.CharacterIndex < GetCurrentLine().Length) { m_CurrentLine.RemoveAt(m_Cursor.CharacterIndex); m_Renderer.RemoveAt(m_Cursor.CharacterIndex); m_CurrentLine.Insert(m_Cursor.CharacterIndex, e.Character.ToString()); m_Renderer.Insert(m_Cursor.CharacterIndex, e.Character.ToString()); } else { m_CurrentLine.Add(e.Character.ToString()); m_Renderer.Insert(m_Cursor.CharacterIndex, e.Character.ToString()); } } else { //If the cursor is in the middle of a line, replace the character. if (m_Cursor.CharacterIndex < GetCurrentLine().Length) { m_CurrentLine.RemoveAt(m_Cursor.CharacterIndex); m_Renderer.RemoveAt(m_Cursor.CharacterIndex); m_CurrentLine.Insert(m_Cursor.CharacterIndex, e.Character.ToString().ToUpper()); m_Renderer.Insert(m_Cursor.CharacterIndex, e.Character.ToString().ToUpper()); } else { m_CurrentLine.Add(e.Character.ToString().ToUpper()); m_Renderer.Insert(m_Cursor.CharacterIndex, e.Character.ToString()); } } } if (!NewLine) { m_Cursor.CharacterIndex++; } m_RemovingTxt = false; m_MovingCursor = false; m_Cursor.Position.X += m_Font.MeasureString(e.Character.ToString()).X; } }