public void MessageTypeUnion_world_command_response_types_are_not_equal_with_different_data() { var worldCommandResponseOne = MessageTypeUnion.WorldCommandResponse(WorldCommand.CreateEntity); var worldCommandResponseTwo = MessageTypeUnion.WorldCommandResponse(WorldCommand.DeleteEntity); Assert.AreNotEqual(worldCommandResponseOne, worldCommandResponseTwo); }
public void MessageTypeUnion_update_types_are_not_equal_with_different_data() { var updateOne = MessageTypeUnion.Update(1); var updateTwo = MessageTypeUnion.Update(2); Assert.AreNotEqual(updateOne, updateTwo); }
public void GetSummary_throws_if_requested_frames_is_longer_than_sequence_stored() { var netStats = new NetStats(5); Assert.Throws <ArgumentOutOfRangeException>(() => netStats.GetSummary(MessageTypeUnion.Update(54), 10, Direction.Incoming)); }
public void MessageTypeUnion_are_not_equal_with_different_types() { var typeOne = MessageTypeUnion.Update(10); var typeTwo = MessageTypeUnion.CommandRequest(10, 10); Assert.AreNotEqual(typeOne, typeTwo); }
public void FrameStats_is_summed_in_summary_stats_and_wraps_correctly() { var netStats = new NetStats(5); var netFrameStats = new NetFrameStats(); var dataInjector = netFrameStats.TestInjector; var messageType = MessageTypeUnion.Update(10); var direction = Direction.Incoming; for (uint i = 1; i <= 5; i++) { dataInjector.AddComponentUpdate(10, i); netStats.SetFrameStats(netFrameStats, direction); netStats.FinishFrame(); netFrameStats.Clear(); } // After the for loop, for the correct direction and message type. // buffer - [5, 4, 3, 2, 1] // nextInsertIndex ^ var(singleFrameData, _) = netStats.GetSummary(messageType, 1, direction); Assert.AreEqual(1, singleFrameData.Count); Assert.AreEqual(5, singleFrameData.Size); var(twoFrameData, _) = netStats.GetSummary(messageType, 2, direction); Assert.AreEqual(2, twoFrameData.Count); Assert.AreEqual(5 + 4, twoFrameData.Size); var(threeFrameData, _) = netStats.GetSummary(messageType, 3, direction); Assert.AreEqual(3, threeFrameData.Count); Assert.AreEqual(5 + 4 + 3, threeFrameData.Size); }
public void MessageTypeUnion_command_response_types_are_not_equal_with_different_data() { var commandResponseData = new List <MessageTypeUnion> { MessageTypeUnion.CommandResponse(1, 1), MessageTypeUnion.CommandResponse(1, 2), MessageTypeUnion.CommandResponse(2, 1), MessageTypeUnion.CommandResponse(2, 2) }; Assert.IsFalse(AreAnyEqual(commandResponseData)); }
protected override void PopulateElementInfo() { ElementInfo = new List <(string, MessageTypeUnion)>() { ("CreateEntity.Request", MessageTypeUnion.WorldCommandRequest(WorldCommand.CreateEntity)), ("CreateEntity.Response", MessageTypeUnion.WorldCommandResponse(WorldCommand.CreateEntity)), ("DeleteEntity.Request", MessageTypeUnion.WorldCommandRequest(WorldCommand.DeleteEntity)), ("DeleteEntity.Response", MessageTypeUnion.WorldCommandResponse(WorldCommand.DeleteEntity)), ("EntityQuery.Request", MessageTypeUnion.WorldCommandRequest(WorldCommand.EntityQuery)), ("EntityQuery.Response", MessageTypeUnion.WorldCommandResponse(WorldCommand.EntityQuery)), ("ReserveEntityIds.Request", MessageTypeUnion.WorldCommandRequest(WorldCommand.ReserveEntityIds)), ("ReserveEntityIds.Response", MessageTypeUnion.WorldCommandResponse(WorldCommand.ReserveEntityIds)), }; }
protected override void PopulateElementInfo() { ElementInfo = ComponentDatabase.Metaclasses .SelectMany(pair => pair.Value.Commands .SelectMany(metaclass => new List <(string, MessageTypeUnion)>() { ($"{metaclass.Name}.Request", MessageTypeUnion.CommandRequest(pair.Key, metaclass.CommandIndex)), ($"{metaclass.Name}.Response", MessageTypeUnion.CommandResponse(pair.Key, metaclass.CommandIndex)) }) ) .ToList(); }
public void FrameTime_summation_wraps_correctly() { var netStats = new NetStats(5); for (var i = 1; i <= 5; i++) { netStats.SetFrameTime(i); netStats.FinishFrame(); } // After the for loop: // FrameTime buffer - [5, 4, 3, 2, 1] // nextInsertIndex ^ var(_, threeFrameTime) = netStats.GetSummary(MessageTypeUnion.Update(54), 3, Direction.Incoming); Assert.AreEqual(5 + 4 + 3, threeFrameTime, float.Epsilon); }
public void MessageTypeUnion_with_same_type_and_data_are_equal() { var update = MessageTypeUnion.Update(10); Assert.AreEqual(update, update); var commandRequest = MessageTypeUnion.CommandRequest(10, 10); Assert.AreEqual(commandRequest, commandRequest); var commandResponse = MessageTypeUnion.CommandResponse(10, 10); Assert.AreEqual(commandResponse, commandResponse); var worldCommandRequest = MessageTypeUnion.WorldCommandRequest(WorldCommand.CreateEntity); Assert.AreEqual(worldCommandRequest, worldCommandRequest); var worldCommandResponse = MessageTypeUnion.WorldCommandResponse(WorldCommand.CreateEntity); Assert.AreEqual(worldCommandResponse, worldCommandResponse); }
public void FrameTime_is_summed_in_summary_stats() { var netStats = new NetStats(5); netStats.SetFrameTime(1); netStats.FinishFrame(); netStats.SetFrameTime(0.5f); netStats.FinishFrame(); netStats.SetFrameTime(0.25f); netStats.FinishFrame(); var(_, singleFrameTime) = netStats.GetSummary(MessageTypeUnion.Update(54), 1, Direction.Incoming); Assert.AreEqual(0.25f, singleFrameTime, float.Epsilon); var(_, twoFrameTime) = netStats.GetSummary(MessageTypeUnion.Update(54), 2, Direction.Incoming); Assert.AreEqual(0.75f, twoFrameTime, float.Epsilon); var(_, threeFrameTime) = netStats.GetSummary(MessageTypeUnion.Update(54), 3, Direction.Incoming); Assert.AreEqual(1.75f, threeFrameTime, float.Epsilon); }
public void SetFrameStats_inserts_into_the_correct_direction_and_message_type(Direction direction) { var netStats = new NetStats(5); var netFrameStats = new NetFrameStats(); var dataInjector = netFrameStats.TestInjector; dataInjector.AddComponentUpdate(5, 3); dataInjector.AddComponentUpdate(10, 3); dataInjector.AddComponentUpdate(10, 3); dataInjector.AddCommandRequest(10, 5, 3); dataInjector.AddCommandRequest(5, 10, 3); dataInjector.AddCommandRequest(5, 10, 3); dataInjector.AddCommandResponse(10, 5, 3); dataInjector.AddCommandResponse(5, 10, 3); dataInjector.AddCommandResponse(5, 10, 3); // To eliminate the possibility of cross-talk we need to insert these in more than once or twice to get // unique counts. for (var i = 0; i < 3; i++) { dataInjector.AddWorldCommandRequest(WorldCommand.CreateEntity); dataInjector.AddWorldCommandRequest(WorldCommand.DeleteEntity); dataInjector.AddWorldCommandRequest(WorldCommand.DeleteEntity); } for (var i = 0; i < 5; i++) { dataInjector.AddWorldCommandResponse(WorldCommand.EntityQuery); dataInjector.AddWorldCommandResponse(WorldCommand.ReserveEntityIds); dataInjector.AddWorldCommandResponse(WorldCommand.ReserveEntityIds); } netStats.SetFrameStats(netFrameStats, direction); netStats.FinishFrame(); var(updateOne, _) = netStats.GetSummary(MessageTypeUnion.Update(5), 1, direction); Assert.AreEqual(1, updateOne.Count); Assert.AreEqual(3, updateOne.Size); var(updateTwo, _) = netStats.GetSummary(MessageTypeUnion.Update(10), 1, direction); Assert.AreEqual(2, updateTwo.Count); Assert.AreEqual(6, updateTwo.Size); var(commandRequestOne, _) = netStats.GetSummary(MessageTypeUnion.CommandRequest(10, 5), 1, direction); Assert.AreEqual(1, commandRequestOne.Count); Assert.AreEqual(3, commandRequestOne.Size); var(commandRequestTwo, _) = netStats.GetSummary(MessageTypeUnion.CommandRequest(5, 10), 1, direction); Assert.AreEqual(2, commandRequestTwo.Count); Assert.AreEqual(6, commandRequestTwo.Size); var(commandResponseOne, _) = netStats.GetSummary(MessageTypeUnion.CommandResponse(10, 5), 1, direction); Assert.AreEqual(1, commandResponseOne.Count); Assert.AreEqual(3, commandResponseOne.Size); var(commandResponseTwo, _) = netStats.GetSummary(MessageTypeUnion.CommandResponse(5, 10), 1, direction); Assert.AreEqual(2, commandResponseTwo.Count); Assert.AreEqual(6, commandResponseTwo.Size); var(worldCommandRequestOne, _) = netStats.GetSummary(MessageTypeUnion.WorldCommandRequest(WorldCommand.CreateEntity), 1, direction); Assert.AreEqual(3, worldCommandRequestOne.Count); var(worldCommandRequestTwo, _) = netStats.GetSummary(MessageTypeUnion.WorldCommandRequest(WorldCommand.DeleteEntity), 1, direction); Assert.AreEqual(6, worldCommandRequestTwo.Count); var(worldCommandResponseOne, _) = netStats.GetSummary(MessageTypeUnion.WorldCommandResponse(WorldCommand.EntityQuery), 1, direction); Assert.AreEqual(5, worldCommandResponseOne.Count); var(worldCommandResponseTwo, _) = netStats.GetSummary(MessageTypeUnion.WorldCommandResponse(WorldCommand.ReserveEntityIds), 1, direction); Assert.AreEqual(10, worldCommandResponseTwo.Count); }
protected override void PopulateElementInfo() { ElementInfo = ComponentDatabase.Metaclasses .Select(pair => (pair.Value.Name, MessageTypeUnion.Update(pair.Key))) .ToList(); }