public void TestEmpty()
		{
			SnapshotHistory<int> h = new SnapshotHistory<int>(TimeSpan.FromMilliseconds(1000.0));
			Assert.True(h.IsEmpty());
			h.AddSnapshot(0, 0.0);
			Assert.False(h.IsEmpty());
		}
Example #2
0
        public void TestClosest()
        {
            SnapshotHistory <int> h = new SnapshotHistory <int>(TimeSpan.FromSeconds(1000.0));

            h.AddSnapshot(5, 15.0);

            Assert.AreEqual(5, h.GetClosestSnapshot(15.0).Value, "1 elem and t=same");
            Assert.AreEqual(5, h.GetClosestSnapshot(1000.0).Value, "1 elem and t=bigger");
            Assert.AreEqual(15.0, h.GetClosestSnapshot(0.0).Key, "1 elem and t=smaller, check for time");

            h.AddSnapshot(7, 26.0);

            Assert.AreEqual(5, h.GetClosestSnapshot(15.0).Value, "elem 1 and t=same as first and 2elems");
            Assert.AreEqual(5, h.GetClosestSnapshot(20.0).Value, "elem 1 and t=closer to first and 2elems");
            Assert.AreEqual(7, h.GetClosestSnapshot(26.0).Value, "elem 2 and t=same as second and 2elems");
            Assert.AreEqual(7, h.GetClosestSnapshot(22.0).Value, "elem 2 and t=closer to second and 2elems");
            Assert.AreEqual(7, h.GetClosestSnapshot(40.0).Value, "elem 2 and t=closer to second (higher) and 2elems");

            h.AddSnapshot(9, 50.0);

            Assert.AreEqual(5, h.GetClosestSnapshot(15.0).Value, "elem 1 and t=same as first and 3elems");
            Assert.AreEqual(5, h.GetClosestSnapshot(20.0).Value, "elem 1 and t=closer to first and 3elems");
            Assert.AreEqual(7, h.GetClosestSnapshot(26.0).Value, "elem 2 and t=same as second and 3elems");
            Assert.AreEqual(7, h.GetClosestSnapshot(22.0).Value, "elem 2 and t=closer to second and 3elems");
            Assert.AreEqual(9, h.GetClosestSnapshot(50.0).Value, "elem 2 and t=same as third and 3elems");
            Assert.AreEqual(9, h.GetClosestSnapshot(40.0).Value, "elem 2 and t=closer to third and 3elems");
        }
		public void TestBefore()
		{
			SnapshotHistory<int> h = new SnapshotHistory<int>(TimeSpan.FromSeconds(1000.0));

			h.AddSnapshot(1, 1.0);

			Assert.AreEqual(1, h.GetSnapshotBefore(2.0).Value, "first element with one element(1.0) and t=2");
			Assert.AreEqual(1, h.GetSnapshotBefore(1.0).Value, "first element with one element(1.0) and t=1");
			Assert.AreEqual(1, h.GetSnapshotBefore(0.0).Value, "gives first element when given time before the first snapshot");

			h.AddSnapshot(2, 2.0);

			Assert.AreEqual(2, h.GetSnapshotBefore(5.0).Value, "second element before with 2 elements(1.0,2.0) and t=5");
			Assert.AreEqual(2, h.GetSnapshotBefore(2.0).Value, "second element before with 2 elements(1.0,2.0) and t=2");
			Assert.AreEqual(1, h.GetSnapshotBefore(1.0).Value, "first element before with 2 elements(1.0,2.0) and t=1");
			Assert.AreEqual(1, h.GetSnapshotBefore(0.0).Value, "gives first element when given time before the first snapshot (2 elements)");

			h.AddSnapshot(5, 5.0);

			Assert.AreEqual(5, h.GetSnapshotBefore(7.0).Value, "third element before with 3 elements(1.0,2.0,5.0) and t=7");
			Assert.AreEqual(5, h.GetSnapshotBefore(5.0).Value, "third element before with 3 elements(1.0,2.0,5.0) and t=5");
			Assert.AreEqual(2, h.GetSnapshotBefore(2.0).Value, "second element before with 3 elements(1.0,2.0,5.0) and t=2");
			Assert.AreEqual(1, h.GetSnapshotBefore(1.5).Value, "first element before with 3 elements(1.0,2.0,5.0) and t=1");
			Assert.AreEqual(1, h.GetSnapshotBefore(1.0).Value, "first element before with 3 elements(1.0,2.0,5.0) and t=1.5");
			Assert.AreEqual(1, h.GetSnapshotBefore(0.0).Value, "gives first element when given time before the first snapshot (3 elements)");
		}
