コード例 #1
0
ファイル: TestSetList.cs プロジェクト: waqashaneef/NosDB
        public void TestBasics()
        {
            SetList <int> list = new SetList <int>();

            Assert.IsFalse(list.IsReadOnly);

            for (int i = 512; i >= 0; i--)
            {
                list.Add(i);
            }

            int offset = 0;

            foreach (int item in list)
            {
                Assert.AreEqual(offset++, item);
            }

            Assert.AreEqual(513, offset);
            Assert.AreEqual(513, list.Count);

            list.Clear();
            list.AddRange(new int[] { 5, 10, 20 });
            list.AddRange(new int[] { });

            Assert.AreEqual(3, list.Count);

            Assert.IsTrue(list.Contains(20));
            Assert.IsTrue(list.Remove(20));

            Assert.IsFalse(list.Contains(20));
            Assert.IsFalse(list.Remove(20));

            Assert.AreEqual(2, list.Count);

            int pos;

            list.Add(10, out pos);
            Assert.AreEqual(1, pos);
            Assert.AreEqual(2, list.Count);

            int[] items = new int[2];
            list.CopyTo(items, 0);
            Assert.AreEqual(5, items[0]);
            Assert.AreEqual(10, items[1]);

            items = list.ToArray();
            Assert.AreEqual(5, items[0]);
            Assert.AreEqual(10, items[1]);

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

            foreach (int i in list)
            {
                tmp.Add(i);
            }
            Assert.AreEqual(2, tmp.Count);
            Assert.AreEqual(5, tmp[0]);
            Assert.AreEqual(10, tmp[1]);
        }