當前位置: 首頁>>代碼示例>>C#>>正文


C# List.Insert方法代碼示例

本文整理匯總了C#中NUnit.Framework.List.Insert方法的典型用法代碼示例。如果您正苦於以下問題:C# List.Insert方法的具體用法?C# List.Insert怎麽用?C# List.Insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NUnit.Framework.List的用法示例。


在下文中一共展示了List.Insert方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DoubleTest

 public void DoubleTest()
 {
     List<int> myList = new List<int>();
     myList.Insert(0, 1);
     myList.Insert(1, 2);
     myList.Insert(2, 3);
     List<int> changedList = Map.MapFunction(myList, x => x * 2);
     Assert.AreEqual(2, changedList[0]);
     Assert.AreEqual(4, changedList[1]);
     Assert.AreEqual(6, changedList[2]);
 }
開發者ID:Julia-Berezhnova,項目名稱:Semester-2,代碼行數:11,代碼來源:MapFunctionTest.cs

示例2: OriginalListDoesntChangeTest

 public void OriginalListDoesntChangeTest()
 {
     List<int> myList = new List<int>();
     myList.Insert(0, 5);
     Map.MapFunction(myList, x => x * x);
     Assert.AreEqual(5, (myList[0]));
 }
開發者ID:Julia-Berezhnova,項目名稱:Semester-2,代碼行數:7,代碼來源:MapFunctionTest.cs

示例3: SquareTest

 public void SquareTest()
 {
     List<int> myList = new List<int>();
     myList.Insert(0, 5);
     List<int> changedList = Map.MapFunction(myList, x => x * x);
     Assert.AreEqual(25, (changedList[0]));
 }
開發者ID:Julia-Berezhnova,項目名稱:Semester-2,代碼行數:7,代碼來源:MapFunctionTest.cs

示例4: EvaluateScriptWithJqueryAsync

 public static async Task<String> EvaluateScriptWithJqueryAsync(params String[] sources)
 {
     var list = new List<String>(sources);
     list.Insert(0, Sources.Jquery);
     var cfg = Configuration.Default.WithDefaultLoader(setup => setup.IsResourceLoadingEnabled = true).WithJavaScript();
     var scripts = "<script>" + String.Join("</script><script>", list) + "</script>";
     var html = "<!doctype html><div id=result></div>" + scripts;
     var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(html));
     return document.GetElementById("result").InnerHtml;
 }
開發者ID:AlgorithmsAreCool,項目名稱:AngleSharp.Scripting,代碼行數:10,代碼來源:JqueryTests.cs

示例5: ReportListGenerator

 public IEnumerable<Report> ReportListGenerator()
 {
     int iCount = 5;
     var x = new List<Report>();
     while (iCount > 0)
     {
         x.Insert(0, new Report() { ID = iCount, Name = "Report #" + iCount });
         iCount--;
     }
     return x.AsEnumerable();
 }
開發者ID:SirPhobos,項目名稱:RMM,代碼行數:11,代碼來源:ReportHubServiceTests.cs

示例6: UnionQueryReuse

        public void UnionQueryReuse()
        {
            List<int> first = new List<int> { 1, 2 };
            List<int> second = new List<int> { 2, 3 };
            IEnumerable<int> enumerable = first.Union(second);

            enumerable.AssertEqual(1, 2, 3);

            first.Insert(0, 0);
            second.Add(4);
            enumerable.AssertEqual(0, 1, 2, 3, 4);
        }
開發者ID:barisertekin,項目名稱:LINQlone,代碼行數:12,代碼來源:UnionTests.cs

示例7: TestExecute

        public void TestExecute()
        {
            var list = new List<int> ();
            Action<int,int> exeAction = (i, v) => list.Insert (i, v);
            Action<int,int> undoAction = (i, v) => list.RemoveAt (i);

            var command = new Command<int,int>(0,4,exeAction, undoAction);
            command.Execute ();
            Assert.AreEqual (1, list.Count);
            Assert.AreEqual (list[0],4);

            command.Undo ();
            Assert.AreEqual (0, list.Count);
        }
