Skip to content

Commit

Permalink
Remove unused code from DeferredPacketRecieverTest
Browse files Browse the repository at this point in the history
Also handling edge case in NitroxCollectionFaker
  • Loading branch information
Jannify committed Feb 25, 2024
1 parent 023428a commit fe3391f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
12 changes: 1 addition & 11 deletions Nitrox.Test/Client/Communication/DeferredPacketReceiverTest.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Nitrox.Test.Client.Communication;
using NitroxClient.Map;
using NitroxModel.DataStructures.GameLogic;
using NitroxModel.DataStructures.Unity;
using Nitrox.Test.Client.Communication;
using NitroxModel.Packets;

namespace NitroxClient.Communication;

[TestClass]
public class DeferredPacketReceiverTest
{
private readonly VisibleCells visibleCells = new();
private PacketReceiver packetReceiver;

// Test Data
private const ushort PLAYER_ID = 1;
private const int CELL_LEVEL = 3;
private readonly NitroxVector3 loadedActionPosition = new(50, 50, 50);
private AbsoluteEntityCell loadedCell;

[TestInitialize]
public void TestInitialize()
{
packetReceiver = new PacketReceiver();
loadedCell = new AbsoluteEntityCell(loadedActionPosition, CELL_LEVEL);
visibleCells.Add(loadedCell);
}

[TestMethod]
Expand Down
28 changes: 18 additions & 10 deletions Nitrox.Test/Helper/Faker/NitroxCollectionFaker.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;

namespace Nitrox.Test.Helper.Faker;

public class NitroxCollectionFaker : NitroxFaker, INitroxFaker
Expand Down Expand Up @@ -67,7 +61,7 @@ public static bool TryGetCollectionTypes(Type type, out Type[] types)

if (collectionType == CollectionType.ARRAY)
{
types = new[] {type.GetElementType() };
types = new[] { type.GetElementType() };
return true;
}

Expand Down Expand Up @@ -121,7 +115,7 @@ public NitroxCollectionFaker(Type type, CollectionType collectionType)
for (int i = 0; i < GenerateSize; i++)
{
MethodInfo castMethod = CastMethodBase.MakeGenericMethod(OutputType);
dynamic castedObject = castMethod.Invoke(null, new[] { elementFaker.GenerateUnsafe(typeTree)});
dynamic castedObject = castMethod.Invoke(null, new[] { elementFaker.GenerateUnsafe(typeTree) });
list.Add(castedObject);
}
Expand All @@ -140,10 +134,24 @@ public NitroxCollectionFaker(Type type, CollectionType collectionType)
{
typeTree.Add(dicType[0]);
typeTree.Add(dicType[1]);
IDictionary dict = (IDictionary) Activator.CreateInstance(type);
IDictionary dict = (IDictionary)Activator.CreateInstance(type);
for (int i = 0; i < GenerateSize; i++)
{
dict.Add(keyFaker.GenerateUnsafe(typeTree), valueFaker.GenerateUnsafe(typeTree));
for (int tries = 0; tries < 10; tries++)
{
object key = keyFaker.GenerateUnsafe(typeTree);
if (!dict.Contains(key))
{
dict.Add(key, valueFaker.GenerateUnsafe(typeTree));
break;
}
if (tries == 9)
{
throw new InvalidOperationException($"While generating action for filling Dictionary an unique key of {dicType[0]} couldn't be generated even after 10 tries");
}
}
}
typeTree.Remove(dicType[0]);
Expand Down

0 comments on commit fe3391f

Please sign in to comment.