Example #4
0
        public void TestBefore()
        {
            SnapshotHistory <int> h = new SnapshotHistory <int>(TimeSpan.FromSeconds(1000.0));

            h.AddSnapshot(1, 1.0);

            Assert.AreEqual(1, h.GetSnapshotBefore(2.0).Value, "first element with one element(1.0) and t=2");
            Assert.AreEqual(1, h.GetSnapshotBefore(1.0).Value, "first element with one element(1.0) and t=1");
            Assert.AreEqual(1, h.GetSnapshotBefore(0.0).Value, "gives first element when given time before the first snapshot");

            h.AddSnapshot(2, 2.0);

            Assert.AreEqual(2, h.GetSnapshotBefore(5.0).Value, "second element before with 2 elements(1.0,2.0) and t=5");
            Assert.AreEqual(2, h.GetSnapshotBefore(2.0).Value, "second element before with 2 elements(1.0,2.0) and t=2");
            Assert.AreEqual(1, h.GetSnapshotBefore(1.0).Value, "first element before with 2 elements(1.0,2.0) and t=1");
            Assert.AreEqual(1, h.GetSnapshotBefore(0.0).Value, "gives first element when given time before the first snapshot (2 elements)");

            h.AddSnapshot(5, 5.0);

            Assert.AreEqual(5, h.GetSnapshotBefore(7.0).Value, "third element before with 3 elements(1.0,2.0,5.0) and t=7");
            Assert.AreEqual(5, h.GetSnapshotBefore(5.0).Value, "third element before with 3 elements(1.0,2.0,5.0) and t=5");
            Assert.AreEqual(2, h.GetSnapshotBefore(2.0).Value, "second element before with 3 elements(1.0,2.0,5.0) and t=2");
            Assert.AreEqual(1, h.GetSnapshotBefore(1.5).Value, "first element before with 3 elements(1.0,2.0,5.0) and t=1");
            Assert.AreEqual(1, h.GetSnapshotBefore(1.0).Value, "first element before with 3 elements(1.0,2.0,5.0) and t=1.5");
            Assert.AreEqual(1, h.GetSnapshotBefore(0.0).Value, "gives first element when given time before the first snapshot (3 elements)");
        }
 public static void Flush <T>(this SnapshotHistory <T> history, ISnapshotWriter writer, string path)
     where T : Snapshot
 {
     for (int i = 0; i < history.Results.Count; i++)
     {
         writer.TrySave(history.Results[i], $"snapshot_{history.Results[i].Identifier}.json", path);
     }
 }
Example #6
0
        public void TestEmpty()
        {
            SnapshotHistory <int> h = new SnapshotHistory <int>(TimeSpan.FromMilliseconds(1000.0));

            Assert.True(h.IsEmpty());
            h.AddSnapshot(0, 0.0);
            Assert.False(h.IsEmpty());
        }
		public void TestAddSnapshot()
		{
			SnapshotHistory<double> h = new SnapshotHistory<double>(TimeSpan.FromSeconds(1000.0));
			h.AddSnapshot(0.0, 0.0);
			h.AddSnapshot(1.0, 1.0);
			h.AddSnapshot(2.0, 2.0);
			h.AddSnapshot(1.5, 1.5);
			h.AddSnapshot(3.0, 3.0);
			h.AddSnapshot(0.5, 0.5);
			Assert.AreEqual(2.0, h.GetClosestSnapshot(2.1).Key, "select snapshot from added");
		}
Example #8
0
        public void TestCleanup()
        {
            SnapshotHistory <int> h = new SnapshotHistory <int>(TimeSpan.FromMilliseconds(1000.0));

            h.AddSnapshot(1, 0.0);

            Assert.AreEqual(1, h.GetClosestSnapshot(0.0).Value, "1 elem t=0");

            h.AddSnapshot(2, 1.1);

            Assert.AreEqual(2, h.GetClosestSnapshot(0.0).Value, "elem 1 cleaned t=1001");
        }
Example #9
0
        public void TestAddSnapshot()
        {
            SnapshotHistory <double> h = new SnapshotHistory <double>(TimeSpan.FromSeconds(1000.0));

            h.AddSnapshot(0.0, 0.0);
            h.AddSnapshot(1.0, 1.0);
            h.AddSnapshot(2.0, 2.0);
            h.AddSnapshot(1.5, 1.5);
            h.AddSnapshot(3.0, 3.0);
            h.AddSnapshot(0.5, 0.5);
            Assert.AreEqual(2.0, h.GetClosestSnapshot(2.1).Key, "select snapshot from added");
        }
