public void HasNextWithNoElements() { this.listIterator = new ListIterator(); Assert.That(this.listIterator.HasNext(), Is.EqualTo(false), "HasNext returns true when its on the last index"); }
static void Main(string[] args) { List list = new List(); list.Add(1); list.Add(2); list.Add(3); IListIterator iterator = list.CreateIterator(); while (iterator.MoveNext()) { Console.WriteLine(iterator.Current); } ReverseList revList = new ReverseList(); revList.Add(1); revList.Add(2); revList.Add(3); IListIterator revIterator = revList.CreateIterator(); while (revIterator.MoveNext()) { Console.WriteLine(revIterator.Current); } Console.Read(); }
public void PrintTestWithEmptyCollection() { this.listIterator = new ListIterator(); Assert.That(() => this.listIterator.Print(), Throws.InvalidOperationException.With.Message.EqualTo( "Invalid Operation!")); }
public void InitializeData() { values = new List <string> { "1", "2" /*, "3", "4"*/ }; this.list = new ListIterator(values); }
public void MoveTestWithNoElements() { this.listIterator = new ListIterator(); this.listIterator.Move(); Assert.That(this.listIterator.CurrentIndex, Is.EqualTo(0), "Move is changing index when the current index is the last"); Assert.That(this.listIterator.Move(), Is.EqualTo(false), "Move returns true when the current index is the last"); }
internal static bool ReorderIncorrectBinaryTransition(IList <ITransition> transitions) { int shiftCount = 0; IListIterator <ITransition> cursor = transitions.ListIterator(); do { if (!cursor.MoveNext()) { return(false); } ITransition next = cursor.Current; if (next is ShiftTransition) { ++shiftCount; } else { if (next is BinaryTransition) { --shiftCount; if (shiftCount <= 0) { cursor.Remove(); } } } }while (shiftCount > 0); if (!cursor.MoveNext()) { return(false); } ITransition next_1 = cursor.Current; while ((next_1 is UnaryTransition) || (next_1 is CompoundUnaryTransition)) { cursor.Remove(); if (!cursor.MoveNext()) { return(false); } next_1 = cursor.Current; } // At this point, the rest of the transition sequence should suffice return(true); }
public static void Main() { IListIterator <string> listIterator = null; string inputLine = Console.ReadLine(); while (inputLine != "END") { string[] commandArgs = inputLine.Split(); string command = commandArgs[0]; try { switch (command) { case "Create": string[] items = commandArgs.Skip(1).ToArray(); listIterator = new ListIterator <string>(items); break; case "HasNext": Console.WriteLine(listIterator.HasNext()); break; case "Move": Console.WriteLine(listIterator.Move()); break; case "Print": Console.WriteLine(listIterator.GetCurrent()); break; } } catch (Exception e) { Console.WriteLine(e.Message); } inputLine = Console.ReadLine(); } }
public static void Main() { IListIterator list = null; var input = string.Empty; while ((input = Console.ReadLine()) != "END") { try { var tokens = input.Split(); switch (tokens[0]) { case "Create": var collection = new List <string>(tokens.Skip(1)); list = new ListIterator(collection); break; case "Move": Console.WriteLine(list.Move()); break; case "HasNext": Console.WriteLine(list.HasNext()); break; case "Print": Console.WriteLine(list.Print()); break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
// Constructor. public ReadOnlyListIterator(IListIterator <T> iterator) { this.iterator = iterator; }
public void Inizialize() { collection = new ListIterator(new string[] { "Pesho", "Gosho", "Ivan" }); }
public void TestPrintMethod_WithEmptyList_ExpextedException() { this.list = new ListIterator(new List <string>()); Assert.Throws <ArgumentException>(() => this.list.Print()); }
// Constructor. public SynchronizedListIterator (IList <T> list, IListIterator <T> iterator) { this.list = list; this.iterator = iterator; }
public TokensAggregate(IListIterator <T> iterator) { _iterator = iterator; }
public void SetUp() { this.arr = new int[] { 1, 2, 3, 4 }; this.listIterator = new ListIterator <int>(this.arr); }
// Constructor. public FixedSizeListIterator(IListIterator <T> iterator) { this.iterator = iterator; }
public UnmodifiableListIterator(IListIterator <T> i) { this.i = i; }
// Constructor. public ReverseIterator(IListIterator <T> iterator) { this.iterator = iterator; }
public void TestListIterator() { string[] args = new string[] { "first", "second", "third" }; this.listIterator = new ListIterator(args); }
public void TestConstructor() { string[] args = new string[] { "first", "second" }; Assert.DoesNotThrow(() => this.listIterator = new ListIterator(args)); }
public static IListIterator <T> CreateUnmodifiableListIterator <T>(IListIterator <T> i) { return(new UnmodifiableListIterator <T>(i)); }
/// <summary> /// In this case, we are starting to build a new subtree when instead /// we should have been combining existing trees. /// </summary> /// <remarks> /// In this case, we are starting to build a new subtree when instead /// we should have been combining existing trees. What we can do is /// find the transitions that build up the next subtree in the gold /// transition list, figure out how it gets applied to a /// BinaryTransition, and make that the next BinaryTransition we /// perform after finishing the subtree. If there are multiple /// BinaryTransitions in a row, we ignore any associated /// UnaryTransitions (unfixable) and try to transition to the final /// state. The assumption is that we can't do anything about the /// incorrect subtrees any more, so we skip them all. /// <br /> /// Sadly, this does not seem to help - the parser gets worse when it /// learns these states /// </remarks> internal static bool ReorderIncorrectShiftTransition(IList <ITransition> transitions) { IList <BinaryTransition> leftoverBinary = Generics.NewArrayList(); while (transitions.Count > 0) { ITransition head = transitions.Remove(0); if (head is ShiftTransition) { break; } if (head is BinaryTransition) { leftoverBinary.Add((BinaryTransition)head); } } if (transitions.Count == 0 || leftoverBinary.Count == 0) { // honestly this is an error we should probably just throw return(false); } int shiftCount = 0; IListIterator <ITransition> cursor = transitions.ListIterator(); BinaryTransition lastBinary = null; while (cursor.MoveNext() && shiftCount >= 0) { ITransition next = cursor.Current; if (next is ShiftTransition) { ++shiftCount; } else { if (next is BinaryTransition) { --shiftCount; if (shiftCount < 0) { lastBinary = (BinaryTransition)next; cursor.Remove(); } } } } if (!cursor.MoveNext() || lastBinary == null) { // once again, an error. even if the sequence of tree altering // gold transitions ends with a BinaryTransition, there should // be a FinalizeTransition after that return(false); } string label = lastBinary.label; if (lastBinary.IsBinarized()) { label = Sharpen.Runtime.Substring(label, 1); } if (lastBinary.side == BinaryTransition.Side.Right) { // When we finally transition all the binary transitions, we // will want to have the new node be the right head. Therefore, // we add a bunch of temporary binary transitions with a right // head, ending up with a binary transition with a right head for (int i = 0; i < leftoverBinary.Count; ++i) { cursor.Add(new BinaryTransition("@" + label, BinaryTransition.Side.Right)); } // use lastBinary.label in case the last transition is temporary cursor.Add(new BinaryTransition(lastBinary.label, BinaryTransition.Side.Right)); } else { cursor.Add(new BinaryTransition("@" + label, BinaryTransition.Side.Left)); for (int i = 0; i < leftoverBinary.Count - 1; ++i) { cursor.Add(new BinaryTransition("@" + label, leftoverBinary[i].side)); } cursor.Add(new BinaryTransition(lastBinary.label, leftoverBinary[leftoverBinary.Count - 1].side)); } return(true); }