public void AddAfterTest() { Node <char> node = new Node <char>() { Data = 'H' }; node.AddAfter(new Node <char>() { Data = 'o' }); node.NextNode.AddAfter(new Node <char>() { Data = '!' }); node.AddAfter(new Node <char>() { Data = 'l' }); node.AddAfter(new Node <char>() { Data = 'l' }); node.AddAfter(new Node <char>() { Data = 'e' }); var actual = GetStringFromNode(node); var expected = "Hello!"; Assert.AreEqual(expected, actual); new Node <char>().AddAfter(null); }
public void AddAfterTest() { Node<char> node = new Node<char>() {Data = 'H'}; node.AddAfter(new Node<char>(){Data = 'o'}); node.NextNode.AddAfter(new Node<char>() { Data = '!' }); node.AddAfter(new Node<char>() { Data = 'l' }); node.AddAfter(new Node<char>() { Data = 'l' }); node.AddAfter(new Node<char>() { Data = 'e' }); var actual=GetStringFromNode(node); var expected = "Hello!"; Assert.AreEqual(expected,actual); new Node<char>().AddAfter(null); }
public void RemoveTest() { var head = new Node<char>() { Data = 'H' }; var last=new Node<char>(){Data = '!'}; head.AddAfter(new Node<char>() { Data = 'o' }); head.NextNode.AddAfter(last); head.AddAfter(new Node<char>() { Data = 'l' }); head.AddAfter(new Node<char>() { Data = 'l' }); head.AddAfter(new Node<char>() { Data = 'e' }); var node = head.NextNode.NextNode; head.NextNode.BreakLinks(); head.BreakLinks(); last.BreakLinks(); var actual = GetStringFromNode(node); var expected = "llo"; Assert.AreEqual(expected, actual); var singleNode=new Node<char>(); singleNode.BreakLinks(); }
public void RemoveTest() { var head = new Node <char>() { Data = 'H' }; var last = new Node <char>() { Data = '!' }; head.AddAfter(new Node <char>() { Data = 'o' }); head.NextNode.AddAfter(last); head.AddAfter(new Node <char>() { Data = 'l' }); head.AddAfter(new Node <char>() { Data = 'l' }); head.AddAfter(new Node <char>() { Data = 'e' }); var node = head.NextNode.NextNode; head.NextNode.BreakLinks(); head.BreakLinks(); last.BreakLinks(); var actual = GetStringFromNode(node); var expected = "llo"; Assert.AreEqual(expected, actual); var singleNode = new Node <char>(); singleNode.BreakLinks(); }
public void Step() { Node <RCoroutine>?nextNode; for (var n = itrNode = coroutines.First; n != null; n = itrNode = nextNode) { bool remaining = n.obj.ienum.MoveNext(); if (n.Deleted) { if (coroutines.Count != 0) { throw new Exception($"Since a coroutine node was externally deleted, expected all nodes to be " + $"deleted, but {coroutines.Count} yet exist."); } break; } else if (remaining) { if (n.obj.ienum.Current is IEnumerator ienum) { nextNode = coroutines.AddAfter(n, new RCoroutine(ienum, n, n.obj.droppable)); coroutines.Remove(n); } else { nextNode = n.Next; } } else { if (n.obj.parent != null) { coroutines.InsertAfter(n, n.obj.parent); } nextNode = n.Next; coroutines.Remove(n); } } //Important for break case. itrNode = null; }
protected override object SolvePartTwo() { var m = Regex.Match(Input, @"(\d+).*?(\d+)"); int[] input = new int[] { int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value) }; input[1] *= 100; Dictionary <int, long> players = new Dictionary <int, long>(); for (int i = 0; i < input[0]; i++) { players.Add(i, 0); } LinkedList <long> marbles = new LinkedList <long>(); Node node = new Node(); node.Value = 0; node.Next = node; node.Previous = node; for (int i = 1; i < input[1]; i++) { if (i % 23 == 0) { for (int j = 0; j < 7; j++) { node = node.Previous; } players[i % players.Count] += i + node.Value; node = node.Remove(); } else { node = node.Next; node = node.AddAfter(i); } } return(players.Values.Max()); }
/* * adds a control to wysiwyg surface */ private void AddControlToSurface( Node ip, Node controlToAddNode) { // defaulting to currently selected if exists, otherwise main surface string dna = SelectedControlDna ?? DataSource["controls"].Dna; string position = "after"; if (ip.Contains("where")) { if (ip["where"].ContainsValue("dna")) { dna = ip["where"]["dna"].Get <string>(); } if (ip["where"].ContainsValue("position")) { position = ip["where"]["position"].Get <string>(); } } if (dna == DataSource["controls"].Dna) { // main surface is destination, making sure position gets correct if user chose "before", and we can do such a thing if (position == "before" && DataSource["controls"].Count > 0) { dna = DataSource["controls"][0].Dna; } else { position = "child"; } } if (!controlToAddNode.Contains("id") && string.IsNullOrEmpty(controlToAddNode.Get <string>())) { GetNextAvailableControlId(controlToAddNode); } else if (controlToAddNode.Contains("id")) { if (controlToAddNode.Value != null) { throw new ArgumentException("either supply [id] or value, not both"); } // moving id into value for consistency controlToAddNode.Value = controlToAddNode["id"].Get <string>(); controlToAddNode["id"].UnTie(); } AddToUndoChain(!ip.ContainsValue("skip-undo") || !ip["skip-undo"].Get <bool>()); Node destinationNode = DataSource.FindDna(dna); switch (position) { case "before": destinationNode.AddBefore(controlToAddNode); break; case "after": destinationNode.AddAfter(controlToAddNode); break; case "child": { if (destinationNode.Dna == DataSource["controls"].Dna) { destinationNode.Add(controlToAddNode); } else { // verifying control supports having children, otherwise defaulting to 'after' Node inspectParent = new Node(); inspectParent["inspect"].Value = null; RaiseActiveEvent( "magix.forms.controls." + destinationNode.Name, inspectParent); if (inspectParent["magix.forms.create-web-part"]["controls"][0].Contains("controls")) { destinationNode["controls"].Add(controlToAddNode); } else { Node msg = new Node(); msg["message"].Value = "control didn't support children, added the control after your selection"; msg["color"].Value = "#ffbbbb"; RaiseActiveEvent( "magix.viewport.show-message", msg); destinationNode.AddAfter(controlToAddNode); // defaulting to after } } } break; default: throw new ArgumentException("only before, after or child are legal positions"); } if (ip.Contains("auto-select") && ip["auto-select"].Get <bool>()) { SelectedControlDna = controlToAddNode.Dna; } BuildForm(); wrp.ReRender(); RaiseSurfaceAndSelectionChangedChanged(); }