public void Enumerable() { LinkedList list = new LinkedList(); list.AddFirst( "third" ); list.AddFirst( "second" ); list.AddFirst( "first" ); int index = 0; foreach(String value in list) { switch(index++) { case 0: Assert.AreEqual( "first", value ); break; case 1: Assert.AreEqual( "second", value ); break; case 2: Assert.AreEqual( "third", value ); break; } } }
private static void Visit(IVertex node, ColorsSet colors, TimestampSet discovery, TimestampSet finish, LinkedList<IVertex> list, ref int time) { colors.Set(node, VertexColor.Gray); discovery.Register(node, time++); foreach(IVertex child in node.Adjacencies) { if (colors.ColorOf(child) == VertexColor.White) { Visit(child, colors, discovery, finish, list, ref time); } } finish.Register(node, time++); #if DEBUG Debug.Assert(discovery.TimeOf(node) < finish.TimeOf(node)); #endif list.AddFirst(node); colors.Set(node, VertexColor.Black); }
public void AddFirst() { LinkedList list = new LinkedList(); list.AddFirst( "third" ); Assert.AreEqual( "third", list.Head ); Assert.AreEqual( 1, list.Count ); list.AddFirst( "second" ); Assert.AreEqual( "second", list.Head ); Assert.AreEqual( 2, list.Count ); list.AddFirst( "first" ); Assert.AreEqual( "first", list.Head ); Assert.AreEqual( 3, list.Count ); }
public void Add() { LinkedList list = new LinkedList(); list.Add( "1" ); Assert.AreEqual( "1", list.Head ); Assert.AreEqual( 1, list.Count ); list.Add( "2" ); Assert.AreEqual( "1", list.Head ); Assert.AreEqual( 2, list.Count ); list.Add( "3" ); Assert.AreEqual( "1", list.Head ); Assert.AreEqual( 3, list.Count ); }
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 static IVertex[] Sort(IVertex[] graphNodes) { ColorsSet colors = new ColorsSet(graphNodes); TimestampSet discovery = new TimestampSet(); TimestampSet finish = new TimestampSet(); LinkedList<IVertex> list = new LinkedList<IVertex>(); int time = 0; foreach(IVertex node in graphNodes) { if (colors.ColorOf(node) == VertexColor.White) { Visit(node, colors, discovery, finish, list, ref time); } } IVertex[] vertices = new IVertex[list.Count]; list.CopyTo(vertices, 0); return vertices; }
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 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 IndexOf2() { LinkedList list = new LinkedList(); list.Add( "1" ); list.Add( "2" ); list.Add( "3" ); list.Add( "4" ); list.Add( "5" ); Assert.AreEqual( 4, list.IndexOf("5") ); Assert.AreEqual( -1, list.IndexOf("10") ); }
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) ); }
private static LinkedList<int> IdentifyBlockBoundaries(string inputString) { var blockBoundaries = new LinkedList<int>(); var previousLine = string.Empty; var currentLine = 0; foreach (var line in new LineReader(() => new StringReader(inputString))) { currentLine++; var trimmedLine = line.TrimStart(' ').TrimEnd(' '); if (trimmedLine.StartsWith("Show") || trimmedLine.StartsWith("Hide") || trimmedLine.StartsWith("# Section:")) { // If the line previous to the Show or Hide line is a comment then we should include that in the block // as it represents the block description. // currentLine > 2 caters for an edge case where the script description is a single line and the first // block has no description. This prevents the script description from being assigned to the first block's description. blockBoundaries.AddLast(previousLine.StartsWith("#") && !previousLine.StartsWith("# Section:") && currentLine > 2 ? currentLine - 2 : currentLine - 1); } previousLine = line; } return blockBoundaries; }
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 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 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)); }