/// <summary> /// helper method to load repro states from stream /// </summary> private static Randomizer.State[] LoadFromStream(StreamReader reproStream) { var reproStack = new List <Randomizer.State>(); string reproStateStr = reproStream.ReadLine(); do { Randomizer.State state = Randomizer.State.Parse(reproStateStr); reproStack.Add(state); reproStateStr = reproStream.ReadLine(); } while (reproStateStr != null); return(reproStack.ToArray()); }
/// <summary> /// helper method called from the scope c-tor to construct the new scope /// </summary> private void CreateScopeRandomizer <RandomizerType>(IScope parentScope, out Randomizer.State[] scopeStates, out RandomizerType current) where RandomizerType : Randomizer, new() { Randomizer.State[] parentStates = parentScope != null?parentScope.GetStates() : null; int newLength = parentStates != null ? parentStates.Length + 1 : 1; scopeStates = new Randomizer.State[newLength]; if (parentStates != null) { // clone the states from the parent scope first. Note that it creates shallow copy of the state only. // this is OK since Randomizer.State is immutable Array.Copy(parentStates, scopeStates, newLength - 1); } // select the randomizer and state for the new scope if (_reproStates != null && newLength <= _reproStates.Length) { // repro mode Randomizer.State reproState = _reproStates[newLength - 1]; current = Randomizer.Create <RandomizerType>(reproState); scopeStates[newLength - 1] = reproState; } else { // either generation more or repro state did not capture this depth, thus create random randomizer // to make the scope generation deterministic, use the parent scope randomizer or the pool's one for roots int seed; if (parentScope != null) { seed = parentScope.Current.NextSeed(); } else { seed = NextRootSeed(); } current = Randomizer.Create <RandomizerType>(seed); scopeStates[newLength - 1] = current.GetCurrentState(); } }