1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Add tests showing expected behaviour of naming helper

This commit is contained in:
Bartłomiej Dach 2022-02-16 22:32:42 +01:00
parent 1f9892802c
commit cb9ffc655a
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,132 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using NUnit.Framework;
using osu.Game.Utils;
namespace osu.Game.Tests.Utils
{
[TestFixture]
public class NamingUtilsTest
{
[Test]
public void TestEmptySet()
{
string nextBestName = NamingUtils.GetNextBestName(Enumerable.Empty<string>(), "New Difficulty");
Assert.AreEqual("New Difficulty", nextBestName);
}
[Test]
public void TestNotTaken()
{
string[] existingNames =
{
"Something",
"Entirely",
"Different"
};
string nextBestName = NamingUtils.GetNextBestName(existingNames, "New Difficulty");
Assert.AreEqual("New Difficulty", nextBestName);
}
[Test]
public void TestNotTakenButClose()
{
string[] existingNames =
{
"New Difficulty(1)",
"New Difficulty (abcd)",
"New Difficulty but not really"
};
string nextBestName = NamingUtils.GetNextBestName(existingNames, "New Difficulty");
Assert.AreEqual("New Difficulty", nextBestName);
}
[Test]
public void TestAlreadyTaken()
{
string[] existingNames =
{
"New Difficulty"
};
string nextBestName = NamingUtils.GetNextBestName(existingNames, "New Difficulty");
Assert.AreEqual("New Difficulty (1)", nextBestName);
}
[Test]
public void TestAlreadyTakenWithDifferentCase()
{
string[] existingNames =
{
"new difficulty"
};
string nextBestName = NamingUtils.GetNextBestName(existingNames, "New Difficulty");
Assert.AreEqual("New Difficulty (1)", nextBestName);
}
[Test]
public void TestAlreadyTakenWithBrackets()
{
string[] existingNames =
{
"new difficulty (copy)"
};
string nextBestName = NamingUtils.GetNextBestName(existingNames, "New Difficulty (copy)");
Assert.AreEqual("New Difficulty (copy) (1)", nextBestName);
}
[Test]
public void TestMultipleAlreadyTaken()
{
string[] existingNames =
{
"New Difficulty",
"New difficulty (1)",
"new Difficulty (2)",
"New DIFFICULTY (3)"
};
string nextBestName = NamingUtils.GetNextBestName(existingNames, "New Difficulty");
Assert.AreEqual("New Difficulty (4)", nextBestName);
}
[Test]
public void TestEvenMoreAlreadyTaken()
{
string[] existingNames = Enumerable.Range(1, 30).Select(i => $"New Difficulty ({i})").Append("New Difficulty").ToArray();
string nextBestName = NamingUtils.GetNextBestName(existingNames, "New Difficulty");
Assert.AreEqual("New Difficulty (31)", nextBestName);
}
[Test]
public void TestMultipleAlreadyTakenWithGaps()
{
string[] existingNames =
{
"New Difficulty",
"New Difficulty (1)",
"New Difficulty (4)",
"New Difficulty (9)"
};
string nextBestName = NamingUtils.GetNextBestName(existingNames, "New Difficulty");
Assert.AreEqual("New Difficulty (2)", nextBestName);
}
}
}

View File

@ -0,0 +1,15 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
namespace osu.Game.Utils
{
public static class NamingUtils
{
public static string GetNextBestName(IEnumerable<string> existingNames, string desiredName)
{
return null;
}
}
}