public void TestPush() { int value = Generator.GetInt32(); var stack = ImmutableTreeStack.Create <int>(); Assert.Empty(stack); // Push doesn't change the original stack stack.Push(value); Assert.Empty(stack); stack = stack.Push(value); Assert.Single(stack); Assert.Equal(value, stack.Peek()); int[] expected = { value }; int[] actual = stack.ToArray(); Assert.Equal(expected, actual); // Test through the IImmutableStack<T> interface IImmutableStack <int> immutableStack = stack; immutableStack.Push(Generator.GetInt32()); Assert.Equal(expected, immutableStack); int nextValue = Generator.GetInt32(); immutableStack = immutableStack.Push(nextValue); Assert.Equal(new[] { nextValue, value }, immutableStack); }
static IImmutableStack <T> GetNextElementInHierarchyCore <T>(IImmutableStack <T> rootStack, Func <T, IList <T> > getChildren, Func <IList <T>, T, int> indedOf, bool skipChildren) where T : class { var currentElement = rootStack.Peek(); var children = getChildren(currentElement); if (!skipChildren && children.Any()) { return(rootStack.Push(children.First())); } var parents = rootStack.Pop(); var parent = parents.FirstOrDefault(); if (parent == null) { return(rootStack); } var neighbors = getChildren(parent); var index = indedOf(neighbors, currentElement); if (index < neighbors.Count - 1) { return(parents.Push(neighbors[index + 1])); } return(GetNextElementInHierarchyCore(parents, getChildren, indedOf, skipChildren: true)); }
/// <summary> /// A test for Empty /// </summary> /// <typeparam name="T">The type of elements held in the stack.</typeparam> private void EmptyTestHelper <T>() where T : new() { IImmutableStack <T> actual = ImmutableStack <T> .Empty; Assert.NotNull(actual); Assert.True(actual.IsEmpty); AssertAreSame(ImmutableStack <T> .Empty, actual.Clear()); AssertAreSame(ImmutableStack <T> .Empty, actual.Push(new T()).Clear()); }
internal sealed override HarshProvisionerContextBase PushStateCore(Object state) { if (state == null) { throw Logger.Fatal.ArgumentNull(nameof(state)); } return(this.With(c => c._stateStack, _stateStack.Push(state))); }
private static IImmutableStack <object> GetLogicalOperationStack() { IImmutableStack <object> empty = (IImmutableStack <object>)CallContext.LogicalGetData(LogicalOperation.CallContextDataSlotName); if (empty == null) { empty = ImmutableLogicalOperationStack <object> .Empty; if (LogicalOperation.IsRunningInAdapter) { empty = empty.Push(new object()); } LogicalOperation.UpdateImmutableStack(empty); } return(empty); }
private DocumentNode CreateDelegationQuery( OperationType operation, IImmutableStack <SelectionPathComponent> path, FieldNode requestedField) { if (!path.Any()) { path = path.Push(new SelectionPathComponent( requestedField.Name, Array.Empty <ArgumentNode>())); } FieldNode current = CreateRequestedField(requestedField, ref path); while (path.Any()) { path = path.Pop(out SelectionPathComponent component); current = CreateSelection(current, component); } var usedVariables = new HashSet <string>(); _usedVariables.CollectUsedVariables(current, usedVariables); _usedVariables.CollectUsedVariables(_fragments, usedVariables); var definitions = new List <IDefinitionNode>(); definitions.Add(CreateOperation( _operationName, operation, new List <FieldNode> { current }, _variables.Where(t => usedVariables.Contains(t.Variable.Name.Value)) .ToList())); definitions.AddRange(_fragments); return(new DocumentNode(null, definitions)); }
public static IImmutableStack <T> push <T>(IImmutableStack <T> stack, T value) => stack.Push(value);
public IImmutableQueue <T> Enqueue(T value) { return(new ImmutableQueue <T>(forwards, backwards.Push(value))); }
public ParserContext AddVariable(ParameterExpression variable) { return(new ParserContext(ExpectedType, TypeResolver, nameTable.Add(variable.Name, variable), variables.Push(variable))); }
public GameState Do(Covers covers) { var moves = _moves.Push(covers); return(new GameState(moves, CursorPosition)); }
public IImmutableStack <Step> AddStep <TStep>(IImmutableStack <Step> steps, TStep step, IGremlinQueryEnvironment environment) where TStep : Step { return(TryGetAddHandler(typeof(TStep), step.GetType()) is Func <IImmutableStack <Step>, TStep, IGremlinQueryEnvironment, IAddStepHandler, IImmutableStack <Step> > del ? del(steps, step, environment, this) : steps.Push(step)); }
public override IImmutableStack <Step> AddStep <TStep>(IImmutableStack <Step> steps, TStep step, IGremlinQueryEnvironment environment) => steps.Push(step);