ToArray() public method

public ToArray ( Type type ) : Array
type System.Type
return System.Array
Beispiel #1
0
		public static IVertex[] Sort(IVertex[] graphNodes)
		{
			ColorsSet colors = new ColorsSet(graphNodes);
			TimestampSet discovery = new TimestampSet();
			TimestampSet finish = new TimestampSet();
			LinkedList list = new LinkedList();

			int time = 0;

			foreach(IVertex node in graphNodes)
			{
				if (colors.ColorOf(node) == VertexColor.White)
				{
					Visit(node, colors, discovery, finish, list, ref time);
				}
			}

			return (IVertex[]) list.ToArray(typeof(IVertex));
		}
		public void RemoveBoundary1()
		{
			LinkedList list = new LinkedList();
			
			list.Add( "1" );

			list.Add( "2" );

			list.Add( "3" );

			list.Remove( "1" );

			Assert.AreEqual( "2", list.Head );
			Assert.AreEqual( 2, list.Count );

			String[] array = (String[]) list.ToArray( typeof(String) );
			Assert.AreEqual( "2,3", String.Join(",", array) );
		}
		public void ToArray()
		{
			LinkedList list = new LinkedList();
			
			list.AddFirst( "third" );
			list.AddFirst( "second" );
			list.AddFirst( "first" );

			String[] values = (String[]) list.ToArray( typeof(String) );
			Assert.AreEqual( "first", values[0] );
			Assert.AreEqual( "second", values[1] );
			Assert.AreEqual( "third", values[2] );
		}
		public void Replace4()
		{
			LinkedList list = new LinkedList();
			
			list.Add( "0" );
			list.Add( "1" );
			list.Add( "2" );
			list.Add( "3" );
			Assert.IsTrue( list.Replace("2", "x") ); 

			Assert.AreEqual( 4, list.Count );
			
			String[] array = (String[]) list.ToArray( typeof(String) );
			Assert.AreEqual( "0,1,x,3", String.Join(",", array) );
		}
		public void Replace3()
		{
			LinkedList list = new LinkedList();
			
			list.Add( "0" );
			list.Add( "1" );
			Assert.IsFalse( list.Replace("11", "x") ); 

			Assert.AreEqual( 2, list.Count );
			
			String[] array = (String[]) list.ToArray( typeof(String) );
			Assert.AreEqual( "0,1", String.Join(",", array) );
		}
		public void Insert2bis()
		{
			LinkedList list = new LinkedList();
			
			list.Add( "0" );
			list.Add( "1" );
			list.Add( "2" );
			list.Add( "3" );
			list.Add( "4" );
			list.Add( "5" );
			list.Insert(2, "x");

			Assert.AreEqual( 7, list.Count );
			
			String[] array = (String[]) list.ToArray( typeof(String) );
			Assert.AreEqual( "0,1,x,2,3,4,5", String.Join(",", array) );
		}
		public void Insert2()
		{
			LinkedList list = new LinkedList();
			
			list.Add( "1" );
			list.Add( "2" );
			list.Add( "3" );
			list.Insert(2, "x");

			Assert.AreEqual( 4, list.Count );
			
			String[] array = (String[]) list.ToArray( typeof(String) );
			Assert.AreEqual( "1,2,x,3", String.Join(",", array) );
		}
		public void RemoveMiddle2()
		{
			LinkedList list = new LinkedList();
			
			list.Add( "1" );
			list.Add( "2" );
			list.Add( "3" );
			list.Add( "4" );
			list.Add( "5" );

			list.Remove( "3" );

			Assert.AreEqual( "1", list.Head );
			Assert.AreEqual( 4, list.Count );
			
			String[] array = (String[]) list.ToArray( typeof(String) );
			Assert.AreEqual( "1,2,4,5", String.Join(",", array) );
		}
Beispiel #9
0
		public void Replace3()
		{
			LinkedList list = new LinkedList();
			
			list.Add( "0" );
			list.Add( "1" );
			Assert.IsFalse( list.Replace("11", "x"), "Successfully replaced 11 with x when it should have failed." ); 

			Assert.AreEqual( 2, list.Count );
			
			String[] array = (String[]) list.ToArray( typeof(String) );
			Assert.AreEqual( "0,1", String.Join(",", array) );
		}
		public void Insert1_AfterReplacingHeadWithAddFirst()
		{
			LinkedList list = new LinkedList();

			list.Add("2");
			list.AddFirst("1");
			list.Insert(1, "x");

			Assert.AreEqual(3, list.Count);

			String[] array = (String[])list.ToArray(typeof(String));
			Assert.AreEqual("1,x,2", String.Join(",", array));
		}