Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further improve test coverage #17

Merged
merged 8 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/.idea.yTools/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.yTools/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.yTools/.idea/projectSettingsUpdater.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.yTools/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions yTools.Tests/GeneralTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace yTools.Tests;

[TestClass]
public class GeneralTests
{
[TestMethod]
[DataRow(50)]
[DataRow("FooBar")]
[DataRow(24f)]
[DataRow(32L)]
[DataRow(new[] { 6, 7, 8, 9 })]
public void GetInput(object expected)
{
var actual = General.GetInput(expected);

Assert.AreSame(expected, actual);
}
}
41 changes: 35 additions & 6 deletions yTools.Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
using System;
namespace yTools.Tests
namespace yTools.Tests
{
[TestClass]
public class SerializationTests
{
[TestCleanup]
public void Cleanup()
{
const string testDirectory = @"yTools";

var fullDir = $"{Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData
)}\\{testDirectory}";
if (Directory.Exists(fullDir))
Directory.Delete(fullDir, true);
}

[TestMethod]
public void CheckObjectsBinarySerialized()
{
Expand All @@ -12,9 +23,15 @@ public void CheckObjectsBinarySerialized()

BinarySerializer serializer = new();

serializer.SetSerializationDirectoryInLocalAppData(@"yTools\Tests\Serialization");
const string directory = @"yTools\Tests\Serialization";
serializer.SetSerializationDirectoryInLocalAppData(directory);

Assert.IsTrue(Directory.Exists(
$"{Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData
)}\\{directory}"));

bool serialized = serializer.SerializeInDefault("testObject1.bin", testObject1, out Exception? exception, out _);
var serialized = serializer.SerializeInDefault("testObject1.bin", testObject1, out Exception? exception, out _);
if (!serialized && exception != null) throw exception;
serialized = serializer.SerializeInDefault("testObject2.bin", testObject2, out exception, out _);
if (!serialized && exception != null) throw exception;
Expand All @@ -38,7 +55,13 @@ public void CheckObjectsJsonSerialized()

JsonSerializer serializer = new();

serializer.SetSerializationDirectoryInLocalAppData(@"yTools\Tests\Serialization");
const string directory = @"yTools\Tests\Serialization";
serializer.SetSerializationDirectoryInLocalAppData(directory);

Assert.IsTrue(Directory.Exists(
$"{Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData
)}\\{directory}"));

bool serialized = serializer.SerializeInDefault("testObject1.json", testObject1, out Exception? exception, out _);
if (!serialized && exception != null) throw exception;
Expand All @@ -64,7 +87,13 @@ public void CheckObjectsXmlSerialized()

XmlSerializer serializer = new();

serializer.SetSerializationDirectoryInLocalAppData(@"yTools\Tests\Serialization");
const string directory = @"yTools\Tests\Serialization";
serializer.SetSerializationDirectoryInLocalAppData(directory);

Assert.IsTrue(Directory.Exists(
$"{Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData
)}\\{directory}"));

bool serialized = serializer.SerializeInDefault("testObject1.xml", testObject1, out Exception? exception, out _);
if (!serialized && exception != null) throw exception;
Expand Down
12 changes: 12 additions & 0 deletions yTools.Tests/StringsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,17 @@ public void IsNullOrWhitespace(string str)

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void Writes()
{
var str = "Hello from Strings.Write test!";
var color = ConsoleColor.Green;

Strings.Write(str);
Strings.WriteColored(str, color);
Strings.WriteWithoutEndLine(str);
Strings.WriteColoredWithoutEndLine(str, color);
}
}
}
34 changes: 34 additions & 0 deletions yTools.Tests/VectorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,38 @@ public void Vector3ToString()

Assert.AreEqual(expected, actual);
}

[TestMethod]
public void Vector2Casts()
{
Vector2 vector = new(5, 6.5);
var castedSystemVector = (System.Numerics.Vector2)vector;

System.Numerics.Vector2 systemVector = new(4f, 8.5f);
Vector2 castedVector = systemVector;

Assert.AreEqual(vector.X, castedSystemVector.X);
Assert.AreEqual(vector.Y, castedSystemVector.Y);

Assert.AreEqual(systemVector.X, castedVector.X);
Assert.AreEqual(systemVector.Y, castedVector.Y);
}

[TestMethod]
public void Vector3Casts()
{
Vector3 vector = new(5, 6.5, 8);
var castedSystemVector = (System.Numerics.Vector3)vector;

System.Numerics.Vector3 systemVector = new(4.1f, 8.5f, 45f);
Vector3 castedVector = systemVector;

Assert.AreEqual(vector.X, castedSystemVector.X);
Assert.AreEqual(vector.Y, castedSystemVector.Y);
Assert.AreEqual(vector.Z, castedSystemVector.Z);

Assert.AreEqual(systemVector.X, castedVector.X);
Assert.AreEqual(systemVector.Y, castedVector.Y);
Assert.AreEqual(systemVector.Z, castedVector.Z);
}
}
7 changes: 2 additions & 5 deletions yTools/Serialization/BinarySerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ public class BinarySerializer
/// <param name="directory">The directory inside AppData\Local to store serialized objects. Use '\' to nest directories.</param>
public void SetSerializationDirectoryInLocalAppData(string directory)
{
defaultFolder = directory[0] == '\\'
SetSerializationDirectory(directory[0] == '\\'
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + directory
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory;

if (!Directory.Exists(defaultFolder))
Directory.CreateDirectory(defaultFolder);
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory);
}

/// <summary>
Expand Down
7 changes: 2 additions & 5 deletions yTools/Serialization/JsonSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ public class JsonSerializer
/// <param name="directory">The directory inside AppData\Local to store serialized objects. Use '\' to nest directories.</param>
public void SetSerializationDirectoryInLocalAppData(string directory)
{
defaultDirectory = directory[0] == '\\'
SetSerializationDirectory(directory[0] == '\\'
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + directory
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory;

if (!Directory.Exists(defaultDirectory))
Directory.CreateDirectory(defaultDirectory);
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory);
}

/// <summary>
Expand Down
7 changes: 2 additions & 5 deletions yTools/Serialization/XmlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ public class XmlSerializer
/// <param name="directory">The directory inside AppData\Local to store serialized objects. Use '\' to nest directories.</param>
public void SetSerializationDirectoryInLocalAppData(string directory)
{
defaultFolder = directory[0] == '\\'
SetSerializationDirectory(directory[0] == '\\'
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + directory
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory;

if (!Directory.Exists(defaultFolder))
Directory.CreateDirectory(defaultFolder);
: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\" + directory);
}

/// <summary>
Expand Down
Loading