開發者ID:magerate,項目名稱:Commands,代碼行數:14,代碼來源:Command2Test.cs

示例8: ListCollectgionInitialization

        public void ListCollectgionInitialization()
        {
            var people = new List<Person>
            {
                new Person { Name = "Matteo", Age = 12 }, //equivalent to people.Add(new Person { Name = "Matteo", Age = 12 }); add the object to the end of the list
                new Person { Name = "Valerio", Age = 13 }
            };

            people.Insert(1, new Person { Name = "Antonio", Age = 23 });

            foreach (var person in people)
            {
                Console.WriteLine(person.Name);
            }
        }
開發者ID:pierangelim,項目名稱:advanced-c-sharp,代碼行數:15,代碼來源:GenericCollections.cs

示例9: AddReplicaTest

        public void AddReplicaTest()
        {
            Assert.IsTrue(this.repTable.Exists(), "RTable does not exist");

            View v = this.configurationWrapper.GetWriteView();
            int index = v.Chain.Count - 1;
            string accountName = v.GetReplicaInfo(index).StorageAccountName;

            List<ReplicaInfo> replicas = new List<ReplicaInfo>();
            for (int i = 0; i <= index; i++)
            {
                replicas.Add(v.Chain[i].Item1);
            }

            //Just add the last replica again at the head to simulate a new replica addition
            ReplicaInfo newReplica = new ReplicaInfo()
            {
                StorageAccountName = accountName,
            };

            //Add the new replica at the head
            replicas.Insert(0, newReplica);

            int readViewHeadIndex = 1;
            this.UpdateConfiguration(replicas, readViewHeadIndex);

            // validate all state
            Assert.IsFalse(this.configurationWrapper.IsViewStable(), "View = {0}", this.configurationWrapper.GetWriteView().IsStable);
            View readView = this.configurationWrapper.GetReadView();
            View writeView = this.configurationWrapper.GetWriteView();
            long viewIdAfterFirstUpdate = writeView.ViewId;

            // Actually, both read and write views point to the same view
            Assert.IsTrue(readView == writeView);

            int headIndex = 0;
            long readViewHeadViewId = readView.GetReplicaInfo(readViewHeadIndex).ViewInWhichAddedToChain;
            Assert.IsTrue(writeView.GetReplicaInfo(headIndex).ViewInWhichAddedToChain == readViewHeadViewId + 1);

            //Now, make the read and write views the same
            this.UpdateConfiguration(replicas, 0);
            // validate all state
            Assert.IsTrue(this.configurationWrapper.IsViewStable());
            readView = this.configurationWrapper.GetReadView();
            writeView = this.configurationWrapper.GetWriteView();
            Assert.IsTrue(readView == writeView);
            Assert.IsTrue(readView.ViewId == viewIdAfterFirstUpdate + 1);
        }
開發者ID:farukc,項目名稱:rtable,代碼行數:48,代碼來源:RTableConfigurationServiceTests.cs

示例10: Insert

		public void Insert()
		{
			List<string> applied = new List<string> { "foo", "bar", "baz" };

			Action reset = () => Assert.Fail ("Reset should not be called");
			Action<object, int, bool> insert = (o, i, create) => {
				Assert.That (create, Is.True);
				applied.Insert (i, (string) o);
			};
			Action<object, int> removeAt = (o, i) => applied.RemoveAt (i);

			var items = new ObservableCollection<string> (applied);
			items.CollectionChanged += (s, e) => e.Apply (insert, removeAt, reset);

			items.Insert (1, "monkey");

			CollectionAssert.AreEqual (items, applied);
		}
開發者ID:Costo,項目名稱:Xamarin.Forms,代碼行數:18,代碼來源:NotifyCollectionChangedEventArgsExtensionsTests.cs

示例11: TestStack

        public void TestStack()
        {
            Stack<string> stack = new Stack<string>();

            stack.Push("1");
            stack.Push("2");
            stack.Push("3");
            stack.Push("4");
            List<string> list = new List<string>();

            while (stack.Count >0)
            {
                list.Insert(0,stack.Pop());
            }
            foreach (string s in list)
            {
                Console.WriteLine(s);
            }
        }