Example #10
0
        public void SaveHistoryToFile_SavedDataCanBeLoadedBack()
        {
            var path     = Path.GetTempFileName();
            var history  = SnapshotHistory.Empty;
            var snapshot = Snapshot.Create("V1", new[] { typeof(Order) });

            history.AddSnapshot(snapshot);
            history.SaveTo(path);

            var loadedHistory = SnapshotHistory.LoadFrom(path);

            loadedHistory.Count.Should().Be(1);

            File.Delete(path);
        }
		public void TestDuplicates()
		{
			SnapshotHistory<double> h = new SnapshotHistory<double>(TimeSpan.FromSeconds(1000.0));
			h.AddSnapshot(0.0, 0.0);
			h.AddSnapshot(1.0, 1.0);
			h.AddSnapshot(2.0, 2.0);

			Assert.AreEqual(1.0, h.GetNext(h.GetSnapshotBefore(0.0)).Value.Value, "next to first is second with 1.0");

			h.AddSnapshot(5.0, 1.0);

			Assert.AreEqual(5.0, h.GetNext(h.GetSnapshotBefore(0.0)).Value.Value, "next to first is second with 5.0 (after we added a duplicate)");

			Assert.AreEqual(2.0, h.GetNext(h.GetNext(h.GetSnapshotBefore(0.0)).Value).Value.Value, "last is still 2.0 (didn't keep the 1.0,1.0)");
		}
Example #12
0
        public void TestDuplicates()
        {
            SnapshotHistory <double> h = new SnapshotHistory <double>(TimeSpan.FromSeconds(1000.0));

            h.AddSnapshot(0.0, 0.0);
            h.AddSnapshot(1.0, 1.0);
            h.AddSnapshot(2.0, 2.0);

            Assert.AreEqual(1.0, h.GetNext(h.GetSnapshotBefore(0.0)).Value.Value, "next to first is second with 1.0");

            h.AddSnapshot(5.0, 1.0);

            Assert.AreEqual(5.0, h.GetNext(h.GetSnapshotBefore(0.0)).Value.Value, "next to first is second with 5.0 (after we added a duplicate)");

            Assert.AreEqual(2.0, h.GetNext(h.GetNext(h.GetSnapshotBefore(0.0)).Value).Value.Value, "last is still 2.0 (didn't keep the 1.0,1.0)");
        }
Example #13
0
        public void SaveHistory_SavedDataCanBeLoadedBack()
        {
            var history = SnapshotHistory.Empty;

            using (var memoryStream = new MemoryStream())
            {
                var snapshot = Snapshot.Create("V1", new[] { typeof(Order) });
                history.AddSnapshot(snapshot);
                history.SaveTo(memoryStream);

                memoryStream.Position = 0;

                var newHistory = SnapshotHistory.LoadFrom(memoryStream);
                newHistory.Count.Should().Be(1);
            }
        }
Example #14
0
        public ServerGame(NetServer server)
        {
            NetServer    = server;
            Clients      = new Dictionary <NetConnection, ServerClient>();
            ActiveSpells = new List <LinearSpell>();

            StateHistory = new SnapshotHistory <MatchState>(HISTORY_MAX_TIME_KEPT);
            Match        = new GameMatch(MapLoader.MAIN_MAP_PATH);

            RemarkableEvents = new List <KeyValuePair <ServerCommand, Action <NetBuffer> > >();

            TimeSinceLastCorrection  = 0.0;
            TimeSinceLastGameHistory = 0.0;

            LeftKills = RightKills = 0;
        }
Example #15
0
        public void List()
        {
            var path = GetSnapshotPath();

            if (!System.IO.File.Exists(path))
            {
                throw new ApplicationException(String.Format("Snapshot file on path {0} not found.", path));
            }
            var history = SnapshotHistory.LoadFrom(path);

            Console.WriteLine("Snapshots:");

            foreach (var snapshot in history)
            {
                Console.WriteLine(String.Format("{0} taken at {1}", snapshot.Name, snapshot.TakenDate));
            }

            Console.WriteLine("Listing done.");
        }
Example #16
0
        public void TestGetNext()
        {
            SnapshotHistory <int> h = new SnapshotHistory <int>(TimeSpan.FromSeconds(1000.0));

            h.AddSnapshot(1, 0.0);

            h.AddSnapshot(2, 1.0);

            h.AddSnapshot(3, 2.0);

            var s = h.GetClosestSnapshot(0.0);

            Assert.AreEqual(1, s.Value, "get first with closest");
            s = h.GetNext(s).Value;
            Assert.AreEqual(2, s.Value, "next to first is second");
            s = h.GetNext(s).Value;
            Assert.AreEqual(3, s.Value, "next to second is third");
            Assert.False(h.GetNext(s).HasValue, "next to last is null");

            Assert.AreEqual(3, h.GetNext(h.GetClosestSnapshot(1.0)).Value.Value, "next to closest to second is third");
        }
