예제 #1
0
        public void TestSearchBackward()
        {
            GapBuffer buffer = new GapBuffer();

            for (int i = 0; i < 100; i++)
            {
                buffer.Insert(0, "a");
            }
            var idx = new List <int> (new [] { 0, buffer.Length / 2, buffer.Length });

            idx.ForEach(i => buffer.Insert(i, "test"));

            // move gap to the beginning
            buffer.Replace(idx[0], 1, buffer.GetCharAt(idx[0]).ToString());

            List <int> results = new List <int> (buffer.SearchBackward("test", buffer.Length));

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);

            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[idx.Count - 1 - i], results[i], (i + 1) + ". match != " + idx[idx.Count - 1 - i] + " was " + results[i]);
            }

            // move gap to the middle
            buffer.Replace(idx[1], 1, buffer.GetCharAt(idx[1]).ToString());

            results = new List <int> (buffer.SearchBackward("test", buffer.Length));
            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[idx.Count - 1 - i], results[i], (i + 1) + ". match != " + idx[idx.Count - 1 - i] + " was " + results[i]);
            }

            // move gap to the end
            buffer.Replace(idx[2], 1, buffer.GetCharAt(idx[2]).ToString());

            results = new List <int> (buffer.SearchBackward("test", buffer.Length));

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[idx.Count - 1 - i], results[i], (i + 1) + ". match != " + idx[idx.Count - 1 - i] + " was " + results[i]);
            }

            // move gap to the end
            buffer.Replace(buffer.Length - 1, 1, buffer.GetCharAt(buffer.Length - 1).ToString());

            results = new List <int> (buffer.SearchBackward("test", buffer.Length));
            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[idx.Count - 1 - i], results[i], (i + 1) + ". match != " + idx[idx.Count - 1 - i] + " was " + results[i]);
            }
        }
예제 #2
0
		public void TestSearchForward ()
		{
			GapBuffer buffer = new GapBuffer ();
			for (int i = 0; i < 100; i++) {
				buffer.Insert (0, "a");
			}
			var idx = new List<int> (new [] { 0,  buffer.Length / 2, buffer.Length });
			
			idx.ForEach (i => buffer.Insert (i, "test"));
			
			// move gap to the beginning
			buffer.Replace (idx[0], 1, buffer.GetCharAt (idx[0]).ToString ());
			
			List<int> results = new List<int> (buffer.SearchForward ("test", 0));
			
			Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
			for (int i = 0; i < idx.Count; i++)
				Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
			
			// move gap to the middle
			buffer.Replace (idx[1], 1, buffer.GetCharAt (idx[1]).ToString ());
			
			results = new List<int> (buffer.SearchForward ("test", 0));
			Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
			for (int i = 0; i < idx.Count; i++)
				Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
			
			// move gap to the end
			buffer.Replace (idx[2], 1, buffer.GetCharAt (idx[2]).ToString ());
			
			results = new List<int> (buffer.SearchForward ("test", 0));
			Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
			for (int i = 0; i < idx.Count; i++)
				Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
			
			// move gap to the end
			buffer.Replace (buffer.Length - 1, 1, buffer.GetCharAt (buffer.Length - 1).ToString ());
			
			results = new List<int> (buffer.SearchForward ("test", 0));
			Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
			for (int i = 0; i < idx.Count; i++)
				Assert.AreEqual (idx[i], results[i], (i + 1) +". match != " + idx[i] +  " was " + results[i]);
		}
