public void SaveCreateRoundTrip() { var ms = new MemoryStream(); var zw = new ZwinderStateManager(new ZwinderStateManagerSettings { CurrentBufferSize = 16, CurrentTargetFrameLength = 10000, RecentBufferSize = 16, RecentTargetFrameLength = 100000, AncientStateInterval = 50000 }, f => false); zw.SaveStateHistory(new BinaryWriter(ms)); var buff = ms.ToArray(); var rms = new MemoryStream(buff, false); var zw2 = ZwinderStateManager.Create(new BinaryReader(rms), zw.Settings, f => false); // TODO: we could assert more things here to be thorough Assert.IsNotNull(zw2); Assert.AreEqual(zw.Settings.CurrentBufferSize, zw2.Settings.CurrentBufferSize); Assert.AreEqual(zw.Settings.RecentBufferSize, zw2.Settings.RecentBufferSize); }
public void StateBeforeFrame() { var ss = new StateSource { PaddingData = new byte[1000] }; var zw = new ZwinderStateManager(new ZwinderStateManagerSettings { CurrentBufferSize = 1, CurrentTargetFrameLength = 10000, RecentBufferSize = 1, RecentTargetFrameLength = 100000, AncientStateInterval = 50000 }, f => false); { var ms = new MemoryStream(); ss.SaveStateBinary(new BinaryWriter(ms)); zw.Engage(ms.ToArray()); } for (int frame = 0; frame <= 10440; frame++) { ss.Frame = frame; zw.Capture(frame, ss); } var kvp = zw.GetStateClosestToFrame(10440); var actual = StateSource.GetFrameNumberInState(kvp.Value); Assert.AreEqual(kvp.Key, actual); Assert.IsTrue(actual <= 10440); }
public void SaveCreateRoundTrip() { var ms = new MemoryStream(); var zw = new ZwinderStateManager(); zw.SaveStateHistory(new BinaryWriter(ms)); var buff = ms.ToArray(); var rms = new MemoryStream(buff, false); var zw2 = ZwinderStateManager.Create(new BinaryReader(rms), new ZwinderStateManagerSettings()); // TODO: we could assert more things here to be thorough Assert.IsNotNull(zw2); Assert.AreEqual(zw.Settings.CurrentBufferSize, zw2.Settings.CurrentBufferSize); Assert.AreEqual(zw.Settings.RecentBufferSize, zw2.Settings.RecentBufferSize); }
private ZwinderStateManager CreateSmallZwinder(IStatable ss) { var zw = new ZwinderStateManager(new ZwinderStateManagerSettings { CurrentBufferSize = 1, CurrentTargetFrameLength = 10000, RecentBufferSize = 1, RecentTargetFrameLength = 100000, AncientStateInterval = 50000 }, f => false); var ms = new MemoryStream(); ss.SaveStateBinary(new BinaryWriter(ms)); zw.Engage(ms.ToArray()); return(zw); }
public void StateCache() { var ss = CreateStateSource(); var zw = new ZwinderStateManager(new ZwinderStateManagerSettings { CurrentBufferSize = 2, CurrentTargetFrameLength = 1000, RecentBufferSize = 2, RecentTargetFrameLength = 1000, AncientStateInterval = 100 }, f => false); for (int i = 0; i < 1000; i += 200) { zw.CaptureReserved(i, ss); } for (int i = 400; i < 1000; i += 400) { zw.EvictReserved(i); } for (int i = 0; i < 10000; i++) { zw.Capture(i, ss); } zw.Capture(101, ss); var allStates = zw.AllStates() .Select(s => s.Frame) .ToList(); for (int i = 0; i < 10000; i++) { var actual = zw.HasState(i); var expected = allStates.Contains(i); Assert.AreEqual(expected, actual); } }