diff options
author | Mike Krüger <mkrueger@novell.com> | 2011-05-03 18:02:31 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@novell.com> | 2011-05-03 18:02:31 +0400 |
commit | f8aa2382056f0f4db3f95f049d335eb6773ab7d2 (patch) | |
tree | c241e94225e78ceac6a3ac1649b6e7ee49ad33dc /main/tests | |
parent | e012ce2a36ad1257a171903cf85394a13170bdc6 (diff) |
Added height tree implementation.
Diffstat (limited to 'main/tests')
-rw-r--r-- | main/tests/UnitTests/Makefile.am | 1 | ||||
-rw-r--r-- | main/tests/UnitTests/Mono.TextEditor.Tests/HeightTreeTests.cs | 176 | ||||
-rw-r--r-- | main/tests/UnitTests/UnitTests.csproj | 1 |
3 files changed, 178 insertions, 0 deletions
diff --git a/main/tests/UnitTests/Makefile.am b/main/tests/UnitTests/Makefile.am index b26d4afaad..c0603bb162 100644 --- a/main/tests/UnitTests/Makefile.am +++ b/main/tests/UnitTests/Makefile.am @@ -47,6 +47,7 @@ FILES = \ Mono.TextEditor.Tests/DocumentTests.cs \ Mono.TextEditor.Tests/EditActionsTest.cs \ Mono.TextEditor.Tests/FoldingTests.cs \ + Mono.TextEditor.Tests/HeightTreeTests.cs \ Mono.TextEditor.Tests/InsertionModeTests.cs \ Mono.TextEditor.Tests/LineSplitterTests.cs \ Mono.TextEditor.Tests/RedBlackTreeTests.cs \ diff --git a/main/tests/UnitTests/Mono.TextEditor.Tests/HeightTreeTests.cs b/main/tests/UnitTests/Mono.TextEditor.Tests/HeightTreeTests.cs new file mode 100644 index 0000000000..454fd9a938 --- /dev/null +++ b/main/tests/UnitTests/Mono.TextEditor.Tests/HeightTreeTests.cs @@ -0,0 +1,176 @@ +// +// HeightTreeTests.cs +// +// Author: +// Mike Krüger <mkrueger@novell.com> +// +// Copyright (c) 2011 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using NUnit.Framework; +using UnitTests; + +namespace Mono.TextEditor.Tests +{ + [TestFixture()] + public class HeightTreeTests : TestBase + { + [Test()] + public void TestSimpleLineNumberToY () + { + TextEditor editor = new TextEditor (); + editor.Text = "1\n2\n3\n4\n5\n6\n7"; + HeightTree heightTree = new HeightTree (editor); + heightTree.Rebuild (); + for (int i = 1; i <= editor.LineCount; i++) { + Assert.AreEqual ((i - 1) * editor.LineHeight, heightTree.LineNumberToY (i)); + } + } + + [Test()] + public void TestSimpleYToLineNumber () + { + TextEditor editor = new TextEditor (); + editor.Text = "1\n2\n3\n4\n5\n6\n7"; + HeightTree heightTree = new HeightTree (editor); + heightTree.Rebuild (); + for (int i = 1; i <= editor.LineCount; i++) { + Assert.AreEqual (i, heightTree.YToLineNumber ((i - 1) * editor.LineHeight)); + } + } + + [Test()] + public void TestSetLineHeight () + { + TextEditor editor = new TextEditor (); + editor.Text = "1\n2\n3\n4\n5\n6\n7"; + HeightTree heightTree = new HeightTree (editor); + heightTree.Rebuild (); + for (int i = 1; i <= editor.LineCount; i += 2) { + heightTree.SetLineHeight (i, editor.LineHeight * 2); + } + + double y = 0; + for (int i = 1; i <= editor.LineCount; i++) { + Assert.AreEqual (y, heightTree.LineNumberToY (i)); + y += i % 2 == 0 ? editor.LineHeight : editor.LineHeight * 2; + } + + y = 0; + for (int i = 1; i <= editor.LineCount; i++) { + Assert.AreEqual (i, heightTree.YToLineNumber (y)); + y += i % 2 == 0 ? editor.LineHeight : editor.LineHeight * 2; + } + + } + + [Test()] + public void TestFoldLineNumberToYCase1 () + { + TextEditor editor = new TextEditor (); + editor.Text = "1\n2\n3\n4\n5\n6\n7"; + HeightTree heightTree = new HeightTree (editor); + heightTree.Rebuild (); + + heightTree.Fold (2, 2); + + for (int i = 1; i <= editor.LineCount; i++) { + int j = i; + if (j >= 2) { + if (j <= 4) { + j = 2; + } else { + j -= 2; + } + } + Console.WriteLine ("i:" + i + "/" + j); + Assert.AreEqual ((j - 1) * editor.LineHeight, heightTree.LineNumberToY (i)); + } + } + + [Test()] + public void TestFoldYToLineNumber () + { + TextEditor editor = new TextEditor (); + editor.Text = "1\n2\n3\n4\n5\n6\n7"; + HeightTree heightTree = new HeightTree (editor); + heightTree.Rebuild (); + + heightTree.Fold (2, 2); + + for (int i = 1; i <= editor.LineCount; i++) { + int j = i; + if (j >= 2) { + if (j <= 4) { + j = 2; + } else { + j -= 2; + } + } + + int k; + if (i >= 2 && i <= 4) { + k = 2; + } else { + k = i; + } + + Assert.AreEqual (k, heightTree.YToLineNumber ((j - 1) * editor.LineHeight)); + } + } + + [Test()] + public void TestFoldLineNumberToY () + { + TextEditor editor = new TextEditor (); + editor.Text = "1\n2\n3\n4\n5\n6\n7\n8"; + HeightTree heightTree = new HeightTree (editor); + heightTree.Rebuild (); + + heightTree.Fold (1, 3); + for (int i = 1; i <= editor.LineCount; i++) { + Console.WriteLine (i + ":"+ heightTree.LineNumberToY (i)); + } + Assert.AreEqual (0, heightTree.LineNumberToY (2)); + Assert.AreEqual (0, heightTree.LineNumberToY (4)); + Assert.AreEqual (1 * editor.LineHeight, heightTree.LineNumberToY (5)); + Assert.AreEqual (2 * editor.LineHeight, heightTree.LineNumberToY (6)); + Assert.AreEqual (3 * editor.LineHeight, heightTree.LineNumberToY (7)); + } + + [Test()] + public void TestUnfold () + { + TextEditor editor = new TextEditor (); + editor.Text = "1\n2\n3\n4\n5\n6\n7"; + HeightTree heightTree = new HeightTree (editor); + heightTree.Rebuild (); + heightTree.Fold (2, 2); + heightTree.Unfold (2, 2); + for (int i = 1; i <= editor.LineCount; i++) { + Assert.AreEqual ((i - 1) * editor.LineHeight, heightTree.LineNumberToY (i)); + Assert.AreEqual (i, heightTree.YToLineNumber ((i - 1) * editor.LineHeight)); + } + } + + + } +} + diff --git a/main/tests/UnitTests/UnitTests.csproj b/main/tests/UnitTests/UnitTests.csproj index 8ae5bdadf2..60875b9c7c 100644 --- a/main/tests/UnitTests/UnitTests.csproj +++ b/main/tests/UnitTests/UnitTests.csproj @@ -236,6 +236,7 @@ <Compile Include="MonoDevelop.VersionControl.Git\GitUtilsTests.cs" /> <Compile Include="Mono.TextEditor.Tests\SegmentTreeTests.cs" /> <Compile Include="Mono.TextEditor.Tests\RedBlackTreeTests.cs" /> + <Compile Include="Mono.TextEditor.Tests\HeightTreeTests.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\md.targets" /> |