1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

improved data-related tests

This commit is contained in:
Ell 2021-06-19 21:51:09 +02:00
parent dd09f0af25
commit a0357e4dfc

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Diagnostics;
using System.IO; using System.IO;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using MLEM.Data; using MLEM.Data;
@ -10,7 +11,7 @@ using NUnit.Framework;
namespace Tests { namespace Tests {
public class DataTests { public class DataTests {
private readonly TestObject testObject = new TestObject(Vector2.One, "test") { private readonly TestObject testObject = new(Vector2.One, "test") {
Vec = new Vector2(10, 20), Vec = new Vector2(10, 20),
Point = new Point(20, 30), Point = new Point(20, 30),
Dir = Direction2.Left, Dir = Direction2.Left,
@ -45,6 +46,22 @@ namespace Tests {
Assert.AreNotSame(this.testObject.OtherTest, deepCopy.OtherTest); Assert.AreNotSame(this.testObject.OtherTest, deepCopy.OtherTest);
} }
[Test]
public void TestCopySpeed() {
const int count = 1000000;
var stopwatch = Stopwatch.StartNew();
for (var i = 0; i < count; i++)
this.testObject.Copy();
stopwatch.Stop();
TestContext.WriteLine($"Copy took {stopwatch.Elapsed.TotalMilliseconds / count * 1000000}ns on average");
stopwatch.Restart();
for (var i = 0; i < count; i++)
this.testObject.DeepCopy();
stopwatch.Stop();
TestContext.WriteLine($"DeepCopy took {stopwatch.Elapsed.TotalMilliseconds / count * 1000000}ns on average");
}
private class TestObject { private class TestObject {
public Vector2 Vec; public Vector2 Vec;
@ -55,10 +72,6 @@ namespace Tests {
public TestObject(Vector2 test, string test2) { public TestObject(Vector2 test, string test2) {
} }
public override string ToString() {
return $"{nameof(this.Vec)}: {this.Vec}, {nameof(this.Point)}: {this.Point}, {nameof(this.OtherTest)}: {this.OtherTest}, {nameof(this.Dir)}: {this.Dir}";
}
protected bool Equals(TestObject other) { protected bool Equals(TestObject other) {
return this.Vec.Equals(other.Vec) && this.Point.Equals(other.Point) && Equals(this.OtherTest, other.OtherTest) && this.Dir == other.Dir; return this.Vec.Equals(other.Vec) && this.Point.Equals(other.Point) && Equals(this.OtherTest, other.OtherTest) && this.Dir == other.Dir;
} }