Skip to content

Commit

Permalink
Update dictionary serialization test
Browse files Browse the repository at this point in the history
  • Loading branch information
Reousa committed Dec 25, 2023
1 parent 7166843 commit 9378fe7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ public class SampleDictionaryPacket
{
public Dictionary<int, int> SampleInts { get; set; } = new();

public Dictionary<SampleCustomType, SampleCustomType> SampleCustomTypes { get; set; } = new();
public Dictionary<SampleCustomClass, SampleCustomClass> SampleCustomTypes { get; set; } = new();
public Dictionary<SampleNetSerializableClass, SampleNetSerializableStruct> SampleNetSerializables { get; set; } = new();

public Dictionary<SampleNetSerializableClass, SampleNetSerializableClass> SampleNetSerializableClasses { get; set; } = new();

public Dictionary<SampleNetSerializableStruct, SampleNetSerializableStruct> SampleNetSerializableStructs { get; set; } = new();

// This is the one used by Assert.AreEqual, we don't need to implement the rest for now.
public override bool Equals(object? obj)
Expand All @@ -35,14 +33,6 @@ public override bool Equals(object? obj)
return false;
}

foreach (var kvp in SampleNetSerializableStructs)
{
if (!other.SampleNetSerializableStructs.ContainsKey(kvp.Key))
return false;
if (other.SampleNetSerializableStructs[kvp.Key] != SampleNetSerializableStructs[kvp.Key])
return false;
}

return true;
}
}
Expand All @@ -56,23 +46,17 @@ public class DictionarySerializationTest
SampleCustomTypes =
new()
{
{ new SampleCustomType { Value = 1 }, new SampleCustomType { Value = 1 } },
{ new SampleCustomType { Value = 2 }, new SampleCustomType { Value = 2 } },
{ new SampleCustomType { Value = 3 }, new SampleCustomType { Value = 3 } }
{ new SampleCustomClass { Value = 1 }, new SampleCustomClass() { Value = 2 } },
{ new SampleCustomClass { Value = 3 }, new SampleCustomClass() { Value = 4 } },
{ new SampleCustomClass { Value = 5 }, new SampleCustomClass() { Value = 6 } }
},
SampleNetSerializableClasses =
SampleNetSerializables =
new()
{
{ new SampleNetSerializableClass { value = 1 }, new SampleNetSerializableClass { value = 1 } },
{ new SampleNetSerializableClass { value = 2 }, new SampleNetSerializableClass { value = 2 } },
{ new SampleNetSerializableClass { value = 3 }, new SampleNetSerializableClass { value = 3 } },
},
SampleNetSerializableStructs = new()
{
{ new SampleNetSerializableStruct { value = 1 }, new SampleNetSerializableStruct { value = 1 } },
{ new SampleNetSerializableStruct { value = 2 }, new SampleNetSerializableStruct { value = 2 } },
{ new SampleNetSerializableStruct { value = 3 }, new SampleNetSerializableStruct { value = 3 } },
}
{ new SampleNetSerializableClass { value = 1 }, new SampleNetSerializableStruct { value = 1 } },
{ new SampleNetSerializableClass { value = 2 }, new SampleNetSerializableStruct { value = 2 } },
{ new SampleNetSerializableClass { value = 3 }, new SampleNetSerializableStruct { value = 3 } },
}
};

[TestMethod, Timeout(1000)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace NebulaTests.NebulaModel.Networking.Serialization;

public class SampleCustomType : IEquatable<SampleCustomType>
public class SampleCustomClass : IEquatable<SampleCustomClass>
{
public int Value { get; set; }

public bool Equals(SampleCustomType? other)
public bool Equals(SampleCustomClass? other)
{
if (ReferenceEquals(null, other))
{
Expand Down Expand Up @@ -36,15 +36,15 @@ public override bool Equals(object? obj)
return false;
}

return Equals((SampleCustomType)obj);
return Equals((SampleCustomClass)obj);
}

public override int GetHashCode()
{
return Value;
}

public static bool operator ==(SampleCustomType lhs, SampleCustomType rhs)
public static bool operator ==(SampleCustomClass lhs, SampleCustomClass rhs)
{
if (lhs is null)
{
Expand All @@ -60,5 +60,5 @@ public override int GetHashCode()
return lhs.Equals(rhs);
}

public static bool operator !=(SampleCustomType lhs, SampleCustomType rhs) => !(lhs == rhs);
public static bool operator !=(SampleCustomClass lhs, SampleCustomClass rhs) => !(lhs == rhs);
}

0 comments on commit 9378fe7

Please sign in to comment.