コード例 #1
0
        [Test] public void RemoveResetsReferenceTypesToDefault()
        {
            RawList <string> list = new RawList <string>(
                Enumerable.Range(0, 10)
                .Select(i => i.ToString())
                .ToArray());

            // Is the internal array empty if not assigned otherwise?
            if (list.Capacity > list.Count)
            {
                Assert.AreSame(null, list.Data[list.Count]);
            }

            // Adjusting the count shouldn't affect the internal array, just as documented
            list.Count = 0;
            for (int i = 0; i < 10; i++)
            {
                Assert.AreNotSame(null, list.Data[i]);
            }
            list.Count = 10;

            // Check various types of removal and make sure the internal array is reset properly
            {
                // Remove an element
                list.Remove("1");
                Assert.AreSame(null, list.Data[list.Count]);
                list.RemoveAt(5);
                Assert.AreSame(null, list.Data[list.Count]);

                // Remove the last element specifically to tap into a different code path
                list.RemoveAt(list.Count - 1);
                Assert.AreSame(null, list.Data[list.Count]);

                // Remove a range
                list.RemoveRange(0, 5);
                for (int i = list.Count; i < list.Data.Length; i++)
                {
                    Assert.AreSame(null, list.Data[i]);
                }

                // Clear the list
                list.Clear();
                for (int i = list.Count; i < list.Data.Length; i++)
                {
                    Assert.AreSame(null, list.Data[i]);
                }
            }
        }
コード例 #2
0
ファイル: RawListTest.cs プロジェクト: Scottyaim/duality
		[Test] public void RemoveResetsReferenceTypesToDefault()
		{
			RawList<string> list = new RawList<string>(Enumerable.Range(0, 10).Select(i => i.ToString()));

			// Is the internal array empty if not assigned otherwise?
			if (list.Capacity > list.Count)
				Assert.AreSame(null, list.Data[list.Count]);

			// Adjusting the count shouldn't affect the internal array, just as documented
			list.Count = 0;
			for (int i = 0; i < 10; i++)
			{
				Assert.AreNotSame(null, list.Data[i]);
			}
			list.Count = 10;

			// Check various types of removal and make sure the internal array is reset properly
			{
				// Remove an element
				list.Remove("1");
				Assert.AreSame(null, list.Data[list.Count]);
				list.RemoveAt(5);
				Assert.AreSame(null, list.Data[list.Count]);

				// Remove a range
				list.RemoveRange(0, 5);
				for (int i = list.Count; i < list.Data.Length; i++)
				{
					Assert.AreSame(null, list.Data[i]);
				}

				// Clear the list
				list.Clear();
				for (int i = list.Count; i < list.Data.Length; i++)
				{
					Assert.AreSame(null, list.Data[i]);
				}
			}
		}