開發者ID:luckyzhiqiu,項目名稱:ProtoBuffer,代碼行數:19,代碼來源:TestNormal.cs

示例12: diff_charsToLinesTest

        public void diff_charsToLinesTest()
        {
            diff_match_patchTest dmp = new diff_match_patchTest();

              Assert.AreEqual(new Diff(Operation.EQUAL, "a"),
              new Diff(Operation.EQUAL, "a"));

              // Convert chars up to lines.
              List<Diff> diffs = new List<Diff> {
              new Diff(Operation.EQUAL, "\u0001\u0002\u0001"),
              new Diff(Operation.INSERT, "\u0002\u0001\u0002")};
              List<string> tmpVector = new List<string>();
              tmpVector.Add("");
              tmpVector.Add("alpha\n");
              tmpVector.Add("beta\n");
              dmp.diff_charsToLines(diffs, tmpVector);
              CollectionAssert.AreEqual(new List<Diff> {
              new Diff(Operation.EQUAL, "alpha\nbeta\nalpha\n"),
              new Diff(Operation.INSERT, "beta\nalpha\nbeta\n")}, diffs);

              // More than 256 to reveal any 8-bit limitations.
              int n = 300;
              tmpVector.Clear();
              StringBuilder lineList = new StringBuilder();
              StringBuilder charList = new StringBuilder();
              for (int x = 1; x < n + 1; x++) {
            tmpVector.Add(x + "\n");
            lineList.Append(x + "\n");
            charList.Append(Convert.ToChar (x));
              }
              Assert.AreEqual(n, tmpVector.Count);
              string lines = lineList.ToString();
              string chars = charList.ToString();
              Assert.AreEqual(n, chars.Length);
              tmpVector.Insert(0, "");
              diffs = new List<Diff> {new Diff(Operation.DELETE, chars)};
              dmp.diff_charsToLines(diffs, tmpVector);
              CollectionAssert.AreEqual(new List<Diff>
              {new Diff(Operation.DELETE, lines)}, diffs);
        }
開發者ID:Smarsh,項目名稱:Google-Diff-Match-Patch,代碼行數:40,代碼來源:DiffMatchPatchTest.cs

示例13: TestAddGetRemove

		public void TestAddGetRemove ()
		{
			var foos = new List<string> (){ "1", "2", "3" };
			Assert.AreEqual (3, foos.Count);

			foos [2] = "MooFoey!";
			Assert.IsTrue (foos.Contains ("MooFoey!"));
			Assert.AreEqual ("MooFoey!", foos [2]);

			foos.Add ("Hello!");
			Assert.AreEqual (4, foos.Count);

			foos.Remove ("Hello!");
			Assert.AreEqual (3, foos.Count);

			foos.Insert (1, "foomoey!");
			Assert.AreEqual (4, foos.Count);

			foos.InsertRange (1, new List<string>{ "1", "2", "3" }); 
			Assert.AreEqual (7, foos.Count);

			foos.Clear ();
			Assert.IsEmpty (foos);
		}
開發者ID:caloggins,項目名稱:DOT-NET-on-Linux,代碼行數:24,代碼來源:ListExampleTests.cs

