1
0

Added VersionStringComparer

This commit is contained in:
2024-02-25 09:44:36 +01:00
parent d4b390ad91
commit cf425da609
3 changed files with 154 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
using AMWD.Common.Comparer;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTests.Common.Comparer
{
[TestClass]
public class VersionStringComparerTests
{
[DataTestMethod]
[DataRow(null, "0")]
[DataRow("", "0")]
[DataRow("0", "1")]
[DataRow("1.0", "1.1")]
[DataRow("1.0.0", "1.0.1")]
[DataRow("1.0.0.0", "1.0.0.1")]
[DataRow("1.0.0.0-RC1", "1.0.0.0-RC2")]
public void ShouldBeLessThan(string x, string y)
{
// Arrange
var comparer = new VersionStringComparer();
// Act
int result = comparer.Compare(x, y);
// Assert
Assert.AreEqual(-1, result);
}
[DataTestMethod]
[DataRow("0", null)]
[DataRow("0", "")]
[DataRow("1", "0")]
[DataRow("1.1", "1.0")]
[DataRow("1.0.1", "1.0.0")]
[DataRow("1.0.0.1", "1.0.0.0")]
[DataRow("1.0.0.0-RC2", "1.0.0.0-RC1")]
public void ShouldBeGreaterThan(string x, string y)
{
// Arrange
var comparer = new VersionStringComparer();
// Act
int result = comparer.Compare(x, y);
// Assert
Assert.AreEqual(1, result);
}
[DataTestMethod]
[DataRow(null, null)]
[DataRow("", "")]
[DataRow("1", "1")]
[DataRow("1.2.3", "1.2.3")]
[DataRow("1.2.3-alpha", "1.2.3-alpha")]
public void ShouldBeEqual(string x, string y)
{
// Arrange
var comparer = new VersionStringComparer();
// Act
int result = comparer.Compare(x, y);
// Assert
Assert.AreEqual(0, result);
}
}
}