public object GetPartOfRecord(FakeInput kind, object fakeInputParameter) { if (kind == FakeInput.NONE || _playStorage == null || !_playStorage.ContainsKey(kind) || !_playStorage[kind].ContainsKey(fakeInputParameter)) { throw new Exception("Play Storage is unload."); } try { if (AtfInitializer.Instance.isDebugPrintOn) { print($"Action to deliver remain: {_playStorage[kind][fakeInputParameter].Count}"); } if (recorder.IsPlaying() && !recorder.IsPlayPaused()) { return(_playStorage[kind][fakeInputParameter].Dequeue().Content); } return(_playStorage[kind][fakeInputParameter].Peek().Content); } catch (Exception e) { if (AtfInitializer.Instance.isDebugPrintOn) { print($"Clearing play cache: {e}"); } recorder.StopPlay(); ClearPlayStorage(); } throw new Exception("Play Storage is unload or empty."); }
public void Game_Runs_Over_2D_World_From_Console() { var worldSize = "3x4"; var lifeCoords = "0,0.1,1.1,2"; var fakeInput = new FakeInput(); var sequenceOfInput = new string[] { worldSize, lifeCoords, "", "" }; fakeInput.SetupSequence(sequenceOfInput); var fakeOutput = new FakeOutput(); var fakeSleeper = new FakeSleeper(); var expectedGenerationOne = $"*...\n.**.\n....\n"; var expectedGenerationTwo = $".*..\n.*..\n.*..\n"; var expectedGenerationThree = $"***.\n***.\n***.\n"; var expectedEmptyWorld = $"....\n....\n....\n"; var game = new Game(fakeInput, fakeOutput, fakeSleeper); game.Run(); Assert.Equal(1, fakeInput.readStrings[worldSize]); Assert.Equal(1, fakeInput.readStrings[lifeCoords]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationOne]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationTwo]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationThree]); Assert.Equal(1, fakeOutput.writtenStrings[expectedEmptyWorld]); Assert.Equal(3, fakeSleeper.Calls); }
public void SetUp() { input = new FakeInput(); output = new FakeOutput(); pid = new PIDController(0.05, 0.0, 0.0, input, output); pid.SetInputRange(-range/2, range/2); }
public void Game_Skips_Over_Invalid_Input() { var worldSize = "5x4"; var garbage = "i am garbage"; var lifeCoords = "0,1.2,1.2,3.3,3"; var fakeInput = new FakeInput(); var sequenceOfInput = new string[] { garbage, worldSize, garbage, lifeCoords, "", "" }; fakeInput.SetupSequence(sequenceOfInput); var fakeOutput = new FakeOutput(); var fakeSleeper = new FakeSleeper(); var expectedGenerationOne = $".*..\n....\n.*.*\n...*\n....\n"; var expectedGenerationTwo = $"....\n*.*.\n*.*.\n*.*.\n....\n"; var expectedGenerationThree = $"....\n....\n*.*.\n....\n....\n"; var expectedEmptyWorld = $"....\n....\n....\n....\n....\n"; var game = new Game(fakeInput, fakeOutput, fakeSleeper); game.Run(); Assert.Equal(1, fakeInput.readStrings[worldSize]); Assert.Equal(1, fakeInput.readStrings[lifeCoords]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationOne]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationTwo]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationThree]); Assert.Equal(1, fakeOutput.writtenStrings[expectedEmptyWorld]); Assert.Equal(3, fakeSleeper.Calls); }
public void Game_Runs_Over_2D_World_From_Console_With_Custom_CellStrings() { var worldSize = "4x5"; var lifeCoords = "0,1.2,1.2,3.3,3"; string deadCellString = "🐙"; string liveCellString = "🙊"; var fakeInput = new FakeInput(); var sequenceOfInput = new string[] { worldSize, lifeCoords, deadCellString, liveCellString }; fakeInput.SetupSequence(sequenceOfInput); var fakeOutput = new FakeOutput(); var fakeSleeper = new FakeSleeper(); var expectedGenerationOne = $"🐙🙊🐙🐙🐙\n🐙🐙🐙🐙🐙\n🐙🙊🐙🙊🐙\n🐙🐙🐙🙊🐙\n"; var expectedGenerationTwo = $"🐙🐙🐙🐙🐙\n🐙🐙🙊🐙🐙\n🐙🐙🙊🐙🐙\n🐙🐙🐙🐙🐙\n"; var expectedGenerationThree = $"🐙🐙🐙🐙🐙\n🐙🐙🐙🐙🐙\n🐙🐙🐙🐙🐙\n🐙🐙🐙🐙🐙\n"; var game = new Game(fakeInput, fakeOutput, fakeSleeper); game.Run(); Assert.Equal(1, fakeInput.readStrings[worldSize]); Assert.Equal(1, fakeInput.readStrings[lifeCoords]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationOne]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationTwo]); Assert.Equal(1, fakeOutput.writtenStrings[expectedGenerationThree]); Assert.Equal(2, fakeSleeper.Calls); }
public void SetLastInput(FakeInput kind, object realInput, object fakeInputParameter) { if (GetLastInput(kind, fakeInputParameter) != null) { STORAGE.Dequeue(LAST_INPUT_RECORD_NAME, kind, fakeInputParameter); } STORAGE.Enqueue(LAST_INPUT_RECORD_NAME, kind, fakeInputParameter, new AtfAction { Content = realInput }); }
private static T Intercept <T>(T realInput, FakeInput fakeInputKind, object fakeInputParameter = null) { if (fakeInputParameter == null) { fakeInputParameter = "EMPTY FAKE INPUT PARAMETER"; } dynamic result = RealOrFakeInputOrRecord(realInput, fakeInputParameter, fakeInputKind); if (result is string) { Debug.Log(result); } return(result); }
public ProgramTests() { _input = new FakeInput(); _input.EnterLine("5:00 PM"); _input.EnterLine("9:00 PM"); _input.EnterLine("9:00 PM"); _output = new FakeOutput(); var services = new ServiceCollection() .AddBabySitterCli() .Replace(new ServiceDescriptor(typeof(IOutput), p => _output, ServiceLifetime.Singleton)) .Replace(new ServiceDescriptor(typeof(IInput), p => _input, ServiceLifetime.Singleton)); _program = new Program(services); }
public FrameTestsBase() { Services = new FakeServices(); App = new FakeApp(); Output = new FakeOutput(); Input = new FakeInput(); Frame = new Frame( new FrameContext { Services = Services, App = App.Call, Write = Output.Write, Flush = Output.Flush, End = Output.End, }); Input.Consume = (baton, callback) => Frame.Consume(baton, (frame, ex) => callback(ex)); }
public void Enqueue(string recordName, FakeInput kind, object fakeInputParameter, AtfAction atfAction) { if (!_actionStorage.ContainsKey(recordName)) { _actionStorage.Add(recordName, new Dictionary <FakeInput, Dictionary <object, AtfActionRleQueue> >()); } if (!_actionStorage[recordName].ContainsKey(kind)) { _actionStorage[recordName].Add(kind, new Dictionary <object, AtfActionRleQueue>()); } if (!_actionStorage[recordName][kind].ContainsKey(fakeInputParameter)) { _actionStorage[recordName][kind][fakeInputParameter] = new AtfActionRleQueue(); } _actionStorage[recordName][kind][fakeInputParameter].Enqueue(atfAction); }
public void Record(FakeInput kind, object input, object fakeInputParameter) { STORAGE.Enqueue(GetCurrentRecordName(), kind, fakeInputParameter, new AtfAction { Content = input }); }
public object GetLastInput(FakeInput kind, object fakeInputParameter) { return(STORAGE.Peek(LAST_INPUT_RECORD_NAME, kind, fakeInputParameter)?.Content); }
public string Visualize(FakeInput input) { return("I'm Mr " + input.Name); }
public void DoNothing(FakeInput input) { }
public void OneInZeroOut(FakeInput input) { }
private T IfNameAndKindAndFipIsNotExistInStorageReturnDefault <T>(string recordName, FakeInput kind, object fakeInputParameter, Func <T> toReturn, T defaultValue) { if (!_actionStorage.ContainsKey(recordName) || !_actionStorage[recordName].ContainsKey(kind) || !_actionStorage[recordName][kind].ContainsKey(fakeInputParameter) || _actionStorage[recordName][kind][fakeInputParameter].Count == 0) { return(defaultValue); } return(toReturn()); }
public FakeInputWithFipAndActions FindFakeInputWithFipAndActionsByKind(FakeInput kind) { return(fakeInputsWithFipsAndActions?.Find((element) => element.fakeInput.Equals(kind))); }
public string Visualize(FakeInput input) { return "I'm Mr " + input.Name; }
public AtfAction Dequeue(string recordName, FakeInput kind, object fakeInputParameter) { return(IfNameAndKindAndFipIsNotExistInStorageReturnDefault(recordName, kind, fakeInputParameter, () => _actionStorage[recordName][kind][fakeInputParameter].Dequeue(), null)); }
private static object GetCurrentFakeInput(FakeInput inputKind, object fakeInputParameter) { return(STORAGE.GetPartOfRecord(inputKind, fakeInputParameter)); }
private static object RealOrFakeInputOrRecord(object realInput, object fakeInputParameter, FakeInput kind) { if (RECORDER.IsPlaying()) { if (RECORDER.IsInputStopped()) { print("Input now cannot be stopped. Please uncheck the option."); } if (!RECORDER.IsPlayPaused()) { try { realInput = GetCurrentFakeInput(kind, fakeInputParameter); } catch (Exception e) { if (AtfInitializer.Instance.isDebugPrintOn) { print(e); } } return(realInput); } else { return(realInput); } } else { if (RECORDER.IsRecording()) { if (RECORDER.IsInputStopped()) { realInput = RECORDER.GetLastInput(kind, fakeInputParameter); } if (!RECORDER.IsRecordingPaused()) { RECORDER.Record(kind, realInput, fakeInputParameter); } return(realInput); } else { if (RECORDER.IsInputStopped()) { return(RECORDER.GetLastInput(kind, fakeInputParameter)); } else { RECORDER.SetLastInput(kind, realInput, fakeInputParameter); return(realInput); } } } }