Example #17
0
        public void Add(
            [Required]
            [Description("The name of the snapshot")]
            string name,
            [Required]
            [Description("Comma separated list of files to be parsed during snapshot creation. Wildcards are accepted.")]
            string[] include,
            [Description("Comma separated list of files to be excluded during snapshot creation. Only specify file names, not paths. Wildcards are accepted.")]
            [Aliases("x")]
            string[] exclude,
            [Description("If specified the snapshot won't be saved to the snapshot file.")]
            [DefaultValue(false)]
            bool whatif,
            [Description("If specified the snapshot will replace an existing one with the same name (Use only in special cases to fixup messed snapshots).")]
            [DefaultValue(false)]
            bool replace)
        {
            var path            = GetSnapshotPath();
            var snapshotHistory = System.IO.File.Exists(path) ? SnapshotHistory.LoadFrom(path) : SnapshotHistory.Empty;

            var snapshot = SnapshotTaken.TakeSnapshot(name, include, exclude ?? new string[0], _verbose);

            Console.WriteLine("Assemblies parsed:");
            snapshot.AssembliesParsed.ForEach(Console.WriteLine);

            if (replace)
            {
                snapshotHistory.ReplaceSnapshot(snapshot.Snapshot);
            }
            else
            {
                snapshotHistory.AddSnapshot(snapshot.Snapshot);
            }

            if (!whatif)
            {
                snapshotHistory.SaveTo(path);
                Console.WriteLine("Snapshot taken.");
            }
        }
Example #18
0
        public void Delete(
            [Required]
            [Description("The name of the snapshot")]
            string name,
            [Description("If specified the snapshot won't be saved to the snapshot file.")]
            [DefaultValue(false)]
            bool whatif)
        {
            var path = GetSnapshotPath();

            if (!System.IO.File.Exists(path))
            {
                throw new ApplicationException(String.Format("Snapshot file on path {0} not found.", path));
            }
            var history = SnapshotHistory.LoadFrom(path);

            history.RemoveSnapshot(name);

            if (!whatif)
            {
                history.SaveTo(path);
                Console.WriteLine("Snapshot deleted.");
            }
        }
Example #19
0
        public void Compare(
            [Required]
            [Description("Comma separated list of files to be parsed during snapshot creation. Wildcards are accepted.")]
            string[] include,
            [Description("Comma separated list of files to be excluded during snapshot creation. Only specify file names, not paths. Wildcards are accepted.")]
            [Aliases("x")]
            string[] exclude,
            [Description("Defines the name of the oldest snapshot taken into account.")]
            string oldestSnapshot,
            [Description("Returns with exit code 1 if there is a difference between the snapshots.")]
            [Aliases("failOnDifference")]
            bool haltOnDifference)
        {
            var path = GetSnapshotPath();

            if (!System.IO.File.Exists(path))
            {
                throw new ApplicationException(String.Format("Snapshot file on path {0} not found.", path));
            }
            var history  = SnapshotHistory.LoadFrom(path);
            var snapshot = SnapshotTaken.TakeSnapshot("ActualSnapshot", include, exclude ?? new string[0], _verbose);

            var snapshotsToCheckAgainst = oldestSnapshot != null
                ? history.SkipWhile(snp => !snp.Name.Equals(oldestSnapshot, StringComparison.InvariantCultureIgnoreCase))
                : history;

            var difference = snapshot.Snapshot.CompareToBase(snapshotsToCheckAgainst);

            Console.WriteLine("The following differences are detected:");
            Console.WriteLine(difference.GetHumanReadableResult(_verbose));

            if (haltOnDifference)
            {
                Environment.Exit(1);
            }
        }
Example #20
0
 /// <summary>
 /// Returns the most recent snapshot in the timeline.
 /// </summary>
 /// <param name="history"></param>
 /// <typeparam name="T"></typeparam>
 /// <returns></returns>
 public static SnapshotResult <T> MostRecent <T>(this SnapshotHistory <T> history)
     where T : Snapshot
 => history.IsNull() || history.Results.IsNull() || !history.Results.Any()
         ? new EmptySnapshotResult <T>()
 : history.Results.Last();