示例14: diff_linesToCharsTest

        public void diff_linesToCharsTest()
        {
            var dmp = new diff_match_patchTest();
            // Convert lines down to characters.
            var tmpVector = new List<string>{"", "alpha\n", "beta\n"};
            Object[] result = dmp.diff_linesToChars("alpha\nbeta\nalpha\n", "beta\nalpha\nbeta\n");
            Assert.AreEqual("\u0001\u0002\u0001", result[0]);
            Assert.AreEqual("\u0002\u0001\u0002", result[1]);
            CollectionAssert.AreEqual(tmpVector, (List<string>)result[2]);

            tmpVector.Clear();
            tmpVector.Add("");
            tmpVector.Add("alpha\r\n");
            tmpVector.Add("beta\r\n");
            tmpVector.Add("\r\n");
            result = dmp.diff_linesToChars("", "alpha\r\nbeta\r\n\r\n\r\n");
            Assert.AreEqual("", result[0]);
            Assert.AreEqual("\u0001\u0002\u0003\u0003", result[1]);
            CollectionAssert.AreEqual(tmpVector, (List<string>)result[2]);

            tmpVector.Clear();
            tmpVector.Add("");
            tmpVector.Add("a");
            tmpVector.Add("b");
            result = dmp.diff_linesToChars("a", "b");
            Assert.AreEqual("\u0001", result[0]);
            Assert.AreEqual("\u0002", result[1]);
            CollectionAssert.AreEqual(tmpVector, (List<string>)result[2]);

            // More than 256 to reveal any 8-bit limitations.
            const int n = 300;
            tmpVector.Clear();
            var lineList = new StringBuilder();
            var charList = new StringBuilder();
            for (int x = 1; x < n + 1; x++) {
                tmpVector.Add(x + "\n");
                lineList.Append(x + "\n");
                charList.Append(Convert.ToChar(x));
            }
            Assert.AreEqual(n, tmpVector.Count);
            string lines = lineList.ToString();
            string chars = charList.ToString();
            Assert.AreEqual(n, chars.Length);
            tmpVector.Insert(0, "");
            result = dmp.diff_linesToChars(lines, "");
            Assert.AreEqual(chars, result[0]);
            Assert.AreEqual("", result[1]);
            CollectionAssert.AreEqual(tmpVector, (List<string>)result[2]);
        }
開發者ID:i-e-b,項目名稱:DiffTools,代碼行數:49,代碼來源:DiffMatchPatchTest.cs

示例15: MakeContextMenu_CheckedStates_SelCoversMultiSideBySideAnn

		public void MakeContextMenu_CheckedStates_SelCoversMultiSideBySideAnn()
		{
			// Provide hvoTagPoss and SelectedWfics, create a markup tag and examine it.
			// Setup the SelectedWfics property to include 2 words
			List<int> tempList = new List<int>();
			tempList.Add(m_hvoWfics[0]);
			tempList.Add(m_hvoWfics[1]);
			m_tagChild.SelectedWfics = tempList;

			// Make a tag for 1st selection
			int itestItem1 = 0; // first tag in list
			m_tagChild.CallMakeTextTagAnnotation(m_possTagHvos[itestItem1]);

			// Setup the SelectedWfics property to include one more word
			tempList.Clear();
			tempList.Add(m_hvoWfics[2]);
			tempList.Add(m_hvoWfics[3]);
			m_tagChild.SelectedWfics = tempList;

			// Make a tag for 2nd selection
			int itestItem2 = 1; // 2nd tag in list
			m_tagChild.CallMakeTextTagAnnotation(m_possTagHvos[itestItem2]);

			// Setup selection to cover part of first tag, and all of second
			tempList.Insert(0, m_hvoWfics[1]);
			m_tagChild.SelectedWfics = tempList;

			// SUT; make menu while selected phrase has 2 side-by-side tags
			ContextMenuStrip menu = new ContextMenuStrip();
			m_tagChild.CallMakeContextMenuForTags(menu, m_textMarkupTags);

			// Verification of SUT; Two should be checked and that in a submenu
			ToolStripMenuItem subList = AssertHasMenuWithText(menu.Items, kFTO_RRG_Semantics, 3);
			Assert.IsNotNull(subList, "No " + kFTO_RRG_Semantics + " menu!?");
			ToolStripItemCollection subMenu = subList.DropDownItems;
			bool[] expectedStates = new bool[subMenu.Count];
			expectedStates[itestItem1] = true;
			expectedStates[itestItem2] = true;
			AssertMenuCheckState(expectedStates, subMenu);
		}
開發者ID:sillsdev,項目名稱:WorldPad,代碼行數:40,代碼來源:InterlinTaggingTests.cs


注:本文中的NUnit.Framework.List.Insert方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。