public void CreateAndFillStarSystem() { _game = new Game(new NewGameSettings { GameName = "Unit Test Game", StartDateTime = DateTime.Now, MaxSystems = 0 }); // reinit with empty game, so we can do a clean test. _smAuthToken = new AuthenticationToken(_game.SpaceMaster); StarSystemFactory ssf = new StarSystemFactory(_game); var system = ssf.CreateSystem(_game, "Argon Prime", 12345); // Keeping with the X3 theme :P // lets test that the stars generated okay: List <Entity> stars = system.GetAllEntitiesWithDataBlob <StarInfoDB>(_smAuthToken); Assert.IsNotEmpty(stars); if (stars.Count > 1) { Entity rootStar = stars[0].GetDataBlob <OrbitDB>().Root; double highestMass = rootStar.GetDataBlob <MassVolumeDB>().MassDry; Entity highestMassStar = rootStar; foreach (Entity star in stars) { var massDB = star.GetDataBlob <MassVolumeDB>(); if (massDB.MassDry > highestMass) { highestMassStar = star; } } // the first star in the system should have the highest mass: Assert.AreSame(rootStar, highestMassStar); } }
public void PerformanceTest() { // use a stop watch to get more accurate time. System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); const int numSystems = 1000; _game = new Game(new NewGameSettings { GameName = "Unit Test Game", StartDateTime = DateTime.Now, MaxSystems = 0 }); // reinit with empty game, so we can do a clean test. _smAuthToken = new AuthenticationToken(_game.SpaceMaster); var ssf = new StarSystemFactory(_game); GC.Collect(); // lets get our memory before starting: long startMemory = GC.GetTotalMemory(true); timer.Start(); for (int i = 0; i < numSystems; i++) { ssf.CreateSystem(_game, "Performance Test No " + i, i); } timer.Stop(); double totalTime = timer.Elapsed.TotalSeconds; int totalEntities = 0; foreach (StarSystem system in _game.GetSystems(_smAuthToken)) { List <Entity> entities = system.GetAllEntitiesWithDataBlob <OrbitDB>(_smAuthToken); totalEntities += entities.Count; } long endMemory = GC.GetTotalMemory(true); double totalMemory = (endMemory - startMemory) / 1024.0; // in KB // note that because we do 1000 systems total time taken as milliseconds is the time for a single system, on average. string output = $"Total run time: {totalTime.ToString("N4")}s, per system: {(totalTime / numSystems * 1000).ToString("N2")}ms.\ntotal memory used: {(totalMemory / 1024.0).ToString("N2")} MB, per system: {(totalMemory / numSystems).ToString("N2")} KB.\nTotal Entities: {totalEntities}, per system: {totalEntities / (float)numSystems}.\nMemory per entity: {(totalMemory / totalEntities).ToString("N2")}KB"; Console.WriteLine(output); // print results: Assert.Pass(output); }