예제 #3
0
        public void TestSearchBackward()
        {
            GapBuffer buffer = new GapBuffer ();
            for (int i = 0; i < 100; i++) {
                buffer.Insert (0, "a");
            }
            var idx = new List<int> (new [] { 0,  buffer.TextLength / 2, buffer.TextLength });

            idx.ForEach (i => buffer.Insert (i, "test"));

            // move gap to the beginning
            buffer.Replace (idx [0], 1, buffer.GetCharAt (idx [0]).ToString ());

            List<int> results = new List<int> ();
            int o = buffer.TextLength;
            while (o > 0 && (o = buffer.LastIndexOf ("test", o - 1, o, StringComparison.Ordinal)) != -1) {
                results.Add (o);
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);

            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [idx.Count - 1 - i], results [i], (i + 1) + ". match != " + idx [idx.Count - 1 - i] + " was " + results [i]);

            // move gap to the middle
            buffer.Replace (idx [1], 1, buffer.GetCharAt (idx [1]).ToString ());

            results = new List<int> ();
            o = buffer.TextLength - 1;
            while (o > 0 && (o = buffer.LastIndexOf ("test", o - 1, o, StringComparison.Ordinal)) != -1) {
                results.Add (o);
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [idx.Count - 1 - i], results [i], (i + 1) + ". match != " + idx [idx.Count - 1 - i] + " was " + results [i]);

            // move gap to the end
            buffer.Replace (idx [2], 1, buffer.GetCharAt (idx [2]).ToString ());

            results = new List<int> ();
            o = buffer.TextLength - 1;
            while (o > 0 && (o = buffer.LastIndexOf ("test", o - 1, o, StringComparison.Ordinal)) != -1) {
                results.Add (o);
            }

            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx [idx.Count - 1 - i], results [i], (i + 1) + ". match != " + idx [idx.Count - 1 - i] + " was " + results [i]);

            // move gap to the end
            buffer.Replace (buffer.TextLength - 1, 1, buffer.GetCharAt (buffer.TextLength - 1).ToString ());

            results = new List<int> ();
            o = buffer.TextLength - 1;
            while (o > 0 && (o = buffer.LastIndexOf ("test", o - 1, o, StringComparison.Ordinal)) != -1) {
                results.Add (o);
            }
            Assert.AreEqual (idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
                Assert.AreEqual (idx[idx.Count -  1 - i], results[i], (i + 1) +". match != " + idx[idx.Count -  1 - i] +  " was " + results[i]);
        }
        public void TestSearchForward()
        {
            GapBuffer buffer = new GapBuffer();

            for (int i = 0; i < 100; i++)
            {
                buffer.Insert(0, "a");
            }
            var idx = new List <int> (new [] { 0, buffer.TextLength / 2, buffer.TextLength });

            idx.ForEach(i => buffer.Insert(i, "test"));

            // move gap to the beginning
            buffer.Replace(idx [0], 1, buffer.GetCharAt(idx [0]).ToString());

            List <int> results = new List <int> ();

            int o = 0;

            while ((o = buffer.IndexOf("test", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                results.Add(o);
                o++;
            }


            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);
            }

            // move gap to the middle
            buffer.Replace(idx [1], 1, buffer.GetCharAt(idx [1]).ToString());

            results = new List <int> ();
            o       = 0;
            while ((o = buffer.IndexOf("test", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                results.Add(o);
                o++;
            }

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);
            }

            // move gap to the end
            buffer.Replace(idx [2], 1, buffer.GetCharAt(idx [2]).ToString());

            results = new List <int> ();
            o       = 0;
            while ((o = buffer.IndexOf("test", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                results.Add(o);
                o++;
            }

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx [i], results [i], (i + 1) + ". match != " + idx [i] + " was " + results [i]);
            }

            // move gap to the end
            buffer.Replace(buffer.TextLength - 1, 1, buffer.GetCharAt(buffer.TextLength - 1).ToString());

            results = new List <int> ();
            o       = 0;
            while ((o = buffer.IndexOf("test", o, buffer.TextLength - o, StringComparison.Ordinal)) >= 0)
            {
                results.Add(o);
                o++;
            }

            Assert.AreEqual(idx.Count, results.Count, "matches != " + idx.Count + " - found:" + results.Count);
            for (int i = 0; i < idx.Count; i++)
            {
                Assert.AreEqual(idx[i], results[i], (i + 1) + ". match != " + idx[i] + " was " + results[i]);
            }
        }