public void Insert() { RleArray <char> chars = new RleArray <char>(); Set(chars, "aabb"); chars.Insert(2, 'a'); Assert.AreEqual(5, chars.Count); Assert.AreEqual('a', chars[0]); Assert.AreEqual('a', chars[1]); Assert.AreEqual('a', chars[2]); Assert.AreEqual('b', chars[3]); Assert.AreEqual('b', chars[4]); MyAssert.Throws <ArgumentOutOfRangeException>(delegate { chars[-1].ToString(); }); MyAssert.Throws <ArgumentOutOfRangeException>(delegate { chars[5].ToString(); }); Set(chars, "aabb"); chars.Insert(2, 'b'); Assert.AreEqual(5, chars.Count); Assert.AreEqual('a', chars[0]); Assert.AreEqual('a', chars[1]); Assert.AreEqual('b', chars[2]); Assert.AreEqual('b', chars[3]); Assert.AreEqual('b', chars[4]); Set(chars, "aabb"); chars.Insert(2, 'c'); Assert.AreEqual(5, chars.Count); Assert.AreEqual("a a c b b", chars.ToString()); Set(chars, "aabb"); chars.Insert(1, 'a'); Assert.AreEqual(5, chars.Count); Assert.AreEqual('a', chars[0]); Assert.AreEqual('a', chars[1]); Assert.AreEqual('a', chars[2]); Assert.AreEqual('b', chars[3]); Assert.AreEqual('b', chars[4]); Set(chars, "aabb"); chars.Insert(1, 'c'); Assert.AreEqual(5, chars.Count); Assert.AreEqual('a', chars[0]); Assert.AreEqual('c', chars[1]); Assert.AreEqual('a', chars[2]); Assert.AreEqual('b', chars[3]); Assert.AreEqual('b', chars[4]); }
static void Test_Insert() { RleArray <char> chars = new RleArray <char>(); Set(chars, "aabb"); chars.Insert(2, 'a'); TestUtl.AssertEquals(5, chars.Count); TestUtl.AssertEquals('a', chars[0]); TestUtl.AssertEquals('a', chars[1]); TestUtl.AssertEquals('a', chars[2]); TestUtl.AssertEquals('b', chars[3]); TestUtl.AssertEquals('b', chars[4]); try{ chars[-1].ToString(); throw new Exception(); } catch (Exception ex) { TestUtl.AssertExceptionType <ArgumentOutOfRangeException>(ex); } try{ chars[5].ToString(); throw new Exception(); } catch (Exception ex) { TestUtl.AssertExceptionType <ArgumentOutOfRangeException>(ex); } Set(chars, "aabb"); chars.Insert(2, 'b'); TestUtl.AssertEquals(5, chars.Count); TestUtl.AssertEquals('a', chars[0]); TestUtl.AssertEquals('a', chars[1]); TestUtl.AssertEquals('b', chars[2]); TestUtl.AssertEquals('b', chars[3]); TestUtl.AssertEquals('b', chars[4]); Set(chars, "aabb"); chars.Insert(2, 'c'); TestUtl.AssertEquals(5, chars.Count); TestUtl.AssertEquals("a a c b b", chars.ToString()); Set(chars, "aabb"); chars.Insert(1, 'a'); TestUtl.AssertEquals(5, chars.Count); TestUtl.AssertEquals('a', chars[0]); TestUtl.AssertEquals('a', chars[1]); TestUtl.AssertEquals('a', chars[2]); TestUtl.AssertEquals('b', chars[3]); TestUtl.AssertEquals('b', chars[4]); Set(chars, "aabb"); chars.Insert(1, 'c'); TestUtl.AssertEquals(5, chars.Count); TestUtl.AssertEquals('a', chars[0]); TestUtl.AssertEquals('c', chars[1]); TestUtl.AssertEquals('a', chars[2]); TestUtl.AssertEquals('b', chars[3]); TestUtl.AssertEquals('b', chars[4]); }