public static void ReadPrimitiveImmutableStackT() { ImmutableStack <int> result = JsonSerializer.Parse <ImmutableStack <int> >(Encoding.UTF8.GetBytes(@"[1,2]")); int expected = 2; foreach (int i in result) { Assert.Equal(expected--, i); } result = JsonSerializer.Parse <ImmutableStack <int> >(Encoding.UTF8.GetBytes(@"[]")); Assert.Equal(0, result.Count()); }
public void DeserializeStack() { string json = @"[ ""One"", ""II"", ""3"" ]"; ImmutableStack <string> l = JsonConvert.DeserializeObject <ImmutableStack <string> >(json); Assert.AreEqual(3, l.Count()); Assert.AreEqual("3", l.ElementAt(0)); Assert.AreEqual("II", l.ElementAt(1)); Assert.AreEqual("One", l.ElementAt(2)); }
public async Task ReadPrimitiveImmutableStackT() { ImmutableStack <int> result = await JsonSerializerWrapperForString.DeserializeWrapper <ImmutableStack <int> >(@"[1,2]"); int expected = 2; foreach (int i in result) { Assert.Equal(expected--, i); } result = await JsonSerializerWrapperForString.DeserializeWrapper <ImmutableStack <int> >(@"[]"); Assert.Equal(0, result.Count()); }
public DurationFieldInfo Push(int digit) { if (digit < 0 || digit > 9) { throw new ArgumentException($"Digits must be between 0 and 9, value {digit} was rejected."); } if (digits.Count() == maximumNumberOfDigits) { return(this); } if (digits.IsEmpty && digit == 0) { return(this); } return(new DurationFieldInfo(digits.Push(digit))); }
public void When_handling_CreateActor_message_Then_the_LocalActorRef_is_pushed_to_stack_and_afterwards_removed() { var mailbox = A.Fake <Mailbox>(); var actorInstantiator = A.Fake <ActorInstantiator>(); ImmutableStack <LocalActorRef> stackDuringActorCreation = null; A.CallTo(() => actorInstantiator.CreateNewActor()).Invokes(() => { stackDuringActorCreation = ActorHelper.GetActorRefStack(); }).ReturnsLazily(() => new TestActor()); var actorRef = new LocalActorRef(new TestActorSystem(), actorInstantiator, new RootActorPath("test"), mailbox, A.Dummy <InternalActorRef>()); actorRef.HandleSystemMessage(new SystemMessageEnvelope(actorRef, new CreateActor(), A.Fake <ActorRef>())); var stackAfterActorCreation = ActorHelper.GetActorRefStack(); stackDuringActorCreation.IsEmpty.Should().BeFalse("The stack should contain one item"); stackDuringActorCreation.Peek().Should().BeSameAs(actorRef, "The item on stack should be the LocalActorRef that creates the actor"); stackDuringActorCreation.Count().Should().Be(1, "The stack should only contain one item."); (stackAfterActorCreation == null || stackAfterActorCreation.IsEmpty).Should().BeTrue("The stack should be empty after creation"); }
RecEnumerateOutcomes( ImmutableStack<Func<DiscriminatedUnionCaseParameter, DestructureMethodParameter>> results, Func<DiscriminatedUnionCaseParameter, DestructureMethodParameter>[] resultTypes, int numIterations) { if (results.Count() >= numIterations) { yield return results; } else { foreach (var resultType in resultTypes) { foreach (var a in RecEnumerateOutcomes(results.Push(resultType), resultTypes, numIterations)) { yield return a; } } } }
/// <summary> /// Writes zscii text to a memory stream. /// </summary> /// <param name="zsciiText"> /// The zscii text. /// </param> protected virtual void WriteToMemoryStream(ImmutableStack<Zscii> zsciiText) { if (this.memoryStreams != null) { var memoryStream = this.memoryStreams.Top; this.WriteZsciiToMemory(memoryStream.Table + memoryStream.CharacterCount + 2, zsciiText); memoryStream.CharacterCount += zsciiText.Count(); } }
/// <summary> /// Calls a routine. /// </summary> /// <param name="routineType"> /// The routine type. /// </param> /// <param name="packedAddress"> /// The packed address of the routine. /// </param> /// <param name="arguments"> /// Routine arguments. /// </param> protected void CallRoutine(RoutineType routineType, ushort packedAddress, ImmutableStack<ushort> arguments) { if (packedAddress == 0) { this.Return(0, routineType); return; } var argumentCount = (byte)arguments.Count(); var programCounter = this.UnpackRoutineAddress(packedAddress); var localVariableCount = this.Memory.ReadByte(programCounter); if (localVariableCount > MaximumLocalVariables) { this.FrontEnd.ErrorNotification(ErrorCondition.InvalidRoutine, "Called a routine at address " + programCounter + " with " + localVariableCount + " local variables."); } this.CallStack.BeginRoutine(routineType, programCounter + 1, argumentCount, localVariableCount); this.InitializeLocalVariables(localVariableCount); byte localVariableNumber = 0; foreach (var argument in arguments.Enumerable()) { if (localVariableNumber >= localVariableCount) { break; } this.CallStack.WriteLocalVariable(localVariableNumber++, argument); } }
/// <summary> /// Converts z-characters to zscii text. /// </summary> /// <param name="calledRecursively"> /// A value which indicates whether the method was called recursively. /// </param> /// <param name="zcharacter"> /// The zcharacter. /// </param> /// <param name="currentAlphabet"> /// The current alphabet. /// </param> /// <param name="nextAlphabet"> /// The next alphabet. /// </param> /// <param name="lockedAlphabet"> /// The locked alphabet. /// </param> /// <param name="zcharacters"> /// The zcharacters. /// </param> /// <param name="zsciiText"> /// The zscii text. /// </param> protected virtual void ZCharactersToZscii(bool calledRecursively, byte zcharacter, byte currentAlphabet, ref byte nextAlphabet, ref byte lockedAlphabet, ref ImmutableStack<byte> zcharacters, ref ImmutableStack<Zscii> zsciiText) { switch (zcharacter) { case 0: zsciiText = zsciiText.Add(Zscii.Space); break; case 1: zsciiText = zsciiText.Add(Zscii.NewLine); break; case 2: case 3: nextAlphabet = (byte)((lockedAlphabet + zcharacter - 1) % 3); break; case 4: case 5: nextAlphabet = lockedAlphabet = (byte)((lockedAlphabet + zcharacter) % 3); break; default: if (zcharacter == 6 && currentAlphabet == 2) { if (zcharacters.Count() > 1) { zsciiText = zsciiText.Add((Zscii)((zcharacters.Top * 32) + zcharacters.Tail.Top)); zcharacters = zcharacters.Tail.Tail; } else { zcharacters = null; } break; } zsciiText = zsciiText.Add(this.GetZsciiAlphabetCharacter((byte)((currentAlphabet * 26) + zcharacter - 6))); break; } }
public SnapshotableStack(ImmutableStack <T> stack) { this.Stack = stack; this.Count = stack.Count(); }