Example #21
0
 public RemoteClientChampion(ChampionSpawnInfo spawnInfo)
     : base(spawnInfo)
 {
     StateHistory = new SnapshotHistory <StateUpdateData>(HISTORY_TIME_KEPT);
 }
        public void TestCleanup()
        {
			SnapshotHistory<int> h = new SnapshotHistory<int>(TimeSpan.FromMilliseconds(1000.0));

			h.AddSnapshot(1, 0.0);

			Assert.AreEqual(1, h.GetClosestSnapshot(0.0).Value, "1 elem t=0");

			h.AddSnapshot(2, 1.1);

			Assert.AreEqual(2, h.GetClosestSnapshot(0.0).Value, "elem 1 cleaned t=1001");
        }
		public void TestGetNext()
		{
			SnapshotHistory<int> h = new SnapshotHistory<int>(TimeSpan.FromSeconds(1000.0));

			h.AddSnapshot(1, 0.0);

			h.AddSnapshot(2, 1.0);

			h.AddSnapshot(3, 2.0);

			var s = h.GetClosestSnapshot(0.0);
			Assert.AreEqual(1, s.Value, "get first with closest");
			s = h.GetNext(s).Value;
			Assert.AreEqual(2, s.Value, "next to first is second");
			s = h.GetNext(s).Value;
			Assert.AreEqual(3, s.Value, "next to second is third");
			Assert.False(h.GetNext(s).HasValue, "next to last is null");

			Assert.AreEqual(3, h.GetNext(h.GetClosestSnapshot(1.0)).Value.Value, "next to closest to second is third");
		}
		public void TestClosest()
		{
			SnapshotHistory<int> h = new SnapshotHistory<int>(TimeSpan.FromSeconds(1000.0));

			h.AddSnapshot(5, 15.0);

			Assert.AreEqual(5, h.GetClosestSnapshot(15.0).Value, "1 elem and t=same");
			Assert.AreEqual(5, h.GetClosestSnapshot(1000.0).Value, "1 elem and t=bigger"); 
			Assert.AreEqual(15.0, h.GetClosestSnapshot(0.0).Key, "1 elem and t=smaller, check for time");

			h.AddSnapshot(7, 26.0);

			Assert.AreEqual(5, h.GetClosestSnapshot(15.0).Value, "elem 1 and t=same as first and 2elems");
			Assert.AreEqual(5, h.GetClosestSnapshot(20.0).Value, "elem 1 and t=closer to first and 2elems");
			Assert.AreEqual(7, h.GetClosestSnapshot(26.0).Value, "elem 2 and t=same as second and 2elems");
			Assert.AreEqual(7, h.GetClosestSnapshot(22.0).Value, "elem 2 and t=closer to second and 2elems");
			Assert.AreEqual(7, h.GetClosestSnapshot(40.0).Value, "elem 2 and t=closer to second (higher) and 2elems");

			h.AddSnapshot(9, 50.0);

			Assert.AreEqual(5, h.GetClosestSnapshot(15.0).Value, "elem 1 and t=same as first and 3elems");
			Assert.AreEqual(5, h.GetClosestSnapshot(20.0).Value, "elem 1 and t=closer to first and 3elems");
			Assert.AreEqual(7, h.GetClosestSnapshot(26.0).Value, "elem 2 and t=same as second and 3elems");
			Assert.AreEqual(7, h.GetClosestSnapshot(22.0).Value, "elem 2 and t=closer to second and 3elems");
			Assert.AreEqual(9, h.GetClosestSnapshot(50.0).Value, "elem 2 and t=same as third and 3elems");
			Assert.AreEqual(9, h.GetClosestSnapshot(40.0).Value, "elem 2 and t=closer to third and 3elems");
		}
Example #25
0
        public ServerGame(NetServer server)
        {
			NetServer = server;
			Clients = new Dictionary<NetConnection, ServerClient>();
			ActiveSpells = new List<LinearSpell>();

			StateHistory = new SnapshotHistory<MatchState>(HISTORY_MAX_TIME_KEPT);
			Match = new GameMatch(MapLoader.MAIN_MAP_PATH);

			RemarkableEvents = new List<KeyValuePair<ServerCommand, Action<NetBuffer>>>();

			TimeSinceLastCorrection = 0.0;
			TimeSinceLastGameHistory = 0.0;

			LeftKills = RightKills = 0;
        }
        public RemoteClientChampion(ChampionSpawnInfo spawnInfo)
			: base(spawnInfo)
        {
			StateHistory = new SnapshotHistory<StateUpdateData>(HISTORY_TIME_KEPT);
        }