diff --git a/.github/workflows/speed-comparison.yml b/.github/workflows/speed-comparison.yml index 6f58d3269f..8b0413f8c9 100644 --- a/.github/workflows/speed-comparison.yml +++ b/.github/workflows/speed-comparison.yml @@ -29,36 +29,28 @@ jobs: dotnet-version: 9.0.x - name: Build TUnit AOT .NET 8.0 - run: dotnet publish TUnitTimer.csproj -c Release --framework net8.0 --output aot-publish-net8 --property:Aot=true --runtime ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'ubuntu-latest' && 'linux-x64' || 'osx-x64' }} - working-directory: "tools/speed-comparison/TUnitTimer/TUnitTimer" + run: dotnet publish UnifiedTests.csproj -c Release -p:TestFramework=TUNIT --framework net8.0 --output aot-publish-net8 -p:PublishAot=true --runtime ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'ubuntu-latest' && 'linux-x64' || 'osx-x64' }} + working-directory: "tools/speed-comparison/UnifiedTests" - name: Build TUnit AOT .NET 9.0 - run: dotnet publish TUnitTimer.csproj -c Release --framework net9.0 --output aot-publish-net9 --property:Aot=true --runtime ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'ubuntu-latest' && 'linux-x64' || 'osx-x64' }} - working-directory: "tools/speed-comparison/TUnitTimer/TUnitTimer" + run: dotnet publish UnifiedTests.csproj -c Release -p:TestFramework=TUNIT --framework net9.0 --output aot-publish-net9 -p:PublishAot=true --runtime ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'ubuntu-latest' && 'linux-x64' || 'osx-x64' }} + working-directory: "tools/speed-comparison/UnifiedTests" - name: Build TUnit Single File .NET 8.0 - run: dotnet publish TUnitTimer.csproj -c Release --framework net8.0 --output singlefile-publish-net8 --property:SingleFile=true --runtime ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'ubuntu-latest' && 'linux-x64' || 'osx-x64' }} - working-directory: "tools/speed-comparison/TUnitTimer/TUnitTimer" + run: dotnet publish UnifiedTests.csproj -c Release -p:TestFramework=TUNIT --framework net8.0 --output singlefile-publish-net8 -p:PublishSingleFile=true -p:SelfContained=true --runtime ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'ubuntu-latest' && 'linux-x64' || 'osx-x64' }} + working-directory: "tools/speed-comparison/UnifiedTests" - name: Build TUnit Single File .NET 9.0 - run: dotnet publish TUnitTimer.csproj -c Release --framework net9.0 --output singlefile-publish-net9 --property:SingleFile=true --runtime ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'ubuntu-latest' && 'linux-x64' || 'osx-x64' }} - working-directory: "tools/speed-comparison/TUnitTimer/TUnitTimer" + run: dotnet publish UnifiedTests.csproj -c Release -p:TestFramework=TUNIT --framework net9.0 --output singlefile-publish-net9 -p:PublishSingleFile=true -p:SelfContained=true --runtime ${{ matrix.os == 'windows-latest' && 'win-x64' || matrix.os == 'ubuntu-latest' && 'linux-x64' || 'osx-x64' }} + working-directory: "tools/speed-comparison/UnifiedTests" - - name: Build TUnit - run: dotnet build -c Release - working-directory: "tools/speed-comparison/TUnitTimer" - - - name: Build xUnit - run: dotnet build -c Release - working-directory: "tools/speed-comparison/xUnitTimer" - - - name: Build NUnit - run: dotnet build -c Release - working-directory: "tools/speed-comparison/NUnitTimer" - - - name: Build MSTest - run: dotnet build -c Release - working-directory: "tools/speed-comparison/MSTestTimer" + - name: Build All Frameworks + run: | + dotnet build -c Release -p:TestFramework=TUNIT + dotnet build -c Release -p:TestFramework=XUNIT + dotnet build -c Release -p:TestFramework=NUNIT + dotnet build -c Release -p:TestFramework=MSTEST + working-directory: "tools/speed-comparison/UnifiedTests" - name: Run Benchmark run: dotnet run -c Release --framework net9.0 --allCategories=Runtime @@ -97,6 +89,11 @@ jobs: with: dotnet-version: 9.0.x + - name: Prepare builds + run: | + dotnet restore UnifiedTests/UnifiedTests.csproj + working-directory: "tools/speed-comparison" + - name: Run Benchmark run: dotnet run -c Release --allCategories=Build --framework net9.0 working-directory: "tools/speed-comparison/Tests.Benchmark" diff --git a/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/.gitignore b/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/.gitignore deleted file mode 100644 index 9de94a54ad..0000000000 --- a/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/contentModel.xml -/projectSettingsUpdater.xml -/modules.xml -/.idea.MSTestTimer.iml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/encodings.xml b/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/encodings.xml deleted file mode 100644 index df87cf951f..0000000000 --- a/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/material_theme_project_new.xml b/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/material_theme_project_new.xml deleted file mode 100644 index a4167976b0..0000000000 --- a/tools/speed-comparison/MSTestTimer/.idea/.idea.MSTestTimer/.idea/material_theme_project_new.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer.sln b/tools/speed-comparison/MSTestTimer/MSTestTimer.sln deleted file mode 100644 index cbaaa1a1da..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer.sln +++ /dev/null @@ -1,16 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTestTimer", "MSTestTimer\MSTestTimer.csproj", "{0D88A24E-7A58-415E-BBF5-A77904C7420B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0D88A24E-7A58-415E-BBF5-A77904C7420B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0D88A24E-7A58-415E-BBF5-A77904C7420B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0D88A24E-7A58-415E-BBF5-A77904C7420B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0D88A24E-7A58-415E-BBF5-A77904C7420B}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/AssemblyInfo.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/AssemblyInfo.cs deleted file mode 100644 index c3f48a1b21..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/AssemblyInfo.cs +++ /dev/null @@ -1,2 +0,0 @@ - [assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] - diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/AssertionTests.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/AssertionTests.cs deleted file mode 100644 index 6913712e75..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/AssertionTests.cs +++ /dev/null @@ -1,162 +0,0 @@ -namespace MSTestTimer; - -[TestClass] -public class AssertionTests -{ - [TestMethod] - public void NumericAssertionsTest() - { - var value = 42; - var pi = 3.14159; - var negative = -10; - - Assert.AreEqual(42, value); - Assert.IsTrue(value > 40); - Assert.IsTrue(value < 50); - Assert.IsTrue(value >= 40 && value <= 45); - - Assert.AreEqual(3.14159, pi); - Assert.IsTrue(pi > 3.0); - Assert.AreNotEqual(3.14, pi); - - Assert.IsTrue(negative < 0); - Assert.IsTrue(negative < 0); - } - - [TestMethod] - public void StringAssertionsTest() - { - var text = "Hello, MSTest Framework!"; - var empty = ""; - var whitespace = " "; - - Assert.IsNotNull(text); - Assert.IsTrue(text.Length > 0); - Assert.IsTrue(text.Contains("MSTest")); - Assert.IsTrue(text.StartsWith("Hello")); - Assert.IsTrue(text.EndsWith("!")); - Assert.AreEqual(24, text.Length); - - Assert.AreEqual(0, empty.Length); - Assert.IsTrue(whitespace.Length > 0); - Assert.IsFalse(text.Contains("xUnit")); - } - - [TestMethod] - public void CollectionAssertionsTest() - { - var numbers = new List { 1, 2, 3, 4, 5 }; - var empty = new List(); - var duplicates = new[] { 1, 2, 2, 3, 3, 3 }; - - Assert.IsNotNull(numbers); - Assert.IsTrue(numbers.Count > 0); - Assert.AreEqual(5, numbers.Count); - CollectionAssert.Contains(numbers, 3); - CollectionAssert.DoesNotContain(numbers, 10); - - Assert.AreEqual(0, empty.Count); - - CollectionAssert.Contains(duplicates, 2); - Assert.AreEqual(3, duplicates.Distinct().Count()); - } - - [TestMethod] - public void BooleanAssertionsTest() - { - var isTrue = true; - var isFalse = false; - var condition = 10 > 5; - - Assert.IsTrue(isTrue); - Assert.IsFalse(isFalse); - Assert.IsTrue(condition); - Assert.IsFalse(!condition); - - Assert.IsTrue(string.IsNullOrEmpty("")); - Assert.IsFalse(string.IsNullOrEmpty("text")); - } - - [TestMethod] - public void ObjectAssertionsTest() - { - var obj1 = new TestObject { Id = 1, Name = "Test" }; - var obj2 = new TestObject { Id = 1, Name = "Test" }; - var obj3 = obj1; - TestObject? nullObj = null; - - Assert.IsNotNull(obj1); - Assert.IsNull(nullObj); - Assert.AreEqual(obj1, obj2); // Equals comparison - Assert.AreSame(obj3, obj1); - Assert.AreNotSame(obj2, obj1); - - Assert.AreEqual(typeof(TestObject), obj1.GetType()); - } - - [TestMethod] - public void ComplexAssertionsTest() - { - var data = GenerateTestData(); - - Assert.IsNotNull(data); - Assert.IsTrue(data.Count > 0); - - var firstItem = data.First(); - Assert.AreEqual(1, firstItem.Id); - Assert.IsTrue(firstItem.Values.Length > 0); - Assert.AreEqual(15, firstItem.Values.Sum()); - - var allValid = data.All(x => x.IsValid); - Assert.IsTrue(allValid); - - var totalSum = data.SelectMany(x => x.Values).Sum(); - Assert.AreEqual(120, totalSum); - } - - [TestMethod] - [DataRow(new[] { 1, 2, 3 }, 6)] - [DataRow(new[] { 10, 20, 30 }, 60)] - [DataRow(new[] { -5, 0, 5 }, 0)] - public void ParameterizedAssertionsTest(int[] values, int expectedSum) - { - Assert.IsNotNull(values); - Assert.IsTrue(values.Length > 0); - Assert.AreEqual(expectedSum, values.Sum()); - Assert.IsTrue(values.Length > 0); - Assert.AreEqual((double)expectedSum / values.Length, values.Average()); - } - - private List GenerateTestData() - { - return new List - { - new() { Id = 1, Name = "First", Values = new[] { 1, 2, 3, 4, 5 }, IsValid = true }, - new() { Id = 2, Name = "Second", Values = new[] { 6, 7, 8, 9, 10 }, IsValid = true }, - new() { Id = 3, Name = "Third", Values = new[] { 11, 12, 13, 14, 15 }, IsValid = true } - }; - } - - private class TestObject : IEquatable - { - public int Id { get; set; } - public string Name { get; set; } = ""; - - public bool Equals(TestObject? other) - { - if (other is null) return false; - return Id == other.Id && Name == other.Name; - } - - public override bool Equals(object? obj) => Equals(obj as TestObject); - public override int GetHashCode() => HashCode.Combine(Id, Name); - } - - private class ComplexTestObject - { - public int Id { get; set; } - public string Name { get; set; } = ""; - public int[] Values { get; set; } = Array.Empty(); - public bool IsValid { get; set; } - } -} \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/AsyncTests.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/AsyncTests.cs deleted file mode 100644 index 96ae5fdb63..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/AsyncTests.cs +++ /dev/null @@ -1,168 +0,0 @@ -namespace MSTestTimer; - -[TestClass] -public class AsyncTests -{ - [TestMethod] - public async Task SimpleAsyncTest() - { - var result = await ComputeAsync(10); - Assert.AreEqual(100, result); - - var text = await ProcessTextAsync("hello"); - Assert.AreEqual("HELLO", text); - } - - [TestMethod] - public async Task AsyncStreamOperationsTest() - { - using var stream = new MemoryStream(); - using var writer = new StreamWriter(stream); - using var reader = new StreamReader(stream); - - await writer.WriteLineAsync("Line 1"); - await writer.WriteLineAsync("Line 2"); - await writer.WriteLineAsync("Line 3"); - await writer.FlushAsync(); - - stream.Position = 0; - - var lines = new List(); - string? line; - while ((line = await reader.ReadLineAsync()) != null) - { - lines.Add(line); - } - - Assert.AreEqual(3, lines.Count); - Assert.AreEqual("Line 1", lines[0]); - Assert.AreEqual("Line 3", lines[2]); - } - - [TestMethod] - public async Task ConcurrentTasksTest() - { - var tasks = new[] - { - ComputeAsync(5), - ComputeAsync(10), - ComputeAsync(15), - ComputeAsync(20) - }; - - var results = await Task.WhenAll(tasks); - - Assert.AreEqual(4, results.Length); - Assert.AreEqual(25, results[0]); - Assert.AreEqual(100, results[1]); - Assert.AreEqual(225, results[2]); - Assert.AreEqual(400, results[3]); - Assert.AreEqual(750, results.Sum()); - } - - [TestMethod] - public async Task AsyncEnumerableTest() - { - var sum = 0; - var count = 0; - - await foreach (var value in GenerateValuesAsync()) - { - sum += value; - count++; - } - - Assert.AreEqual(10, count); - Assert.AreEqual(55, sum); - } - - [TestMethod] - public async Task AsyncFileSimulationTest() - { - var data = await SimulateFileReadAsync("test.txt"); - var lines = data.Split('\n'); - - Assert.AreEqual(5, lines.Length); - Assert.AreEqual("Header: Test File", lines[0]); - Assert.AreEqual("Footer: End of File", lines[4]); - - var processed = await SimulateFileProcessAsync(data); - Assert.IsTrue(processed.Contains("PROCESSED")); - } - - [TestMethod] - [DataRow(10)] - [DataRow(20)] - [DataRow(30)] - public async Task ParameterizedAsyncTest(int input) - { - var result = await ComputeAsync(input); - Assert.AreEqual(input * input, result); - - var delayed = await DelayedComputeAsync(input, 10); - Assert.AreEqual(input + 10, delayed); - } - - [TestMethod] - public async Task AsyncExceptionHandlingTest() - { - try - { - var result = await SafeComputeAsync(10); - Assert.AreEqual(100, result); - - result = await SafeComputeAsync(-1); - Assert.AreEqual(0, result); - } - catch - { - Assert.Fail("Should not throw"); - } - } - - private async Task ComputeAsync(int value) - { - await Task.Yield(); - return value * value; - } - - private async Task ProcessTextAsync(string text) - { - await Task.Yield(); - return text.ToUpper(); - } - - private async IAsyncEnumerable GenerateValuesAsync() - { - for (var i = 1; i <= 10; i++) - { - await Task.Yield(); - yield return i; - } - } - - private async Task SimulateFileReadAsync(string filename) - { - await Task.Yield(); - return $"Header: Test File\nLine 1: Data\nLine 2: More Data\nLine 3: Even More Data\nFooter: End of File"; - } - - private async Task SimulateFileProcessAsync(string content) - { - await Task.Yield(); - return $"PROCESSED: {content.Length} characters"; - } - - private async Task DelayedComputeAsync(int value, int delay) - { - await Task.Delay(1); - return value + delay; - } - - private async Task SafeComputeAsync(int value) - { - await Task.Yield(); - if (value < 0) return 0; - return value * value; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/BasicTests.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/BasicTests.cs deleted file mode 100644 index 1b8492d05f..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/BasicTests.cs +++ /dev/null @@ -1,71 +0,0 @@ -namespace MSTestTimer; - -[TestClass] -public class BasicTests -{ - [TestMethod] - public void SimpleTest() - { - var result = CalculateSum(5, 10); - Assert.AreEqual(15, result); - } - - [TestMethod] - public void MultipleAssertionsTest() - { - var text = "Hello, World!"; - var numbers = new[] { 1, 2, 3, 4, 5 }; - - Assert.IsNotNull(text); - Assert.AreEqual(13, text.Length); - Assert.IsTrue(text.Contains("World")); - - Assert.AreEqual(5, numbers.Length); - Assert.AreEqual(15, numbers.Sum()); - CollectionAssert.Contains(numbers, 3); - } - - [TestMethod] - public void CollectionOperationsTest() - { - var items = Enumerable.Range(1, 100).ToList(); - var filtered = items.Where(x => x % 2 == 0).ToList(); - var sum = filtered.Sum(); - - Assert.AreEqual(50, filtered.Count); - Assert.AreEqual(2550, sum); - Assert.AreEqual(2, filtered.First()); - Assert.AreEqual(100, filtered.Last()); - } - - [TestMethod] - public void StringManipulationTest() - { - var input = " Hello, MSTest Testing Framework! "; - var trimmed = input.Trim(); - var upper = trimmed.ToUpper(); - var words = trimmed.Split(' '); - - Assert.AreEqual("Hello, MSTest Testing Framework!", trimmed); - Assert.AreEqual("HELLO, MSTEST TESTING FRAMEWORK!", upper); - Assert.AreEqual(4, words.Length); - Assert.AreEqual("MSTest", words[1]); - } - - [TestMethod] - public void DictionaryOperationsTest() - { - var dictionary = new Dictionary(); - for (var i = 0; i < 50; i++) - { - dictionary[$"key{i}"] = i * i; - } - - Assert.AreEqual(50, dictionary.Count); - Assert.AreEqual(100, dictionary["key10"]); - Assert.IsTrue(dictionary.ContainsKey("key25")); - Assert.AreEqual(40425, dictionary.Values.Sum()); - } - - private int CalculateSum(int a, int b) => a + b; -} \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/DataDrivenTests.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/DataDrivenTests.cs deleted file mode 100644 index 4b301e3fca..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/DataDrivenTests.cs +++ /dev/null @@ -1,107 +0,0 @@ -namespace MSTestTimer; - -[TestClass] -public class DataDrivenTests -{ - [TestMethod] - [DataRow(1, 2, 3)] - [DataRow(10, 20, 30)] - [DataRow(-5, 5, 0)] - [DataRow(100, 200, 300)] - public void ParameterizedAdditionTest(int a, int b, int expected) - { - var result = a + b; - Assert.AreEqual(expected, result); - } - - [TestMethod] - [DataRow("hello", "HELLO")] - [DataRow("world", "WORLD")] - [DataRow("MSTest", "MSTEST")] - [DataRow("Testing", "TESTING")] - [DataRow("Framework", "FRAMEWORK")] - public void ParameterizedStringTest(string input, string expected) - { - var result = input.ToUpper(); - Assert.AreEqual(expected, result); - Assert.AreEqual(input.Length, result.Length); - } - - [TestMethod] - [DynamicData(nameof(ComplexTestData), DynamicDataSourceType.Method)] - public void DynamicDataSourceTest(TestData data) - { - var result = ProcessTestData(data); - - Assert.AreEqual(data.Id, result.Id); - Assert.AreEqual(data.Value * 2, result.ProcessedValue); - Assert.IsTrue(result.IsValid); - } - - [TestMethod] - [DynamicData(nameof(GetTestCases), DynamicDataSourceType.Method)] - public void ClassDataSourceTest(int value, string text, bool flag) - { - Assert.IsTrue(value > 0); - Assert.IsNotNull(text); - Assert.IsTrue(text.Length > 0); - Assert.IsTrue(flag); - } - - [TestMethod] - [DataRow(new int[] { 1, 2, 3, 4, 5 }, 15)] - [DataRow(new int[] { 10, 20, 30 }, 60)] - [DataRow(new int[] { -5, 0, 5 }, 0)] - [DataRow(new int[] { 100 }, 100)] - public void ArrayParameterTest(int[] numbers, int expectedSum) - { - var sum = numbers.Sum(); - var average = numbers.Average(); - - Assert.AreEqual(expectedSum, sum); - Assert.AreEqual((double)expectedSum / numbers.Length, average); - Assert.IsTrue(numbers.Length > 0); - } - - public static IEnumerable ComplexTestData() - { - yield return new object[] { new TestData { Id = 1, Value = 10, Name = "Test1" } }; - yield return new object[] { new TestData { Id = 2, Value = 20, Name = "Test2" } }; - yield return new object[] { new TestData { Id = 3, Value = 30, Name = "Test3" } }; - yield return new object[] { new TestData { Id = 4, Value = 40, Name = "Test4" } }; - yield return new object[] { new TestData { Id = 5, Value = 50, Name = "Test5" } }; - } - - public static IEnumerable GetTestCases() - { - yield return new object[] { 1, "First", true }; - yield return new object[] { 2, "Second", true }; - yield return new object[] { 3, "Third", true }; - yield return new object[] { 4, "Fourth", true }; - yield return new object[] { 5, "Fifth", true }; - } - - private ProcessedData ProcessTestData(TestData data) - { - return new ProcessedData - { - Id = data.Id, - ProcessedValue = data.Value * 2, - IsValid = true - }; - } - - public class TestData - { - public int Id { get; set; } - public int Value { get; set; } - public string Name { get; set; } = ""; - } - - public class ProcessedData - { - public int Id { get; set; } - public int ProcessedValue { get; set; } - public bool IsValid { get; set; } - } -} \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/FixtureTests.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/FixtureTests.cs deleted file mode 100644 index 21170c54f3..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/FixtureTests.cs +++ /dev/null @@ -1,170 +0,0 @@ -namespace MSTestTimer; - -public interface ITestDatabase -{ - void Add(string key, string value); - string? Get(string key); - int Count { get; } - void Clear(); -} - -public class TestDatabase : ITestDatabase, IDisposable -{ - private readonly Dictionary _data = new(); - - public TestDatabase() - { - // Simulate expensive initialization - for (var i = 0; i < 100; i++) - { - _data[$"init_{i}"] = $"value_{i}"; - } - } - - public void Add(string key, string value) => _data[key] = value; - public string? Get(string key) => _data.TryGetValue(key, out var value) ? value : null; - public int Count => _data.Count; - public void Clear() => _data.Clear(); - - public void Dispose() - { - _data.Clear(); - } -} - -[TestClass] -public class FixtureTests : IDisposable -{ - private readonly ITestDatabase _database; - private readonly List _testKeys; - - public FixtureTests() - { - _database = new TestDatabase(); - _testKeys = new List(); - } - - [TestInitialize] - public void SetupTest() - { - _testKeys.Clear(); - for (var i = 0; i < 10; i++) - { - var key = $"test_{i}"; - _testKeys.Add(key); - _database.Add(key, $"test_value_{i}"); - } - } - - [TestCleanup] - public void CleanupTest() - { - foreach (var key in _testKeys) - { - _database.Add(key, "cleaned"); - } - _testKeys.Clear(); - } - - [TestMethod] - public void TestDatabaseOperations() - { - Assert.IsTrue(_database.Count >= 110); - - var value = _database.Get("test_5"); - Assert.AreEqual("test_value_5", value); - - _database.Add("custom_key", "custom_value"); - Assert.AreEqual("custom_value", _database.Get("custom_key")); - } - - [TestMethod] - public void TestFixtureIsolation() - { - var initialCount = _database.Count; - - for (var i = 0; i < 5; i++) - { - _database.Add($"isolation_{i}", $"value_{i}"); - } - - Assert.AreEqual(initialCount + 5, _database.Count); - Assert.AreEqual("value_2", _database.Get("isolation_2")); - } - - [TestMethod] - public void TestRepeatedWithFixture() - { - for (var i = 0; i < 3; i++) - { - if (i > 0) SetupTest(); // Re-setup for each iteration - - Assert.AreEqual(10, _testKeys.Count); - Assert.IsNotNull(_database.Get("test_0")); - Assert.IsNotNull(_database.Get("test_9")); - - var sum = _testKeys.Count + _database.Count; - Assert.IsTrue(sum > 100); - - if (i < 2) CleanupTest(); // Clean between iterations - } - } - - public void Dispose() - { - (_database as IDisposable)?.Dispose(); - } -} - -[TestClass] -public class SharedFixtureTests -{ - private static TestDatabase? _sharedDatabase; - private readonly string _instanceId = Guid.NewGuid().ToString(); - - [ClassInitialize] - public static void ClassInit(TestContext context) - { - _sharedDatabase = new TestDatabase(); - } - - [ClassCleanup] - public static void ClassCleanup() - { - _sharedDatabase?.Dispose(); - } - - [TestMethod] - public void TestWithSharedResource1() - { - Assert.IsNotNull(_sharedDatabase); - var key = $"shared_{_instanceId}_1"; - _sharedDatabase.Add(key, "value1"); - - Assert.AreEqual("value1", _sharedDatabase.Get(key)); - Assert.IsTrue(_sharedDatabase.Count > 100); - } - - [TestMethod] - public void TestWithSharedResource2() - { - Assert.IsNotNull(_sharedDatabase); - var key = $"shared_{_instanceId}_2"; - _sharedDatabase.Add(key, "value2"); - - Assert.AreEqual("value2", _sharedDatabase.Get(key)); - Assert.IsTrue(_sharedDatabase.Count > 100); - } - - [TestMethod] - public void TestWithSharedResource3() - { - Assert.IsNotNull(_sharedDatabase); - var count = _sharedDatabase.Count; - var key = $"shared_{_instanceId}_3"; - _sharedDatabase.Add(key, "value3"); - - Assert.AreEqual(count + 1, _sharedDatabase.Count); - Assert.IsNotNull(_sharedDatabase.Get(key)); - } -} \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/GlobalUsings.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/GlobalUsings.cs deleted file mode 100644 index ab67c7ea9d..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/MSTestTimer.csproj b/tools/speed-comparison/MSTestTimer/MSTestTimer/MSTestTimer.csproj deleted file mode 100644 index 415d5e190e..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/MSTestTimer.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - net8.0;net9.0 - enable - enable - false - true - - - - - - - \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/ParallelTests.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/ParallelTests.cs deleted file mode 100644 index cc3f6ad7ae..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/ParallelTests.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System.Collections.Concurrent; - -namespace MSTestTimer; - -[TestClass] -public class ParallelTests -{ - private static readonly object _lock = new(); - private static int _sharedCounter = 0; - - [TestMethod] - public void ParallelTest1() - { - var localData = ProcessData(Enumerable.Range(1, 1000).ToList()); - Assert.AreEqual(500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - [TestMethod] - public void ParallelTest2() - { - var localData = ProcessData(Enumerable.Range(1001, 1000).ToList()); - Assert.AreEqual(1500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - [TestMethod] - public void ParallelTest3() - { - var localData = ProcessData(Enumerable.Range(2001, 1000).ToList()); - Assert.AreEqual(2500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - [TestMethod] - public void ParallelTest4() - { - var localData = ProcessData(Enumerable.Range(3001, 1000).ToList()); - Assert.AreEqual(3500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - [TestMethod] - public void ParallelTest5() - { - var localData = ProcessData(Enumerable.Range(4001, 1000).ToList()); - Assert.AreEqual(4500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - private List ProcessData(List input) - { - // Simulate some CPU work - var result = new List(input.Count); - foreach (var item in input) - { - result.Add(item); - } - result.Sort(); - return result; - } -} - -[TestClass] -[DoNotParallelize] -public class SequentialTests -{ - private static int _sequentialCounter = 0; - private static readonly List _executionOrder = new(); - - [TestMethod] - [DoNotParallelize] - public void SequentialTest1() - { - _executionOrder.Add(1); - _sequentialCounter++; - - Assert.AreEqual(_executionOrder.Count, _sequentialCounter); - Thread.Sleep(5); // Simulate work - } - - [TestMethod] - [DoNotParallelize] - public void SequentialTest2() - { - _executionOrder.Add(2); - _sequentialCounter++; - - Assert.AreEqual(_executionOrder.Count, _sequentialCounter); - Thread.Sleep(5); // Simulate work - } - - [TestMethod] - [DoNotParallelize] - public void SequentialTest3() - { - _executionOrder.Add(3); - _sequentialCounter++; - - Assert.AreEqual(_executionOrder.Count, _sequentialCounter); - Thread.Sleep(5); // Simulate work - } -} - -[TestClass] -public class ThreadSafeTests -{ - private static readonly ConcurrentDictionary _concurrentData = new(); - private static readonly ConcurrentBag _processedItems = new(); - - [TestMethod] - [DataRow(1)] - [DataRow(2)] - [DataRow(3)] - [DataRow(4)] - [DataRow(5)] - public void ConcurrentCollectionTest(int id) - { - var key = Thread.CurrentThread.ManagedThreadId * 1000 + id; - _concurrentData[key] = $"Thread_{Thread.CurrentThread.ManagedThreadId}_Item_{id}"; - _processedItems.Add(key); - - Assert.IsTrue(_concurrentData.ContainsKey(key)); - Assert.IsTrue(_concurrentData[key].Contains($"Item_{id}")); - - // Simulate some work - var sum = Enumerable.Range(1, 100).Select(x => x * id).Sum(); - Assert.AreEqual(5050 * id, sum); - } - - [TestMethod] - public async Task ParallelAsyncTest() - { - var tasks = Enumerable.Range(1, 5).Select(async i => - { - await Task.Yield(); - var result = await ProcessAsync(i); - return result; - }); - - var results = await Task.WhenAll(tasks); - - Assert.AreEqual(55, results.Sum()); - Assert.AreEqual(5, results.Length); - Assert.IsTrue(results.All(r => r > 0)); - } - - private async Task ProcessAsync(int value) - { - await Task.Delay(1); - return value * value; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/RepeatTests.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/RepeatTests.cs deleted file mode 100644 index 68e453e322..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/RepeatTests.cs +++ /dev/null @@ -1,79 +0,0 @@ -namespace MSTestTimer; - -[TestClass] -public class RepeatTests -{ - private static int _counter = 0; - - public static IEnumerable RepeatData100() - { - return Enumerable.Range(0, 100).Select(i => new object[] { i }); - } - - public static IEnumerable RepeatData50() - { - return Enumerable.Range(0, 50).Select(i => new object[] { i }); - } - - public static IEnumerable RepeatData25() - { - return Enumerable.Range(0, 25).Select(i => new object[] { i }); - } - - [TestMethod] - [DynamicData(nameof(RepeatData100), DynamicDataSourceType.Method)] - public void RepeatedCalculationTest(int iteration) - { - var localCounter = Interlocked.Increment(ref _counter); - var result = PerformCalculation(localCounter); - - Assert.IsTrue(result > 0); - Assert.AreEqual(localCounter * (localCounter + 1) / 2, result); - } - - [TestMethod] - [DynamicData(nameof(RepeatData50), DynamicDataSourceType.Method)] - public async Task RepeatedAsyncTest(int iteration) - { - var taskId = Guid.NewGuid(); - var result = await ProcessDataAsync(taskId); - - Assert.IsNotNull(result); - Assert.AreEqual(36, result.Length); // GUID length - Assert.AreEqual(taskId.ToString(), result); - } - - [TestMethod] - [DynamicData(nameof(RepeatData25), DynamicDataSourceType.Method)] - public void RepeatedStringOperationTest(int iteration) - { - var localIteration = Interlocked.Increment(ref _counter); - var text = $"Iteration_{localIteration}"; - var processed = ProcessString(text); - - Assert.IsTrue(processed.Contains("PROCESSED")); - Assert.IsTrue(processed.Contains(localIteration.ToString())); - Assert.IsTrue(processed.Length > text.Length); - } - - private int PerformCalculation(int input) - { - var result = 0; - for (var i = 1; i <= input; i++) - { - result += i; - } - return result; - } - - private async Task ProcessDataAsync(Guid id) - { - await Task.Yield(); - return id.ToString(); - } - - private string ProcessString(string input) - { - return $"PROCESSED_{input.ToUpper()}_{input.Length}"; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/MSTestTimer/MSTestTimer/SetupTeardownTests.cs b/tools/speed-comparison/MSTestTimer/MSTestTimer/SetupTeardownTests.cs deleted file mode 100644 index 9a9bee2bd9..0000000000 --- a/tools/speed-comparison/MSTestTimer/MSTestTimer/SetupTeardownTests.cs +++ /dev/null @@ -1,142 +0,0 @@ -namespace MSTestTimer; - -[TestClass] -public class SetupTeardownTests : IDisposable -{ - private List _testData; - private Dictionary _cache; - private int _setupCounter; - - public SetupTeardownTests() - { - // Constructor - _testData = new List(); - _cache = new Dictionary(); - _setupCounter = 0; - } - - [TestInitialize] - public void BeforeEachTest() - { - _setupCounter++; - _testData.Clear(); - _testData.AddRange(new[] { "Apple", "Banana", "Cherry", "Date", "Elderberry" }); - - _cache.Clear(); - for (var i = 0; i < 10; i++) - { - _cache[i] = $"Value_{i}"; - } - } - - [TestCleanup] - public void AfterEachTest() - { - _testData.Clear(); - _cache.Clear(); - } - - [TestMethod] - public void TestWithSetupData() - { - Assert.AreEqual(5, _testData.Count); - Assert.AreEqual("Apple", _testData[0]); - Assert.AreEqual(10, _cache.Count); - Assert.AreEqual("Value_5", _cache[5]); - - _testData.Add("Fig"); - Assert.AreEqual(6, _testData.Count); - } - - [TestMethod] - public void TestDataIsolation() - { - Assert.AreEqual(5, _testData.Count); - Assert.AreEqual(10, _cache.Count); - - _testData.RemoveAt(0); - _cache.Remove(0); - - Assert.AreEqual(4, _testData.Count); - Assert.AreEqual(9, _cache.Count); - } - - [TestMethod] - public void TestWithDataManipulation() - { - var sorted = _testData.OrderBy(x => x).ToList(); - var reversed = _testData.AsEnumerable().Reverse().ToList(); - - Assert.AreEqual("Apple", sorted[0]); - Assert.AreEqual("Elderberry", sorted[4]); - Assert.AreEqual("Elderberry", reversed[0]); - Assert.AreEqual("Apple", reversed[4]); - } - - public void Dispose() - { - _testData?.Clear(); - _cache?.Clear(); - } -} - -[TestClass] -public class ClassSetupTeardownTests -{ - private static List _sharedData = new(); - private static bool _isInitialized; - - [ClassInitialize] - public static void ClassSetup(TestContext context) - { - _isInitialized = true; - _sharedData = Enumerable.Range(1, 100).ToList(); - } - - [ClassCleanup] - public static void ClassTeardown() - { - _isInitialized = false; - _sharedData.Clear(); - } - - [TestMethod] - public void TestUsingClassData1() - { - Assert.IsTrue(_isInitialized); - Assert.AreEqual(100, _sharedData.Count); - Assert.AreEqual(5050, _sharedData.Sum()); - } - - [TestMethod] - public void TestUsingClassData2() - { - Assert.IsTrue(_isInitialized); - var evens = _sharedData.Where(x => x % 2 == 0).ToList(); - Assert.AreEqual(50, evens.Count); - Assert.AreEqual(2550, evens.Sum()); - } - - [TestMethod] - public void TestUsingClassData3() - { - Assert.IsTrue(_isInitialized); - var primes = _sharedData.Where(IsPrime).ToList(); - Assert.AreEqual(25, primes.Count); - Assert.AreEqual(2, primes.First()); - } - - private static bool IsPrime(int n) - { - if (n <= 1) return false; - if (n <= 3) return true; - if (n % 2 == 0 || n % 3 == 0) return false; - - for (var i = 5; i * i <= n; i += 6) - { - if (n % i == 0 || n % (i + 2) == 0) - return false; - } - return true; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/.gitignore b/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/.gitignore deleted file mode 100644 index 13752d2964..0000000000 --- a/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/.idea.NUnitTimer.iml -/modules.xml -/contentModel.xml -/projectSettingsUpdater.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/encodings.xml b/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/encodings.xml deleted file mode 100644 index df87cf951f..0000000000 --- a/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/material_theme_project_new.xml b/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/material_theme_project_new.xml deleted file mode 100644 index a4167976b0..0000000000 --- a/tools/speed-comparison/NUnitTimer/.idea/.idea.NUnitTimer/.idea/material_theme_project_new.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer.sln b/tools/speed-comparison/NUnitTimer/NUnitTimer.sln deleted file mode 100644 index 77c353cf14..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer.sln +++ /dev/null @@ -1,16 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NUnitTimer", "NUnitTimer\NUnitTimer.csproj", "{936F6833-0677-4DC7-9FB5-F51F8AA7B0F7}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {936F6833-0677-4DC7-9FB5-F51F8AA7B0F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {936F6833-0677-4DC7-9FB5-F51F8AA7B0F7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {936F6833-0677-4DC7-9FB5-F51F8AA7B0F7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {936F6833-0677-4DC7-9FB5-F51F8AA7B0F7}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/AssertionTests.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/AssertionTests.cs deleted file mode 100644 index 4f45749a58..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/AssertionTests.cs +++ /dev/null @@ -1,162 +0,0 @@ -namespace NUnitTimer; - -[TestFixture] -public class AssertionTests -{ - [Test] - public void NumericAssertionsTest() - { - var value = 42; - var pi = 3.14159; - var negative = -10; - - Assert.That(value, Is.EqualTo(42)); - Assert.That(value, Is.GreaterThan(40)); - Assert.That(value, Is.LessThan(50)); - Assert.That(value, Is.InRange(40, 45)); - - Assert.That(pi, Is.EqualTo(3.14159)); - Assert.That(pi, Is.GreaterThan(3.0)); - Assert.That(pi, Is.Not.EqualTo(3.14)); - - Assert.That(negative, Is.Negative); - Assert.That(negative, Is.LessThan(0)); - } - - [Test] - public void StringAssertionsTest() - { - var text = "Hello, NUnit Framework!"; - var empty = ""; - var whitespace = " "; - - Assert.That(text, Is.Not.Null); - Assert.That(text, Is.Not.Empty); - Assert.That(text, Does.Contain("NUnit")); - Assert.That(text, Does.StartWith("Hello")); - Assert.That(text, Does.EndWith("!")); - Assert.That(text.Length, Is.EqualTo(23)); - - Assert.That(empty, Is.Empty); - Assert.That(whitespace, Is.Not.Empty); - Assert.That(text, Does.Not.Contain("xUnit")); - } - - [Test] - public void CollectionAssertionsTest() - { - var numbers = new List { 1, 2, 3, 4, 5 }; - var empty = new List(); - var duplicates = new[] { 1, 2, 2, 3, 3, 3 }; - - Assert.That(numbers, Is.Not.Null); - Assert.That(numbers, Is.Not.Empty); - Assert.That(numbers, Has.Count.EqualTo(5)); - Assert.That(numbers, Does.Contain(3)); - Assert.That(numbers, Does.Not.Contain(10)); - - Assert.That(empty, Is.Empty); - Assert.That(empty, Has.Count.EqualTo(0)); - - Assert.That(duplicates, Does.Contain(2)); - Assert.That(duplicates.Distinct(), Has.Count.EqualTo(3)); - } - - [Test] - public void BooleanAssertionsTest() - { - var isTrue = true; - var isFalse = false; - var condition = 10 > 5; - - Assert.That(isTrue, Is.True); - Assert.That(isFalse, Is.False); - Assert.That(condition, Is.True); - Assert.That(!condition, Is.False); - - Assert.That(string.IsNullOrEmpty(""), Is.True); - Assert.That(string.IsNullOrEmpty("text"), Is.False); - } - - [Test] - public void ObjectAssertionsTest() - { - var obj1 = new TestObject { Id = 1, Name = "Test" }; - var obj2 = new TestObject { Id = 1, Name = "Test" }; - var obj3 = obj1; - TestObject? nullObj = null; - - Assert.That(obj1, Is.Not.Null); - Assert.That(nullObj, Is.Null); - Assert.That(obj1, Is.EqualTo(obj2)); // Equals comparison - Assert.That(obj1, Is.SameAs(obj3)); - Assert.That(obj1, Is.Not.SameAs(obj2)); - - Assert.That(obj1.GetType(), Is.EqualTo(typeof(TestObject))); - } - - [Test] - public void ComplexAssertionsTest() - { - var data = GenerateTestData(); - - Assert.That(data, Is.Not.Null); - Assert.That(data.Count, Is.GreaterThan(0)); - - var firstItem = data.First(); - Assert.That(firstItem.Id, Is.EqualTo(1)); - Assert.That(firstItem.Values, Is.Not.Empty); - Assert.That(firstItem.Values.Sum(), Is.EqualTo(15)); - - var allValid = data.All(x => x.IsValid); - Assert.That(allValid, Is.True); - - var totalSum = data.SelectMany(x => x.Values).Sum(); - Assert.That(totalSum, Is.EqualTo(120)); - } - - [TestCase(new[] { 1, 2, 3 }, 6)] - [TestCase(new[] { 10, 20, 30 }, 60)] - [TestCase(new[] { -5, 0, 5 }, 0)] - public void ParameterizedAssertionsTest(int[] values, int expectedSum) - { - Assert.That(values, Is.Not.Null); - Assert.That(values, Is.Not.Empty); - Assert.That(values.Sum(), Is.EqualTo(expectedSum)); - Assert.That(values.Length, Is.GreaterThan(0)); - Assert.That(values.Average(), Is.EqualTo((double)expectedSum / values.Length)); - } - - private List GenerateTestData() - { - return new List - { - new() { Id = 1, Name = "First", Values = new[] { 1, 2, 3, 4, 5 }, IsValid = true }, - new() { Id = 2, Name = "Second", Values = new[] { 6, 7, 8, 9, 10 }, IsValid = true }, - new() { Id = 3, Name = "Third", Values = new[] { 11, 12, 13, 14, 15 }, IsValid = true } - }; - } - - private class TestObject : IEquatable - { - public int Id { get; set; } - public string Name { get; set; } = ""; - - public bool Equals(TestObject? other) - { - if (other is null) return false; - return Id == other.Id && Name == other.Name; - } - - public override bool Equals(object? obj) => Equals(obj as TestObject); - public override int GetHashCode() => HashCode.Combine(Id, Name); - } - - private class ComplexTestObject - { - public int Id { get; set; } - public string Name { get; set; } = ""; - public int[] Values { get; set; } = Array.Empty(); - public bool IsValid { get; set; } - } -} \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/AsyncTests.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/AsyncTests.cs deleted file mode 100644 index ccfcf73b98..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/AsyncTests.cs +++ /dev/null @@ -1,167 +0,0 @@ -namespace NUnitTimer; - -[TestFixture] -public class AsyncTests -{ - [Test] - public async Task SimpleAsyncTest() - { - var result = await ComputeAsync(10); - Assert.That(result, Is.EqualTo(100)); - - var text = await ProcessTextAsync("hello"); - Assert.That(text, Is.EqualTo("HELLO")); - } - - [Test] - public async Task AsyncStreamOperationsTest() - { - using var stream = new MemoryStream(); - using var writer = new StreamWriter(stream); - using var reader = new StreamReader(stream); - - await writer.WriteLineAsync("Line 1"); - await writer.WriteLineAsync("Line 2"); - await writer.WriteLineAsync("Line 3"); - await writer.FlushAsync(); - - stream.Position = 0; - - var lines = new List(); - string? line; - while ((line = await reader.ReadLineAsync()) != null) - { - lines.Add(line); - } - - Assert.That(lines.Count, Is.EqualTo(3)); - Assert.That(lines[0], Is.EqualTo("Line 1")); - Assert.That(lines[2], Is.EqualTo("Line 3")); - } - - [Test] - public async Task ConcurrentTasksTest() - { - var tasks = new[] - { - ComputeAsync(5), - ComputeAsync(10), - ComputeAsync(15), - ComputeAsync(20) - }; - - var results = await Task.WhenAll(tasks); - - Assert.That(results.Length, Is.EqualTo(4)); - Assert.That(results[0], Is.EqualTo(25)); - Assert.That(results[1], Is.EqualTo(100)); - Assert.That(results[2], Is.EqualTo(225)); - Assert.That(results[3], Is.EqualTo(400)); - Assert.That(results.Sum(), Is.EqualTo(750)); - } - - [Test] - public async Task AsyncEnumerableTest() - { - var sum = 0; - var count = 0; - - await foreach (var value in GenerateValuesAsync()) - { - sum += value; - count++; - } - - Assert.That(count, Is.EqualTo(10)); - Assert.That(sum, Is.EqualTo(55)); - } - - [Test] - public async Task AsyncFileSimulationTest() - { - var data = await SimulateFileReadAsync("test.txt"); - var lines = data.Split('\n'); - - Assert.That(lines.Length, Is.EqualTo(5)); - Assert.That(lines[0], Is.EqualTo("Header: Test File")); - Assert.That(lines[4], Is.EqualTo("Footer: End of File")); - - var processed = await SimulateFileProcessAsync(data); - Assert.That(processed, Does.Contain("PROCESSED")); - } - - [TestCase(10)] - [TestCase(20)] - [TestCase(30)] - public async Task ParameterizedAsyncTest(int input) - { - var result = await ComputeAsync(input); - Assert.That(result, Is.EqualTo(input * input)); - - var delayed = await DelayedComputeAsync(input, 10); - Assert.That(delayed, Is.EqualTo(input + 10)); - } - - [Test] - public async Task AsyncExceptionHandlingTest() - { - try - { - var result = await SafeComputeAsync(10); - Assert.That(result, Is.EqualTo(100)); - - result = await SafeComputeAsync(-1); - Assert.That(result, Is.EqualTo(0)); - } - catch - { - Assert.Fail("Should not throw"); - } - } - - private async Task ComputeAsync(int value) - { - await Task.Yield(); - return value * value; - } - - private async Task ProcessTextAsync(string text) - { - await Task.Yield(); - return text.ToUpper(); - } - - private async IAsyncEnumerable GenerateValuesAsync() - { - for (var i = 1; i <= 10; i++) - { - await Task.Yield(); - yield return i; - } - } - - private async Task SimulateFileReadAsync(string filename) - { - await Task.Yield(); - return $"Header: Test File\nLine 1: Data\nLine 2: More Data\nLine 3: Even More Data\nFooter: End of File"; - } - - private async Task SimulateFileProcessAsync(string content) - { - await Task.Yield(); - return $"PROCESSED: {content.Length} characters"; - } - - private async Task DelayedComputeAsync(int value, int delay) - { - await Task.Delay(1); - return value + delay; - } - - private async Task SafeComputeAsync(int value) - { - await Task.Yield(); - if (value < 0) return 0; - return value * value; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/BasicTests.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/BasicTests.cs deleted file mode 100644 index 7f14fdd74d..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/BasicTests.cs +++ /dev/null @@ -1,71 +0,0 @@ -namespace NUnitTimer; - -[TestFixture] -public class BasicTests -{ - [Test] - public void SimpleTest() - { - var result = CalculateSum(5, 10); - Assert.That(result, Is.EqualTo(15)); - } - - [Test] - public void MultipleAssertionsTest() - { - var text = "Hello, World!"; - var numbers = new[] { 1, 2, 3, 4, 5 }; - - Assert.That(text, Is.Not.Null); - Assert.That(text.Length, Is.EqualTo(13)); - Assert.That(text, Does.Contain("World")); - - Assert.That(numbers.Length, Is.EqualTo(5)); - Assert.That(numbers.Sum(), Is.EqualTo(15)); - Assert.That(numbers, Does.Contain(3)); - } - - [Test] - public void CollectionOperationsTest() - { - var items = Enumerable.Range(1, 100).ToList(); - var filtered = items.Where(x => x % 2 == 0).ToList(); - var sum = filtered.Sum(); - - Assert.That(filtered.Count, Is.EqualTo(50)); - Assert.That(sum, Is.EqualTo(2550)); - Assert.That(filtered.First(), Is.EqualTo(2)); - Assert.That(filtered.Last(), Is.EqualTo(100)); - } - - [Test] - public void StringManipulationTest() - { - var input = " Hello, NUnit Testing Framework! "; - var trimmed = input.Trim(); - var upper = trimmed.ToUpper(); - var words = trimmed.Split(' '); - - Assert.That(trimmed, Is.EqualTo("Hello, NUnit Testing Framework!")); - Assert.That(upper, Is.EqualTo("HELLO, NUNIT TESTING FRAMEWORK!")); - Assert.That(words.Length, Is.EqualTo(4)); - Assert.That(words[1], Is.EqualTo("NUnit")); - } - - [Test] - public void DictionaryOperationsTest() - { - var dictionary = new Dictionary(); - for (var i = 0; i < 50; i++) - { - dictionary[$"key{i}"] = i * i; - } - - Assert.That(dictionary.Count, Is.EqualTo(50)); - Assert.That(dictionary["key10"], Is.EqualTo(100)); - Assert.That(dictionary.ContainsKey("key25"), Is.True); - Assert.That(dictionary.Values.Sum(), Is.EqualTo(40425)); - } - - private int CalculateSum(int a, int b) => a + b; -} \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/DataDrivenTests.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/DataDrivenTests.cs deleted file mode 100644 index 7e28979293..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/DataDrivenTests.cs +++ /dev/null @@ -1,125 +0,0 @@ -namespace NUnitTimer; - -[TestFixture] -public class DataDrivenTests -{ - [TestCase(1, 2, 3)] - [TestCase(10, 20, 30)] - [TestCase(-5, 5, 0)] - [TestCase(100, 200, 300)] - public void ParameterizedAdditionTest(int a, int b, int expected) - { - var result = a + b; - Assert.That(result, Is.EqualTo(expected)); - } - - [TestCase("hello", "HELLO")] - [TestCase("world", "WORLD")] - [TestCase("NUnit", "NUNIT")] - [TestCase("Testing", "TESTING")] - [TestCase("Framework", "FRAMEWORK")] - public void ParameterizedStringTest(string input, string expected) - { - var result = input.ToUpper(); - Assert.That(result, Is.EqualTo(expected)); - Assert.That(result.Length, Is.EqualTo(input.Length)); - } - - [Test] - [TestCaseSource(nameof(ComplexTestData))] - public void TestCaseSourceTest(TestData data) - { - var result = ProcessTestData(data); - - Assert.That(result.Id, Is.EqualTo(data.Id)); - Assert.That(result.ProcessedValue, Is.EqualTo(data.Value * 2)); - Assert.That(result.IsValid, Is.True); - } - - [Test] - [TestCaseSource(typeof(TestDataProvider), nameof(TestDataProvider.GetTestCases))] - public void ClassDataSourceTest(int value, string text, bool flag) - { - Assert.That(value, Is.GreaterThan(0)); - Assert.That(text, Is.Not.Null); - Assert.That(text.Length, Is.GreaterThan(0)); - Assert.That(flag, Is.True); - } - - [TestCase(new int[] { 1, 2, 3, 4, 5 }, 15)] - [TestCase(new int[] { 10, 20, 30 }, 60)] - [TestCase(new int[] { -5, 0, 5 }, 0)] - [TestCase(new int[] { 100 }, 100)] - public void ArrayParameterTest(int[] numbers, int expectedSum) - { - var sum = numbers.Sum(); - var average = numbers.Average(); - - Assert.That(sum, Is.EqualTo(expectedSum)); - Assert.That(average, Is.EqualTo((double)expectedSum / numbers.Length)); - Assert.That(numbers, Is.Not.Empty); - } - - [Test] - [TestCaseSource(nameof(GetValues))] - public void TestCaseSource(int value) - { - var squared = value * value; - Assert.That(squared, Is.GreaterThan(0)); - Assert.That(squared, Is.EqualTo(value * value)); - } - - public static IEnumerable ComplexTestData() - { - yield return new TestData { Id = 1, Value = 10, Name = "Test1" }; - yield return new TestData { Id = 2, Value = 20, Name = "Test2" }; - yield return new TestData { Id = 3, Value = 30, Name = "Test3" }; - yield return new TestData { Id = 4, Value = 40, Name = "Test4" }; - yield return new TestData { Id = 5, Value = 50, Name = "Test5" }; - } - - public static IEnumerable GetValues() - { - yield return 1; - yield return 2; - yield return 3; - yield return 4; - yield return 5; - } - - private ProcessedData ProcessTestData(TestData data) - { - return new ProcessedData - { - Id = data.Id, - ProcessedValue = data.Value * 2, - IsValid = true - }; - } - - public class TestData - { - public int Id { get; set; } - public int Value { get; set; } - public string Name { get; set; } = ""; - } - - public class ProcessedData - { - public int Id { get; set; } - public int ProcessedValue { get; set; } - public bool IsValid { get; set; } - } - - public static class TestDataProvider - { - public static IEnumerable GetTestCases() - { - yield return new TestCaseData(1, "First", true); - yield return new TestCaseData(2, "Second", true); - yield return new TestCaseData(3, "Third", true); - yield return new TestCaseData(4, "Fourth", true); - yield return new TestCaseData(5, "Fifth", true); - } - } -} diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/FixtureTests.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/FixtureTests.cs deleted file mode 100644 index abf980fc3e..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/FixtureTests.cs +++ /dev/null @@ -1,155 +0,0 @@ -namespace NUnitTimer; - -public interface ITestDatabase -{ - void Add(string key, string value); - string? Get(string key); - int Count { get; } - void Clear(); -} - -public class TestDatabase : ITestDatabase, IDisposable -{ - private readonly Dictionary _data = new(); - - public TestDatabase() - { - // Simulate expensive initialization - for (var i = 0; i < 100; i++) - { - _data[$"init_{i}"] = $"value_{i}"; - } - } - - public void Add(string key, string value) => _data[key] = value; - public string? Get(string key) => _data.TryGetValue(key, out var value) ? value : null; - public int Count => _data.Count; - public void Clear() => _data.Clear(); - - public void Dispose() - { - _data.Clear(); - } -} - -[TestFixture] -public class FixtureTests : IDisposable -{ - private readonly ITestDatabase _database; - private readonly List _testKeys; - - public FixtureTests() - { - _database = new TestDatabase(); - _testKeys = new List(); - } - - [SetUp] - public void SetupTest() - { - _testKeys.Clear(); - for (var i = 0; i < 10; i++) - { - var key = $"test_{i}"; - _testKeys.Add(key); - _database.Add(key, $"test_value_{i}"); - } - } - - [TearDown] - public void CleanupTest() - { - foreach (var key in _testKeys) - { - _database.Add(key, "cleaned"); - } - _testKeys.Clear(); - } - - [Test] - public void TestDatabaseOperations() - { - Assert.That(_database.Count, Is.GreaterThanOrEqualTo(110)); - - var value = _database.Get("test_5"); - Assert.That(value, Is.EqualTo("test_value_5")); - - _database.Add("custom_key", "custom_value"); - Assert.That(_database.Get("custom_key"), Is.EqualTo("custom_value")); - } - - [Test] - public void TestFixtureIsolation() - { - var initialCount = _database.Count; - - for (var i = 0; i < 5; i++) - { - _database.Add($"isolation_{i}", $"value_{i}"); - } - - Assert.That(_database.Count, Is.EqualTo(initialCount + 5)); - Assert.That(_database.Get("isolation_2"), Is.EqualTo("value_2")); - } - - [Test] - [Repeat(3)] - public void TestRepeatedWithFixture() - { - Assert.That(_testKeys.Count, Is.EqualTo(10)); - Assert.That(_database.Get("test_0"), Is.Not.Null); - Assert.That(_database.Get("test_9"), Is.Not.Null); - - var sum = _testKeys.Count + _database.Count; - Assert.That(sum, Is.GreaterThan(100)); - } - - public void Dispose() - { - (_database as IDisposable)?.Dispose(); - } -} - -[TestFixture] -public class SharedFixtureTests -{ - private static readonly TestDatabase SharedDatabase = new(); - private readonly string _instanceId = Guid.NewGuid().ToString(); - - [Test] - public void TestWithSharedResource1() - { - var key = $"shared_{_instanceId}_1"; - SharedDatabase.Add(key, "value1"); - - Assert.That(SharedDatabase.Get(key), Is.EqualTo("value1")); - Assert.That(SharedDatabase.Count, Is.GreaterThan(100)); - } - - [Test] - public void TestWithSharedResource2() - { - var key = $"shared_{_instanceId}_2"; - SharedDatabase.Add(key, "value2"); - - Assert.That(SharedDatabase.Get(key), Is.EqualTo("value2")); - Assert.That(SharedDatabase.Count, Is.GreaterThan(100)); - } - - [Test] - public void TestWithSharedResource3() - { - var count = SharedDatabase.Count; - var key = $"shared_{_instanceId}_3"; - SharedDatabase.Add(key, "value3"); - - Assert.That(SharedDatabase.Count, Is.EqualTo(count + 1)); - Assert.That(SharedDatabase.Get(key), Is.Not.Null); - } - - [OneTimeTearDown] - public static void CleanupSharedDatabase() - { - SharedDatabase?.Dispose(); - } -} \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/GlobalUsings.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/GlobalUsings.cs deleted file mode 100644 index cefced4969..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using NUnit.Framework; \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/NUnitTimer.csproj b/tools/speed-comparison/NUnitTimer/NUnitTimer/NUnitTimer.csproj deleted file mode 100644 index 0543283692..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/NUnitTimer.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - net8.0;net9.0 - enable - enable - false - true - - - - - - - \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/ParallelTests.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/ParallelTests.cs deleted file mode 100644 index 48ac5d890a..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/ParallelTests.cs +++ /dev/null @@ -1,173 +0,0 @@ -using System.Collections.Concurrent; - -namespace NUnitTimer; - -[TestFixture] -[Parallelizable(ParallelScope.All)] -public class ParallelTests -{ - private static readonly object _lock = new(); - private static int _sharedCounter = 0; - - [Test] - public void ParallelTest1() - { - var localData = ProcessData(Enumerable.Range(1, 1000).ToList()); - Assert.That(localData.Sum(), Is.EqualTo(500500)); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Test] - public void ParallelTest2() - { - var localData = ProcessData(Enumerable.Range(1001, 1000).ToList()); - Assert.That(localData.Sum(), Is.EqualTo(1500500)); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Test] - public void ParallelTest3() - { - var localData = ProcessData(Enumerable.Range(2001, 1000).ToList()); - Assert.That(localData.Sum(), Is.EqualTo(2500500)); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Test] - public void ParallelTest4() - { - var localData = ProcessData(Enumerable.Range(3001, 1000).ToList()); - Assert.That(localData.Sum(), Is.EqualTo(3500500)); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Test] - public void ParallelTest5() - { - var localData = ProcessData(Enumerable.Range(4001, 1000).ToList()); - Assert.That(localData.Sum(), Is.EqualTo(4500500)); - - lock (_lock) - { - _sharedCounter++; - } - } - - private List ProcessData(List input) - { - // Simulate some CPU work - var result = new List(input.Count); - foreach (var item in input) - { - result.Add(item); - } - result.Sort(); - return result; - } -} - -[TestFixture] -[NonParallelizable] -public class SequentialTests -{ - private static int _sequentialCounter = 0; - private static readonly List _executionOrder = new(); - - [Test] - [NonParallelizable] - public void SequentialTest1() - { - _executionOrder.Add(1); - _sequentialCounter++; - - Assert.That(_sequentialCounter, Is.EqualTo(_executionOrder.Count)); - Thread.Sleep(5); // Simulate work - } - - [Test] - [NonParallelizable] - public void SequentialTest2() - { - _executionOrder.Add(2); - _sequentialCounter++; - - Assert.That(_sequentialCounter, Is.EqualTo(_executionOrder.Count)); - Thread.Sleep(5); // Simulate work - } - - [Test] - [NonParallelizable] - public void SequentialTest3() - { - _executionOrder.Add(3); - _sequentialCounter++; - - Assert.That(_sequentialCounter, Is.EqualTo(_executionOrder.Count)); - Thread.Sleep(5); // Simulate work - } -} - -[TestFixture] -public class ThreadSafeTests -{ - private static readonly ConcurrentDictionary _concurrentData = new(); - private static readonly ConcurrentBag _processedItems = new(); - - [TestCase(1)] - [TestCase(2)] - [TestCase(3)] - [TestCase(4)] - [TestCase(5)] - public void ConcurrentCollectionTest(int id) - { - var key = Thread.CurrentThread.ManagedThreadId * 1000 + id; - _concurrentData[key] = $"Thread_{Thread.CurrentThread.ManagedThreadId}_Item_{id}"; - _processedItems.Add(key); - - Assert.That(_concurrentData.ContainsKey(key), Is.True); - Assert.That(_concurrentData[key], Does.Contain($"Item_{id}")); - - // Simulate some work - var sum = Enumerable.Range(1, 100).Select(x => x * id).Sum(); - Assert.That(sum, Is.EqualTo(5050 * id)); - } - - [Test] - public async Task ParallelAsyncTest() - { - var tasks = Enumerable.Range(1, 5).Select(async i => - { - await Task.Yield(); - var result = await ProcessAsync(i); - return result; - }); - - var results = await Task.WhenAll(tasks); - - Assert.That(results.Sum(), Is.EqualTo(55)); - Assert.That(results.Length, Is.EqualTo(5)); - Assert.That(results.All(r => r > 0), Is.True); - } - - private async Task ProcessAsync(int value) - { - await Task.Delay(1); - return value * value; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/RepeatTests.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/RepeatTests.cs deleted file mode 100644 index ef0390a4d7..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/RepeatTests.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace NUnitTimer; - -[TestFixture] -[Parallelizable(ParallelScope.All)] -public class RepeatTests -{ - private static int _counter = 0; - - [Test] - [Repeat(100)] - public void RepeatedCalculationTest() - { - var localCounter = Interlocked.Increment(ref _counter); - var result = PerformCalculation(localCounter); - - Assert.That(result, Is.GreaterThan(0)); - Assert.That(result, Is.EqualTo(localCounter * (localCounter + 1) / 2)); - } - - [Test] - [Repeat(50)] - public async Task RepeatedAsyncTest() - { - var taskId = Guid.NewGuid(); - var result = await ProcessDataAsync(taskId); - - Assert.That(result, Is.Not.Null); - Assert.That(result.Length, Is.EqualTo(36)); // GUID length - Assert.That(result, Is.EqualTo(taskId.ToString())); - } - - [Test] - [Repeat(25)] - public void RepeatedStringOperationTest() - { - var iteration = Interlocked.Increment(ref _counter); - var text = $"Iteration_{iteration}"; - var processed = ProcessString(text); - - Assert.That(processed, Does.Contain("PROCESSED")); - Assert.That(processed, Does.Contain(iteration.ToString())); - Assert.That(processed.Length, Is.GreaterThan(text.Length)); - } - - private int PerformCalculation(int input) - { - var result = 0; - for (var i = 1; i <= input; i++) - { - result += i; - } - return result; - } - - private async Task ProcessDataAsync(Guid id) - { - await Task.Yield(); - return id.ToString(); - } - - private string ProcessString(string input) - { - return $"PROCESSED_{input.ToUpper()}_{input.Length}"; - } -} diff --git a/tools/speed-comparison/NUnitTimer/NUnitTimer/SetupTeardownTests.cs b/tools/speed-comparison/NUnitTimer/NUnitTimer/SetupTeardownTests.cs deleted file mode 100644 index 9110456224..0000000000 --- a/tools/speed-comparison/NUnitTimer/NUnitTimer/SetupTeardownTests.cs +++ /dev/null @@ -1,153 +0,0 @@ -namespace NUnitTimer; - -[TestFixture] -public class SetupTeardownTests : IDisposable -{ - private List _testData; - private Dictionary _cache; - private int _setupCounter; - - public SetupTeardownTests() - { - // Constructor - _testData = new List(); - _cache = new Dictionary(); - _setupCounter = 0; - } - - [SetUp] - public void BeforeEachTest() - { - _setupCounter++; - _testData.Clear(); - _testData.AddRange(new[] { "Apple", "Banana", "Cherry", "Date", "Elderberry" }); - - _cache.Clear(); - for (var i = 0; i < 10; i++) - { - _cache[i] = $"Value_{i}"; - } - } - - [TearDown] - public void AfterEachTest() - { - _testData.Clear(); - _cache.Clear(); - } - - [Test] - public void TestWithSetupData() - { - Assert.That(_testData.Count, Is.EqualTo(5)); - Assert.That(_testData[0], Is.EqualTo("Apple")); - Assert.That(_cache.Count, Is.EqualTo(10)); - Assert.That(_cache[5], Is.EqualTo("Value_5")); - - _testData.Add("Fig"); - Assert.That(_testData.Count, Is.EqualTo(6)); - } - - [Test] - public void TestDataIsolation() - { - Assert.That(_testData.Count, Is.EqualTo(5)); - Assert.That(_cache.Count, Is.EqualTo(10)); - - _testData.RemoveAt(0); - _cache.Remove(0); - - Assert.That(_testData.Count, Is.EqualTo(4)); - Assert.That(_cache.Count, Is.EqualTo(9)); - } - - [Test] - public void TestWithDataManipulation() - { - var sorted = _testData.OrderBy(x => x).ToList(); - var reversed = _testData.AsEnumerable().Reverse().ToList(); - - Assert.That(sorted[0], Is.EqualTo("Apple")); - Assert.That(sorted[4], Is.EqualTo("Elderberry")); - Assert.That(reversed[0], Is.EqualTo("Elderberry")); - Assert.That(reversed[4], Is.EqualTo("Apple")); - } - - [Test] - [Repeat(5)] - public void RepeatedTestWithSetup() - { - Assert.That(_testData.Count, Is.EqualTo(5)); - Assert.That(_cache.Count, Is.EqualTo(10)); - - var sum = _cache.Keys.Sum(); - Assert.That(sum, Is.EqualTo(45)); - } - - public void Dispose() - { - _testData?.Clear(); - _cache?.Clear(); - } -} - -[TestFixture] -public class ClassSetupTeardownTests -{ - private static List _sharedData = new(); - private static bool _isInitialized; - - [OneTimeSetUp] - public static void ClassSetup() - { - _isInitialized = true; - _sharedData = Enumerable.Range(1, 100).ToList(); - } - - [OneTimeTearDown] - public static void ClassTeardown() - { - _isInitialized = false; - _sharedData.Clear(); - } - - [Test] - public void TestUsingClassData1() - { - Assert.That(_isInitialized, Is.True); - Assert.That(_sharedData.Count, Is.EqualTo(100)); - Assert.That(_sharedData.Sum(), Is.EqualTo(5050)); - } - - [Test] - public void TestUsingClassData2() - { - Assert.That(_isInitialized, Is.True); - var evens = _sharedData.Where(x => x % 2 == 0).ToList(); - Assert.That(evens.Count, Is.EqualTo(50)); - Assert.That(evens.Sum(), Is.EqualTo(2550)); - } - - [Test] - public void TestUsingClassData3() - { - Assert.That(_isInitialized, Is.True); - var primes = _sharedData.Where(IsPrime).ToList(); - Assert.That(primes.Count, Is.EqualTo(25)); - Assert.That(primes.First(), Is.EqualTo(2)); - } - - private static bool IsPrime(int n) - { - if (n <= 1) return false; - if (n <= 3) return true; - if (n % 2 == 0 || n % 3 == 0) return false; - - for (var i = 5; i * i <= n; i += 6) - { - if (n % i == 0 || n % (i + 2) == 0) - return false; - } - return true; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/.gitignore b/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/.gitignore deleted file mode 100644 index e7f23b0ef5..0000000000 --- a/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/projectSettingsUpdater.xml -/contentModel.xml -/.idea.TUnitTimer.iml -/modules.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/encodings.xml b/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/encodings.xml deleted file mode 100644 index df87cf951f..0000000000 --- a/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/material_theme_project_new.xml b/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/material_theme_project_new.xml deleted file mode 100644 index a4167976b0..0000000000 --- a/tools/speed-comparison/TUnitTimer/.idea/.idea.TUnitTimer/.idea/material_theme_project_new.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer.sln b/tools/speed-comparison/TUnitTimer/TUnitTimer.sln deleted file mode 100644 index afaabce29c..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer.sln +++ /dev/null @@ -1,16 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TUnitTimer", "TUnitTimer\TUnitTimer.csproj", "{0605DBCB-35BA-45DF-BC16-2307DDF2ACC8}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0605DBCB-35BA-45DF-BC16-2307DDF2ACC8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0605DBCB-35BA-45DF-BC16-2307DDF2ACC8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0605DBCB-35BA-45DF-BC16-2307DDF2ACC8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0605DBCB-35BA-45DF-BC16-2307DDF2ACC8}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/AssertionTests.cs b/tools/speed-comparison/TUnitTimer/TUnitTimer/AssertionTests.cs deleted file mode 100644 index 1dfabab562..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/AssertionTests.cs +++ /dev/null @@ -1,164 +0,0 @@ -using System.Threading.Tasks; - -namespace TUnitTimer; - -public class AssertionTests -{ - [Test] - public async Task NumericAssertionsTest() - { - var value = 42; - var pi = 3.14159; - var negative = -10; - - await Assert.That(value).IsEqualTo(42); - await Assert.That(value).IsGreaterThan(40); - await Assert.That(value).IsLessThan(50); - await Assert.That(value).IsBetween(40, 45).WithInclusiveBounds(); - - await Assert.That(pi).IsEqualTo(3.14159); - await Assert.That(pi).IsGreaterThan(3.0); - await Assert.That(pi).IsNotEqualTo(3.14); - - await Assert.That(negative).IsNegative(); - await Assert.That(negative).IsLessThan(0); - } - - [Test] - public async Task StringAssertionsTest() - { - var text = "Hello, TUnit Framework!"; - var empty = ""; - var whitespace = " "; - - await Assert.That(text).IsNotNull(); - await Assert.That(text).IsNotEmpty(); - await Assert.That(text).Contains("TUnit"); - await Assert.That(text).StartsWith("Hello"); - await Assert.That(text).EndsWith("!"); - await Assert.That(text).HasLength().EqualTo(23); - - await Assert.That(empty).IsEmpty(); - await Assert.That(whitespace).IsNotEmpty(); - await Assert.That(text).DoesNotContain("XUnit"); - } - - [Test] - public async Task CollectionAssertionsTest() - { - var numbers = new List { 1, 2, 3, 4, 5 }; - var empty = new List(); - var duplicates = new[] { 1, 2, 2, 3, 3, 3 }; - - await Assert.That(numbers).IsNotNull(); - await Assert.That(numbers).IsNotEmpty(); - await Assert.That(numbers).HasCount(5); - await Assert.That(numbers).Contains(3); - await Assert.That(numbers).DoesNotContain(10); - - await Assert.That(empty).IsEmpty(); - await Assert.That(empty).HasCount(0); - - await Assert.That(duplicates).Contains(2); - await Assert.That(duplicates.Distinct()).HasCount(3); - } - - [Test] - public async Task BooleanAssertionsTest() - { - var isTrue = true; - var isFalse = false; - var condition = 10 > 5; - - await Assert.That(isTrue).IsTrue(); - await Assert.That(isFalse).IsFalse(); - await Assert.That(condition).IsTrue(); - await Assert.That(!condition).IsFalse(); - - await Assert.That(string.IsNullOrEmpty("")).IsTrue(); - await Assert.That(string.IsNullOrEmpty("text")).IsFalse(); - } - - [Test] - public async Task ObjectAssertionsTest() - { - var obj1 = new TestObject { Id = 1, Name = "Test" }; - var obj2 = new TestObject { Id = 1, Name = "Test" }; - var obj3 = obj1; - TestObject? nullObj = null; - - await Assert.That(obj1).IsNotNull(); - await Assert.That(nullObj).IsNull(); - await Assert.That(obj1).IsEqualTo(obj2); // Equals comparison - await Assert.That(obj1).IsSameReferenceAs(obj3); - await Assert.That(obj1).IsNotSameReferenceAs(obj2); - - await Assert.That(obj1.GetType()).IsEqualTo(typeof(TestObject)); - } - - [Test] - public async Task ComplexAssertionsTest() - { - var data = GenerateTestData(); - - await Assert.That(data).IsNotNull(); - await Assert.That(data.Count).IsGreaterThan(0); - - var firstItem = data.First(); - await Assert.That(firstItem.Id).IsEqualTo(1); - await Assert.That(firstItem.Values).IsNotEmpty(); - await Assert.That(firstItem.Values.Sum()).IsEqualTo(15); - - var allValid = data.All(x => x.IsValid); - await Assert.That(allValid).IsTrue(); - - var totalSum = data.SelectMany(x => x.Values).Sum(); - await Assert.That(totalSum).IsEqualTo(120); - } - - [Test] - [Arguments(new[] { 1, 2, 3 }, 6)] - [Arguments(new[] { 10, 20, 30 }, 60)] - [Arguments(new[] { -5, 0, 5 }, 0)] - public async Task ParameterizedAssertionsTest(int[] values, int expectedSum) - { - await Assert.That(values).IsNotNull(); - await Assert.That(values).IsNotEmpty(); - await Assert.That(values.Sum()).IsEqualTo(expectedSum); - await Assert.That(values.Length).IsGreaterThan(0); - await Assert.That(values.Average()).IsEqualTo((double) expectedSum / values.Length); - } - - private List GenerateTestData() - { - return new List - { - new() { Id = 1, Name = "First", Values = new[] { 1, 2, 3, 4, 5 }, IsValid = true }, - new() { Id = 2, Name = "Second", Values = new[] { 6, 7, 8, 9, 10 }, IsValid = true }, - new() { Id = 3, Name = "Third", Values = new[] { 11, 12, 13, 14, 15 }, IsValid = true } - }; - } - - private class TestObject : IEquatable - { - public int Id { get; set; } - public string Name { get; set; } = ""; - - public bool Equals(TestObject? other) - { - if (other is null) return false; - return Id == other.Id && Name == other.Name; - } - - public override bool Equals(object? obj) => Equals(obj as TestObject); - public override int GetHashCode() => HashCode.Combine(Id, Name); - } - - private class ComplexTestObject - { - public int Id { get; set; } - public string Name { get; set; } = ""; - public int[] Values { get; set; } = Array.Empty(); - public bool IsValid { get; set; } - } -} diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/AsyncTests.cs b/tools/speed-comparison/TUnitTimer/TUnitTimer/AsyncTests.cs deleted file mode 100644 index 914bebe7fd..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/AsyncTests.cs +++ /dev/null @@ -1,169 +0,0 @@ -using System.Threading.Tasks; - -namespace TUnitTimer; - -public class AsyncTests -{ - [Test] - public async Task SimpleAsyncTest() - { - var result = await ComputeAsync(10); - await Assert.That(result).IsEqualTo(100); - - var text = await ProcessTextAsync("hello"); - await Assert.That(text).IsEqualTo("HELLO"); - } - - [Test] - public async Task AsyncStreamOperationsTest() - { - using var stream = new MemoryStream(); - using var writer = new StreamWriter(stream); - using var reader = new StreamReader(stream); - - await writer.WriteLineAsync("Line 1"); - await writer.WriteLineAsync("Line 2"); - await writer.WriteLineAsync("Line 3"); - await writer.FlushAsync(); - - stream.Position = 0; - - var lines = new List(); - string? line; - while ((line = await reader.ReadLineAsync()) != null) - { - lines.Add(line); - } - - await Assert.That(lines).HasCount(3); - await Assert.That(lines[0]).IsEqualTo("Line 1"); - await Assert.That(lines[2]).IsEqualTo("Line 3"); - } - - [Test] - public async Task ConcurrentTasksTest() - { - var tasks = new[] - { - ComputeAsync(5), - ComputeAsync(10), - ComputeAsync(15), - ComputeAsync(20) - }; - - var results = await Task.WhenAll(tasks); - - await Assert.That(results).HasCount(4); - await Assert.That(results[0]).IsEqualTo(25); - await Assert.That(results[1]).IsEqualTo(100); - await Assert.That(results[2]).IsEqualTo(225); - await Assert.That(results[3]).IsEqualTo(400); - await Assert.That(results.Sum()).IsEqualTo(750); - } - - [Test] - public async Task AsyncEnumerableTest() - { - var sum = 0; - var count = 0; - - await foreach (var value in GenerateValuesAsync()) - { - sum += value; - count++; - } - - await Assert.That(count).IsEqualTo(10); - await Assert.That(sum).IsEqualTo(55); - } - - [Test] - public async Task AsyncFileSimulationTest() - { - var data = await SimulateFileReadAsync("test.txt"); - var lines = data.Split('\n'); - - await Assert.That(lines).HasCount(5); - await Assert.That(lines[0]).IsEqualTo("Header: Test File"); - await Assert.That(lines[4]).IsEqualTo("Footer: End of File"); - - var processed = await SimulateFileProcessAsync(data); - await Assert.That(processed).Contains("PROCESSED"); - } - - [Test] - [Arguments(10)] - [Arguments(20)] - [Arguments(30)] - public async Task ParameterizedAsyncTest(int input) - { - var result = await ComputeAsync(input); - await Assert.That(result).IsEqualTo(input * input); - - var delayed = await DelayedComputeAsync(input, 10); - await Assert.That(delayed).IsEqualTo(input + 10); - } - - [Test] - public async Task AsyncExceptionHandlingTest() - { - try - { - var result = await SafeComputeAsync(10); - await Assert.That(result).IsEqualTo(100); - - result = await SafeComputeAsync(-1); - await Assert.That(result).IsEqualTo(0); - } - catch - { - Assert.Fail("Should not throw"); - } - } - - private async Task ComputeAsync(int value) - { - await Task.Yield(); - return value * value; - } - - private async Task ProcessTextAsync(string text) - { - await Task.Yield(); - return text.ToUpper(); - } - - private async IAsyncEnumerable GenerateValuesAsync() - { - for (var i = 1; i <= 10; i++) - { - await Task.Yield(); - yield return i; - } - } - - private async Task SimulateFileReadAsync(string filename) - { - await Task.Yield(); - return $"Header: Test File\nLine 1: Data\nLine 2: More Data\nLine 3: Even More Data\nFooter: End of File"; - } - - private async Task SimulateFileProcessAsync(string content) - { - await Task.Yield(); - return $"PROCESSED: {content.Length} characters"; - } - - private async Task DelayedComputeAsync(int value, int delay) - { - await Task.Delay(1); - return value + delay; - } - - private async Task SafeComputeAsync(int value) - { - await Task.Yield(); - if (value < 0) return 0; - return value * value; - } -} diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/BasicTests.cs b/tools/speed-comparison/TUnitTimer/TUnitTimer/BasicTests.cs deleted file mode 100644 index 71c60ba9d4..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/BasicTests.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System.Threading.Tasks; - -namespace TUnitTimer; - -public class BasicTests -{ - [Test] - public async Task SimpleTest() - { - var result = CalculateSum(5, 10); - await Assert.That(result).IsEqualTo(15); - } - - [Test] - public async Task MultipleAssertionsTest() - { - var text = "Hello, World!"; - var numbers = new[] { 1, 2, 3, 4, 5 }; - - await Assert.That(text).IsNotNull(); - await Assert.That(text.Length).IsEqualTo(13); - await Assert.That(text).Contains("World"); - - await Assert.That(numbers).HasCount(5); - await Assert.That(numbers.Sum()).IsEqualTo(15); - await Assert.That(numbers).Contains(3); - } - - [Test] - public async Task CollectionOperationsTest() - { - var items = Enumerable.Range(1, 100).ToList(); - var filtered = items.Where(x => x % 2 == 0).ToList(); - var sum = filtered.Sum(); - - await Assert.That(filtered).HasCount(50); - await Assert.That(sum).IsEqualTo(2550); - await Assert.That(filtered.First()).IsEqualTo(2); - await Assert.That(filtered.Last()).IsEqualTo(100); - } - - [Test] - public async Task StringManipulationTest() - { - var input = " Hello, TUnit Testing Framework! "; - var trimmed = input.Trim(); - var upper = trimmed.ToUpper(); - var words = trimmed.Split(' '); - - await Assert.That(trimmed).IsEqualTo("Hello, TUnit Testing Framework!"); - await Assert.That(upper).IsEqualTo("HELLO, TUNIT TESTING FRAMEWORK!"); - await Assert.That(words).HasCount(4); - await Assert.That(words[1]).IsEqualTo("TUnit"); - } - - [Test] - public async Task DictionaryOperationsTest() - { - var dictionary = new Dictionary(); - for (var i = 0; i < 50; i++) - { - dictionary[$"key{i}"] = i * i; - } - - await Assert.That(dictionary).HasCount(50); - await Assert.That(dictionary["key10"]).IsEqualTo(100); - await Assert.That(dictionary.ContainsKey("key25")).IsTrue(); - await Assert.That(dictionary.Values.Sum()).IsEqualTo(40425); - } - - private int CalculateSum(int a, int b) => a + b; -} diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/DataDrivenTests.cs b/tools/speed-comparison/TUnitTimer/TUnitTimer/DataDrivenTests.cs deleted file mode 100644 index 9b7781c2de..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/DataDrivenTests.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System.Threading.Tasks; - -namespace TUnitTimer; - -public class DataDrivenTests -{ - [Test] - [Arguments(1, 2, 3)] - [Arguments(10, 20, 30)] - [Arguments(-5, 5, 0)] - [Arguments(100, 200, 300)] - public async Task ParameterizedAdditionTest(int a, int b, int expected) - { - var result = a + b; - await Assert.That(result).IsEqualTo(expected); - } - - [Test] - [Arguments("hello", "HELLO")] - [Arguments("world", "WORLD")] - [Arguments("TUnit", "TUNIT")] - [Arguments("Testing", "TESTING")] - [Arguments("Framework", "FRAMEWORK")] - public async Task ParameterizedStringTest(string input, string expected) - { - var result = input.ToUpper(); - await Assert.That(result).IsEqualTo(expected); - await Assert.That(result.Length).IsEqualTo(input.Length); - } - - [Test] - [MethodDataSource(nameof(ComplexTestData))] - public async Task MethodDataSourceTest(TestData data) - { - var result = ProcessTestData(data); - - await Assert.That(result.Id).IsEqualTo(data.Id); - await Assert.That(result.ProcessedValue).IsEqualTo(data.Value * 2); - await Assert.That(result.IsValid).IsTrue(); - } - - [Test] - [ClassDataSource] - public async Task ClassDataSourceTest(TestData testData) - { - await Assert.That(testData.Value).IsEqualTo(0); - } - - [Test] - [Arguments(new int[] { 1, 2, 3, 4, 5 }, 15)] - [Arguments(new int[] { 10, 20, 30 }, 60)] - [Arguments(new int[] { -5, 0, 5 }, 0)] - [Arguments(new int[] { 100 }, 100)] - public async Task ArrayParameterTest(int[] numbers, int expectedSum) - { - var sum = numbers.Sum(); - var average = numbers.Average(); - - await Assert.That(sum).IsEqualTo(expectedSum); - await Assert.That(average).IsEqualTo((double) expectedSum / numbers.Length); - await Assert.That(numbers).IsNotEmpty(); - } - - public static IEnumerable> ComplexTestData() - { - yield return () => new TestData { Id = 1, Value = 10, Name = "Test1" }; - yield return () => new TestData { Id = 2, Value = 20, Name = "Test2" }; - yield return () => new TestData { Id = 3, Value = 30, Name = "Test3" }; - yield return () => new TestData { Id = 4, Value = 40, Name = "Test4" }; - yield return () => new TestData { Id = 5, Value = 50, Name = "Test5" }; - } - - private ProcessedData ProcessTestData(TestData data) - { - return new ProcessedData - { - Id = data.Id, - ProcessedValue = data.Value * 2, - IsValid = true - }; - } - - public class TestData - { - public int Id { get; set; } - public int Value { get; set; } - public string Name { get; set; } = ""; - } - - public class ProcessedData - { - public int Id { get; set; } - public int ProcessedValue { get; set; } - public bool IsValid { get; set; } - } - - public class TestDataProvider : DataSourceGeneratorAttribute - { - protected override IEnumerable> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata) - { - yield return () => (1, "First", true); - yield return () => (2, "Second", true); - yield return () => (3, "Third", true); - yield return () => (4, "Fourth", true); - yield return () => (5, "Fifth", true); - } - } -} diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/GlobalUsings.cs b/tools/speed-comparison/TUnitTimer/TUnitTimer/GlobalUsings.cs deleted file mode 100644 index 7aa3922f1f..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using TUnit.Core; \ No newline at end of file diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/ParallelTests.cs b/tools/speed-comparison/TUnitTimer/TUnitTimer/ParallelTests.cs deleted file mode 100644 index 0abdf35408..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/ParallelTests.cs +++ /dev/null @@ -1,171 +0,0 @@ -using System.Collections.Concurrent; -using System.Threading.Tasks; - -namespace TUnitTimer; - -public class ParallelTests -{ - private static readonly object _lock = new(); - private static int _sharedCounter = 0; - - [Test] - public async Task ParallelTest1() - { - var localData = ProcessData(Enumerable.Range(1, 1000).ToList()); - await Assert.That(localData.Sum()).IsEqualTo(500500); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Test] - public async Task ParallelTest2() - { - var localData = ProcessData(Enumerable.Range(1001, 1000).ToList()); - await Assert.That(localData.Sum()).IsEqualTo(1500500); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Test] - public async Task ParallelTest3() - { - var localData = ProcessData(Enumerable.Range(2001, 1000).ToList()); - await Assert.That(localData.Sum()).IsEqualTo(2500500); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Test] - public async Task ParallelTest4() - { - var localData = ProcessData(Enumerable.Range(3001, 1000).ToList()); - await Assert.That(localData.Sum()).IsEqualTo(3500500); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Test] - public async Task ParallelTest5() - { - var localData = ProcessData(Enumerable.Range(4001, 1000).ToList()); - await Assert.That(localData.Sum()).IsEqualTo(4500500); - - lock (_lock) - { - _sharedCounter++; - } - } - - private List ProcessData(List input) - { - // Simulate some CPU work - var result = new List(input.Count); - foreach (var item in input) - { - result.Add(item); - } - result.Sort(); - return result; - } -} - -[NotInParallel("sequential-group")] -public class SequentialTests -{ - private static int _sequentialCounter = 0; - private static readonly List _executionOrder = new(); - - [Test] - [NotInParallel("sequential-group")] - public async Task SequentialTest1() - { - _executionOrder.Add(1); - _sequentialCounter++; - - await Assert.That(_sequentialCounter).IsEqualTo(_executionOrder.Count); - Thread.Sleep(5); // Simulate work - } - - [Test] - [NotInParallel("sequential-group")] - public async Task SequentialTest2() - { - _executionOrder.Add(2); - _sequentialCounter++; - - await Assert.That(_sequentialCounter).IsEqualTo(_executionOrder.Count); - Thread.Sleep(5); // Simulate work - } - - [Test] - [NotInParallel("sequential-group")] - public async Task SequentialTest3() - { - _executionOrder.Add(3); - _sequentialCounter++; - - await Assert.That(_sequentialCounter).IsEqualTo(_executionOrder.Count); - Thread.Sleep(5); // Simulate work - } -} - -public class ThreadSafeTests -{ - private static readonly ConcurrentDictionary _concurrentData = new(); - private static readonly ConcurrentBag _processedItems = new(); - - [Test] - [Arguments(1)] - [Arguments(2)] - [Arguments(3)] - [Arguments(4)] - [Arguments(5)] - public async Task ConcurrentCollectionTest(int id) - { - var key = Thread.CurrentThread.ManagedThreadId * 1000 + id; - _concurrentData[key] = $"Thread_{Thread.CurrentThread.ManagedThreadId}_Item_{id}"; - _processedItems.Add(key); - - await Assert.That(_concurrentData.ContainsKey(key)).IsTrue(); - await Assert.That(_concurrentData[key]).Contains($"Item_{id}"); - - // Simulate some work - var sum = Enumerable.Range(1, 100).Select(x => x * id).Sum(); - await Assert.That(sum).IsEqualTo(5050 * id); - } - - [Test] - public async Task ParallelAsyncTest() - { - var tasks = Enumerable.Range(1, 5).Select(async i => - { - await Task.Yield(); - var result = await ProcessAsync(i); - return result; - }); - - var results = await Task.WhenAll(tasks); - - await Assert.That(results.Sum()).IsEqualTo(55); - await Assert.That(results).HasCount(5); - await Assert.That(results.All(r => r > 0)).IsTrue(); - } - - private async Task ProcessAsync(int value) - { - await Task.Delay(1); - return value * value; - } -} diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/RepeatTests.cs b/tools/speed-comparison/TUnitTimer/TUnitTimer/RepeatTests.cs deleted file mode 100644 index 5a91157fd2..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/RepeatTests.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Threading.Tasks; - -namespace TUnitTimer; - -public class RepeatTests -{ - private static int _counter = 0; - - [Test] - [Repeat(100)] - public async Task RepeatedCalculationTest() - { - var localCounter = Interlocked.Increment(ref _counter); - var result = PerformCalculation(localCounter); - - await Assert.That(result).IsGreaterThan(0); - await Assert.That(result).IsEqualTo(localCounter * (localCounter + 1) / 2); - } - - [Test] - [Repeat(50)] - public async Task RepeatedAsyncTest() - { - var taskId = Guid.NewGuid(); - var result = await ProcessDataAsync(taskId); - - await Assert.That(result).IsNotNull(); - await Assert.That(result.Length).IsEqualTo(36); // GUID length - await Assert.That(result).IsEqualTo(taskId.ToString()); - } - - [Test] - [Repeat(25)] - public async Task RepeatedStringOperationTest() - { - var iteration = Interlocked.Increment(ref _counter); - var text = $"Iteration_{iteration}"; - var processed = ProcessString(text); - - await Assert.That(processed).Contains("PROCESSED"); - await Assert.That(processed).Contains(iteration.ToString()); - await Assert.That(processed.Length).IsGreaterThan(text.Length); - } - - private int PerformCalculation(int input) - { - var result = 0; - for (var i = 1; i <= input; i++) - { - result += i; - } - return result; - } - - private async Task ProcessDataAsync(Guid id) - { - await Task.Yield(); - return id.ToString(); - } - - private string ProcessString(string input) - { - return $"PROCESSED_{input.ToUpper()}_{input.Length}"; - } -} diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/SetupTeardownTests.cs b/tools/speed-comparison/TUnitTimer/TUnitTimer/SetupTeardownTests.cs deleted file mode 100644 index 4b72b166d9..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/SetupTeardownTests.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System.Threading.Tasks; - -namespace TUnitTimer; - -public class SetupTeardownTests : IDisposable -{ - private List _testData; - private Dictionary _cache; - private int _setupCounter; - - public SetupTeardownTests() - { - // Constructor acts as setup - _testData = new List(); - _cache = new Dictionary(); - _setupCounter = 0; - } - - [Before(Test)] - public void BeforeEachTest() - { - _setupCounter++; - _testData.Clear(); - _testData.AddRange(new[] { "Apple", "Banana", "Cherry", "Date", "Elderberry" }); - - _cache.Clear(); - for (var i = 0; i < 10; i++) - { - _cache[i] = $"Value_{i}"; - } - } - - [After(Test)] - public void AfterEachTest() - { - _testData.Clear(); - _cache.Clear(); - } - - [Test] - public async Task TestWithSetupData() - { - await Assert.That(_testData).HasCount(5); - await Assert.That(_testData[0]).IsEqualTo("Apple"); - await Assert.That(_cache).HasCount(10); - await Assert.That(_cache[5]).IsEqualTo("Value_5"); - - _testData.Add("Fig"); - await Assert.That(_testData).HasCount(6); - } - - [Test] - public async Task TestDataIsolation() - { - await Assert.That(_testData).HasCount(5); - await Assert.That(_cache).HasCount(10); - - _testData.RemoveAt(0); - _cache.Remove(0); - - await Assert.That(_testData).HasCount(4); - await Assert.That(_cache).HasCount(9); - } - - [Test] - public async Task TestWithDataManipulation() - { - var sorted = _testData.OrderBy(x => x).ToList(); - var reversed = _testData.AsEnumerable().Reverse().ToList(); - - await Assert.That(sorted[0]).IsEqualTo("Apple"); - await Assert.That(sorted[4]).IsEqualTo("Elderberry"); - await Assert.That(reversed[0]).IsEqualTo("Elderberry"); - await Assert.That(reversed[4]).IsEqualTo("Apple"); - } - - [Test] - [Repeat(5)] - public async Task RepeatedTestWithSetup() - { - await Assert.That(_testData).HasCount(5); - await Assert.That(_cache).HasCount(10); - - var sum = _cache.Keys.Sum(); - await Assert.That(sum).IsEqualTo(45); - } - - public void Dispose() - { - _testData?.Clear(); - _cache?.Clear(); - } -} - -public class ClassSetupTeardownTests -{ - private static List _sharedData = new(); - private static bool _isInitialized; - - [Before(Class)] - public static void ClassSetup() - { - _isInitialized = true; - _sharedData = Enumerable.Range(1, 100).ToList(); - } - - [After(Class)] - public static void ClassTeardown() - { - _isInitialized = false; - _sharedData.Clear(); - } - - [Test] - public async Task TestUsingClassData1() - { - await Assert.That(_isInitialized).IsTrue(); - await Assert.That(_sharedData).HasCount(100); - await Assert.That(_sharedData.Sum()).IsEqualTo(5050); - } - - [Test] - public async Task TestUsingClassData2() - { - await Assert.That(_isInitialized).IsTrue(); - var evens = _sharedData.Where(x => x % 2 == 0).ToList(); - await Assert.That(evens).HasCount(50); - await Assert.That(evens.Sum()).IsEqualTo(2550); - } - - [Test] - public async Task TestUsingClassData3() - { - await Assert.That(_isInitialized).IsTrue(); - var primes = _sharedData.Where(IsPrime).ToList(); - await Assert.That(primes).HasCount(25); - await Assert.That(primes.First()).IsEqualTo(2); - } - - private static bool IsPrime(int n) - { - if (n <= 1) return false; - if (n <= 3) return true; - if (n % 2 == 0 || n % 3 == 0) return false; - - for (var i = 5; i * i <= n; i += 6) - { - if (n % i == 0 || n % (i + 2) == 0) - return false; - } - return true; - } -} diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/TUnitTimer.csproj b/tools/speed-comparison/TUnitTimer/TUnitTimer/TUnitTimer.csproj deleted file mode 100644 index b2b55663fb..0000000000 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/TUnitTimer.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - net8.0;net9.0 - enable - enable - Exe - - - - - - - true - true - - - - true - true - - - diff --git a/tools/speed-comparison/TestProjects.sln b/tools/speed-comparison/TestProjects.sln index 6d326352a8..63fd4e6933 100644 --- a/tools/speed-comparison/TestProjects.sln +++ b/tools/speed-comparison/TestProjects.sln @@ -1,12 +1,6 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xUnitTimer", "xUnitTimer\xUnitTimer\xUnitTimer.csproj", "{D28BD752-BB18-4C2E-85C9-FA965EC55FBA}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TUnitTimer", "TUnitTimer\TUnitTimer\TUnitTimer.csproj", "{8653B65B-DE48-49D3-9D88-A36E457F4106}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NUnitTimer", "NUnitTimer\NUnitTimer\NUnitTimer.csproj", "{8D6D3A0C-C844-432E-AABE-184DC9970101}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MSTestTimer", "MSTestTimer\MSTestTimer\MSTestTimer.csproj", "{B225ACB3-8E1B-4649-8D51-ADBFCFFA48E8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnifiedTests", "UnifiedTests\UnifiedTests.csproj", "{A1B2C3D4-E5F6-7890-ABCD-EF1234567890}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Benchmark", "Tests.Benchmark\Tests.Benchmark.csproj", "{F8678629-33C9-4A75-9575-CB8EC1DA218E}" EndProject @@ -16,25 +10,13 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D28BD752-BB18-4C2E-85C9-FA965EC55FBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D28BD752-BB18-4C2E-85C9-FA965EC55FBA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D28BD752-BB18-4C2E-85C9-FA965EC55FBA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D28BD752-BB18-4C2E-85C9-FA965EC55FBA}.Release|Any CPU.Build.0 = Release|Any CPU - {8653B65B-DE48-49D3-9D88-A36E457F4106}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8653B65B-DE48-49D3-9D88-A36E457F4106}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8653B65B-DE48-49D3-9D88-A36E457F4106}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8653B65B-DE48-49D3-9D88-A36E457F4106}.Release|Any CPU.Build.0 = Release|Any CPU - {8D6D3A0C-C844-432E-AABE-184DC9970101}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8D6D3A0C-C844-432E-AABE-184DC9970101}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8D6D3A0C-C844-432E-AABE-184DC9970101}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8D6D3A0C-C844-432E-AABE-184DC9970101}.Release|Any CPU.Build.0 = Release|Any CPU - {B225ACB3-8E1B-4649-8D51-ADBFCFFA48E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B225ACB3-8E1B-4649-8D51-ADBFCFFA48E8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B225ACB3-8E1B-4649-8D51-ADBFCFFA48E8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B225ACB3-8E1B-4649-8D51-ADBFCFFA48E8}.Release|Any CPU.Build.0 = Release|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A1B2C3D4-E5F6-7890-ABCD-EF1234567890}.Release|Any CPU.Build.0 = Release|Any CPU {F8678629-33C9-4A75-9575-CB8EC1DA218E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F8678629-33C9-4A75-9575-CB8EC1DA218E}.Debug|Any CPU.Build.0 = Debug|Any CPU {F8678629-33C9-4A75-9575-CB8EC1DA218E}.Release|Any CPU.ActiveCfg = Release|Any CPU {F8678629-33C9-4A75-9575-CB8EC1DA218E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection -EndGlobal +EndGlobal \ No newline at end of file diff --git a/tools/speed-comparison/Tests.Benchmark/BenchmarkBase.cs b/tools/speed-comparison/Tests.Benchmark/BenchmarkBase.cs index 24b95598c1..26444d27b6 100644 --- a/tools/speed-comparison/Tests.Benchmark/BenchmarkBase.cs +++ b/tools/speed-comparison/Tests.Benchmark/BenchmarkBase.cs @@ -8,10 +8,7 @@ public class BenchmarkBase { protected readonly Stream OutputStream = Console.OpenStandardOutput(); - protected static readonly string UnitPath = GetProjectPath("TUnitTimer"); - protected static readonly string NUnitPath = GetProjectPath("NUnitTimer"); - protected static readonly string XUnitPath = GetProjectPath("xUnitTimer"); - protected static readonly string MsTestPath = GetProjectPath("MSTestTimer"); + protected static readonly string UnifiedPath = GetProjectPath("UnifiedTests"); protected static readonly string Framework = GetFramework(); @@ -35,16 +32,16 @@ private static string GetProjectPath(string name) folder = folder.Parent!; } - return Path.Combine(folder.FullName, name, name); + return Path.Combine(folder.FullName, name); } protected string GetExecutableFileName() { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - return "TUnitTimer.exe"; + return "UnifiedTests.exe"; } - return "TUnitTimer"; + return "UnifiedTests"; } } diff --git a/tools/speed-comparison/Tests.Benchmark/BuildBenchmarks.cs b/tools/speed-comparison/Tests.Benchmark/BuildBenchmarks.cs index c750ecb229..b7bc062221 100644 --- a/tools/speed-comparison/Tests.Benchmark/BuildBenchmarks.cs +++ b/tools/speed-comparison/Tests.Benchmark/BuildBenchmarks.cs @@ -10,8 +10,8 @@ public class BuildBenchmarks : BenchmarkBase public async Task Build_TUnit() { await Cli.Wrap("dotnet") - .WithArguments(["build", "--no-incremental", "-c", "Release", "--framework", Framework]) - .WithWorkingDirectory(UnitPath) + .WithArguments(["build", "--no-incremental", "-c", "Release", "-p:TestFramework=TUNIT", "--framework", Framework]) + .WithWorkingDirectory(UnifiedPath) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); } @@ -20,8 +20,8 @@ await Cli.Wrap("dotnet") public async Task Build_NUnit() { await Cli.Wrap("dotnet") - .WithArguments(["build", "--no-incremental", "-c", "Release", "--framework", Framework]) - .WithWorkingDirectory(NUnitPath) + .WithArguments(["build", "--no-incremental", "-c", "Release", "-p:TestFramework=NUNIT", "--framework", Framework]) + .WithWorkingDirectory(UnifiedPath) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); } @@ -30,8 +30,8 @@ await Cli.Wrap("dotnet") public async Task Build_xUnit() { await Cli.Wrap("dotnet") - .WithArguments(["build", "--no-incremental", "-c", "Release", "--framework", Framework]) - .WithWorkingDirectory(XUnitPath) + .WithArguments(["build", "--no-incremental", "-c", "Release", "-p:TestFramework=XUNIT", "--framework", Framework]) + .WithWorkingDirectory(UnifiedPath) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); } @@ -40,8 +40,8 @@ await Cli.Wrap("dotnet") public async Task Build_MSTest() { await Cli.Wrap("dotnet") - .WithArguments(["build", "--no-incremental", "-c", "Release", "--framework", Framework]) - .WithWorkingDirectory(MsTestPath) + .WithArguments(["build", "--no-incremental", "-c", "Release", "-p:TestFramework=MSTEST", "--framework", Framework]) + .WithWorkingDirectory(UnifiedPath) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); } diff --git a/tools/speed-comparison/Tests.Benchmark/RuntimeBenchmarks.cs b/tools/speed-comparison/Tests.Benchmark/RuntimeBenchmarks.cs index bd7c27dad1..5734fd7234 100644 --- a/tools/speed-comparison/Tests.Benchmark/RuntimeBenchmarks.cs +++ b/tools/speed-comparison/Tests.Benchmark/RuntimeBenchmarks.cs @@ -1,4 +1,5 @@ -using BenchmarkDotNet.Attributes; +using System.Runtime.InteropServices; +using BenchmarkDotNet.Attributes; using CliWrap; namespace Tests.Benchmark; @@ -7,12 +8,34 @@ namespace Tests.Benchmark; public class RuntimeBenchmarks : BenchmarkBase { private static readonly string? ClassName = Environment.GetEnvironmentVariable("CLASS_NAME"); + + [GlobalSetup] + public async Task Setup() + { + // Build all framework configurations + await Cli.Wrap("dotnet") + .WithArguments(["build", UnifiedPath, "-c", "Release", "-p:TestFramework=TUNIT", "--framework", Framework]) + .ExecuteAsync(); + await Cli.Wrap("dotnet") + .WithArguments(["build", UnifiedPath, "-c", "Release", "-p:TestFramework=XUNIT", "--framework", Framework]) + .ExecuteAsync(); + await Cli.Wrap("dotnet") + .WithArguments(["build", UnifiedPath, "-c", "Release", "-p:TestFramework=NUNIT", "--framework", Framework]) + .ExecuteAsync(); + await Cli.Wrap("dotnet") + .WithArguments(["build", UnifiedPath, "-c", "Release", "-p:TestFramework=MSTEST", "--framework", Framework]) + .ExecuteAsync(); + } [Benchmark] - [BenchmarkCategory("Runtime")] + [BenchmarkCategory("Runtime", "AOT")] public async Task TUnit_AOT() { - await Cli.Wrap(Path.Combine(UnitPath, $"aot-publish-{Framework.Replace(".0", "")}", GetExecutableFileName())) + // Note: AOT build must be done separately with: dotnet publish -c Release -p:TestFramework=TUNIT -p:PublishAot=true + var aotPath = Path.Combine(UnifiedPath, "bin", "Release", Framework, "publish"); + var exeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "UnifiedTests.exe" : "UnifiedTests"; + + await Cli.Wrap(Path.Combine(aotPath, exeName)) .WithArguments(["--treenode-filter", $"/*/*/{ClassName}/*"]) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); @@ -22,8 +45,8 @@ await Cli.Wrap(Path.Combine(UnitPath, $"aot-publish-{Framework.Replace(".0", "") public async Task TUnit() { await Cli.Wrap("dotnet") - .WithArguments(["run", "--no-build", "-c", "Release", "--treenode-filter", $"/*/*/{ClassName}/*", "--framework", Framework]) - .WithWorkingDirectory(UnitPath) + .WithArguments(["run", "--no-build", "-c", "Release", "-p:TestFramework=TUNIT", "--treenode-filter", $"/*/*/{ClassName}/*", "--framework", Framework]) + .WithWorkingDirectory(UnifiedPath) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); } @@ -32,8 +55,8 @@ await Cli.Wrap("dotnet") public async Task NUnit() { await Cli.Wrap("dotnet") - .WithArguments(["test", "--no-build", "-c", "Release", "--filter", $"FullyQualifiedName~{ClassName}", "--framework", Framework]) - .WithWorkingDirectory(NUnitPath) + .WithArguments(["test", "--no-build", "-c", "Release", "-p:TestFramework=NUNIT", "--filter", $"FullyQualifiedName~{ClassName}", "--framework", Framework]) + .WithWorkingDirectory(UnifiedPath) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); } @@ -42,8 +65,8 @@ await Cli.Wrap("dotnet") public async Task xUnit() { await Cli.Wrap("dotnet") - .WithArguments(["test", "--no-build", "-c", "Release", "--filter", $"FullyQualifiedName~{ClassName}", "--framework", Framework]) - .WithWorkingDirectory(XUnitPath) + .WithArguments(["test", "--no-build", "-c", "Release", "-p:TestFramework=XUNIT", "--filter", $"FullyQualifiedName~{ClassName}", "--framework", Framework]) + .WithWorkingDirectory(UnifiedPath) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); } @@ -52,8 +75,8 @@ await Cli.Wrap("dotnet") public async Task MSTest() { await Cli.Wrap("dotnet") - .WithArguments(["test", "--no-build", "-c", "Release", "--filter", $"FullyQualifiedName~{ClassName}", "--framework", Framework]) - .WithWorkingDirectory(MsTestPath) + .WithArguments(["test", "--no-build", "-c", "Release", "-p:TestFramework=MSTEST", "--filter", $"FullyQualifiedName~{ClassName}", "--framework", Framework]) + .WithWorkingDirectory(UnifiedPath) .WithStandardOutputPipe(PipeTarget.ToStream(OutputStream)) .ExecuteAsync(); } diff --git a/tools/speed-comparison/UnifiedTests/AssertionTests.cs b/tools/speed-comparison/UnifiedTests/AssertionTests.cs new file mode 100644 index 0000000000..b7be932221 --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/AssertionTests.cs @@ -0,0 +1,302 @@ +using System.Threading.Tasks; + +namespace UnifiedTests; + +#if MSTEST +[TestClass] +#elif NUNIT +[TestFixture] +#endif +public class AssertionTests +{ +#if TUNIT + [Test] + public async Task NumericAssertionsTest() +#elif XUNIT + [Fact] + public void NumericAssertionsTest() +#elif NUNIT + [Test] + public void NumericAssertionsTest() +#elif MSTEST + [TestMethod] + public void NumericAssertionsTest() +#endif + { + var value = 42; + var pi = 3.14159; + var negative = -10; + +#if TUNIT + await Assert.That(value).IsEqualTo(42); + await Assert.That(value).IsGreaterThan(40); + await Assert.That(value).IsLessThan(50); + await Assert.That(value).IsBetween(40, 45).WithInclusiveBounds(); + + await Assert.That(pi).IsEqualTo(3.14159); + await Assert.That(pi).IsGreaterThan(3.0); + await Assert.That(pi).IsNotEqualTo(3.14); + + await Assert.That(negative).IsNegative(); + await Assert.That(negative).IsLessThan(0); +#elif XUNIT + Assert.Equal(42, value); + Assert.True(value > 40); + Assert.True(value < 50); + Assert.InRange(value, 40, 45); + + Assert.Equal(3.14159, pi); + Assert.True(pi > 3.0); + Assert.NotEqual(3.14, pi); + + Assert.True(negative < 0); +#elif NUNIT + Assert.That(value, Is.EqualTo(42)); + Assert.That(value, Is.GreaterThan(40)); + Assert.That(value, Is.LessThan(50)); + Assert.That(value, Is.InRange(40, 45)); + + Assert.That(pi, Is.EqualTo(3.14159)); + Assert.That(pi, Is.GreaterThan(3.0)); + Assert.That(pi, Is.Not.EqualTo(3.14)); + + Assert.That(negative, Is.Negative); + Assert.That(negative, Is.LessThan(0)); +#elif MSTEST + Assert.AreEqual(42, value); + Assert.IsTrue(value > 40); + Assert.IsTrue(value < 50); + Assert.IsTrue(value >= 40 && value <= 45); + + Assert.AreEqual(3.14159, pi); + Assert.IsTrue(pi > 3.0); + Assert.AreNotEqual(3.14, pi); + + Assert.IsTrue(negative < 0); +#endif + } + +#if TUNIT + [Test] + public async Task StringAssertionsTest() +#elif XUNIT + [Fact] + public void StringAssertionsTest() +#elif NUNIT + [Test] + public void StringAssertionsTest() +#elif MSTEST + [TestMethod] + public void StringAssertionsTest() +#endif + { +#if TUNIT + var text = "Hello, TUnit Framework!"; +#elif XUNIT + var text = "Hello, xUnit Framework!"; +#elif NUNIT + var text = "Hello, NUnit Framework!"; +#elif MSTEST + var text = "Hello, MSTest Framework!"; +#endif + var empty = ""; + var whitespace = " "; + +#if TUNIT + await Assert.That(text).IsNotNull(); + await Assert.That(text).IsNotEmpty(); + await Assert.That(text).Contains("TUnit"); + await Assert.That(text).StartsWith("Hello"); + await Assert.That(text).EndsWith("!"); + await Assert.That(text).HasLength().EqualTo(23); + + await Assert.That(empty).IsEmpty(); + await Assert.That(whitespace).IsNotEmpty(); + await Assert.That(text).DoesNotContain("XUnit"); +#elif XUNIT + Assert.NotNull(text); + Assert.NotEmpty(text); + Assert.Contains("xUnit", text); + Assert.StartsWith("Hello", text); + Assert.EndsWith("!", text); + Assert.Equal(23, text.Length); + + Assert.Empty(empty); + Assert.NotEmpty(whitespace); + Assert.DoesNotContain("TUnit", text); +#elif NUNIT + Assert.That(text, Is.Not.Null); + Assert.That(text, Is.Not.Empty); + Assert.That(text, Does.Contain("NUnit")); + Assert.That(text, Does.StartWith("Hello")); + Assert.That(text, Does.EndWith("!")); + Assert.That(text.Length, Is.EqualTo(23)); + + Assert.That(empty, Is.Empty); + Assert.That(whitespace, Is.Not.Empty); + Assert.That(text, Does.Not.Contain("XUnit")); +#elif MSTEST + Assert.IsNotNull(text); + Assert.IsTrue(!string.IsNullOrEmpty(text)); + Assert.IsTrue(text.Contains("MSTest")); + Assert.IsTrue(text.StartsWith("Hello")); + Assert.IsTrue(text.EndsWith("!")); + Assert.AreEqual(24, text.Length); + + Assert.AreEqual(string.Empty, empty); + Assert.IsTrue(!string.IsNullOrEmpty(whitespace)); + Assert.IsFalse(text.Contains("XUnit")); +#endif + } + +#if TUNIT + [Test] + public async Task CollectionAssertionsTest() +#elif XUNIT + [Fact] + public void CollectionAssertionsTest() +#elif NUNIT + [Test] + public void CollectionAssertionsTest() +#elif MSTEST + [TestMethod] + public void CollectionAssertionsTest() +#endif + { + var numbers = new List { 1, 2, 3, 4, 5 }; + var empty = new List(); + var duplicates = new[] { 1, 2, 2, 3, 3, 3 }; + +#if TUNIT + await Assert.That(numbers).IsNotNull(); + await Assert.That(numbers).IsNotEmpty(); + await Assert.That(numbers).HasCount(5); + await Assert.That(numbers).Contains(3); + await Assert.That(numbers).DoesNotContain(10); + + await Assert.That(empty).IsEmpty(); + await Assert.That(empty).HasCount(0); + + await Assert.That(duplicates).HasCount(6); + await Assert.That(duplicates).Contains(2); +#elif XUNIT + Assert.NotNull(numbers); + Assert.NotEmpty(numbers); + Assert.Equal(5, numbers.Count); + Assert.Contains(3, numbers); + Assert.DoesNotContain(10, numbers); + + Assert.Empty(empty); + Assert.Equal(0, empty.Count); + + Assert.Equal(6, duplicates.Length); + Assert.Contains(2, duplicates); +#elif NUNIT + Assert.That(numbers, Is.Not.Null); + Assert.That(numbers, Is.Not.Empty); + Assert.That(numbers.Count, Is.EqualTo(5)); + Assert.That(numbers, Does.Contain(3)); + Assert.That(numbers, Does.Not.Contain(10)); + + Assert.That(empty, Is.Empty); + Assert.That(empty.Count, Is.EqualTo(0)); + + Assert.That(duplicates.Length, Is.EqualTo(6)); + Assert.That(duplicates, Does.Contain(2)); +#elif MSTEST + Assert.IsNotNull(numbers); + Assert.IsTrue(numbers.Count > 0); + Assert.AreEqual(5, numbers.Count); + CollectionAssert.Contains(numbers, 3); + CollectionAssert.DoesNotContain(numbers, 10); + + Assert.AreEqual(0, empty.Count); + + Assert.AreEqual(6, duplicates.Length); + CollectionAssert.Contains(duplicates, 2); +#endif + } + +#if TUNIT + [Test] + public async Task BooleanAssertionsTest() +#elif XUNIT + [Fact] + public void BooleanAssertionsTest() +#elif NUNIT + [Test] + public void BooleanAssertionsTest() +#elif MSTEST + [TestMethod] + public void BooleanAssertionsTest() +#endif + { + var isTrue = true; + var isFalse = false; + var condition = 10 > 5; + +#if TUNIT + await Assert.That(isTrue).IsTrue(); + await Assert.That(isFalse).IsFalse(); + await Assert.That(condition).IsTrue(); + await Assert.That(!condition).IsFalse(); +#elif XUNIT + Assert.True(isTrue); + Assert.False(isFalse); + Assert.True(condition); + Assert.False(!condition); +#elif NUNIT + Assert.That(isTrue, Is.True); + Assert.That(isFalse, Is.False); + Assert.That(condition, Is.True); + Assert.That(!condition, Is.False); +#elif MSTEST + Assert.IsTrue(isTrue); + Assert.IsFalse(isFalse); + Assert.IsTrue(condition); + Assert.IsFalse(!condition); +#endif + } + +#if TUNIT + [Test] + public async Task ExceptionAssertionsTest() +#elif XUNIT + [Fact] + public void ExceptionAssertionsTest() +#elif NUNIT + [Test] + public void ExceptionAssertionsTest() +#elif MSTEST + [TestMethod] + public void ExceptionAssertionsTest() +#endif + { + Func throwingFunc = () => throw new InvalidOperationException("Test exception"); + Func nonThrowingFunc = () => 42; + +#if TUNIT + await Assert.That(throwingFunc).Throws(); + // TUnit doesn't have DoesNotThrow, just call the function + var result = nonThrowingFunc(); + await Assert.That(result).IsEqualTo(42); +#elif XUNIT + Assert.Throws(() => throwingFunc()); + var result = Record.Exception(() => nonThrowingFunc()); + Assert.Null(result); +#elif NUNIT + Assert.That(throwingFunc, Throws.TypeOf()); + Assert.That(nonThrowingFunc, Throws.Nothing); +#elif MSTEST + Assert.ThrowsException(() => throwingFunc()); + try + { + nonThrowingFunc(); + } + catch + { + Assert.Fail("Should not throw exception"); + } +#endif + } +} \ No newline at end of file diff --git a/tools/speed-comparison/UnifiedTests/AsyncTests.cs b/tools/speed-comparison/UnifiedTests/AsyncTests.cs new file mode 100644 index 0000000000..1c016f127c --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/AsyncTests.cs @@ -0,0 +1,96 @@ +using System.Threading.Tasks; + +namespace UnifiedTests; + +#if MSTEST +[TestClass] +#elif NUNIT +[TestFixture] +#endif +public class AsyncTests +{ +#if TUNIT + [Test] + public async Task SimpleAsyncTest() +#elif XUNIT + [Fact] + public async Task SimpleAsyncTest() +#elif NUNIT + [Test] + public async Task SimpleAsyncTest() +#elif MSTEST + [TestMethod] + public async Task SimpleAsyncTest() +#endif + { + var result = await ComputeAsync(10); +#if TUNIT + await Assert.That(result).IsEqualTo(100); +#elif XUNIT + Assert.Equal(100, result); +#elif NUNIT + Assert.That(result, Is.EqualTo(100)); +#elif MSTEST + Assert.AreEqual(100, result); +#endif + + var text = await ProcessTextAsync("hello"); +#if TUNIT + await Assert.That(text).IsEqualTo("HELLO"); +#elif XUNIT + Assert.Equal("HELLO", text); +#elif NUNIT + Assert.That(text, Is.EqualTo("HELLO")); +#elif MSTEST + Assert.AreEqual("HELLO", text); +#endif + } + +#if TUNIT + [Test] + public async Task ParallelAsyncOperationsTest() +#elif XUNIT + [Fact] + public async Task ParallelAsyncOperationsTest() +#elif NUNIT + [Test] + public async Task ParallelAsyncOperationsTest() +#elif MSTEST + [TestMethod] + public async Task ParallelAsyncOperationsTest() +#endif + { + var tasks = Enumerable.Range(0, 10) + .Select(i => ComputeAsync(i)) + .ToArray(); + + var results = await Task.WhenAll(tasks); + var sum = results.Sum(); + +#if TUNIT + await Assert.That(results).HasCount(10); + await Assert.That(sum).IsEqualTo(285); +#elif XUNIT + Assert.Equal(10, results.Length); + Assert.Equal(285, sum); +#elif NUNIT + Assert.That(results.Length, Is.EqualTo(10)); + Assert.That(sum, Is.EqualTo(285)); +#elif MSTEST + Assert.AreEqual(10, results.Length); + Assert.AreEqual(285, sum); +#endif + } + + private async Task ComputeAsync(int value) + { + await Task.Delay(1); + return value * value; + } + + private async Task ProcessTextAsync(string text) + { + await Task.Delay(1); + return text.ToUpper(); + } +} \ No newline at end of file diff --git a/tools/speed-comparison/UnifiedTests/BasicTests.cs b/tools/speed-comparison/UnifiedTests/BasicTests.cs new file mode 100644 index 0000000000..12a78e1f04 --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/BasicTests.cs @@ -0,0 +1,225 @@ +using System.Threading.Tasks; + +namespace UnifiedTests; + +#if MSTEST +[TestClass] +#elif NUNIT +[TestFixture] +#endif +public class BasicTests +{ +#if TUNIT + [Test] + public async Task SimpleTest() +#elif XUNIT + [Fact] + public void SimpleTest() +#elif NUNIT + [Test] + public void SimpleTest() +#elif MSTEST + [TestMethod] + public void SimpleTest() +#endif + { + var result = CalculateSum(5, 10); +#if TUNIT + await Assert.That(result).IsEqualTo(15); +#elif XUNIT + Assert.Equal(15, result); +#elif NUNIT + Assert.That(result, Is.EqualTo(15)); +#elif MSTEST + Assert.AreEqual(15, result); +#endif + } + +#if TUNIT + [Test] + public async Task MultipleAssertionsTest() +#elif XUNIT + [Fact] + public void MultipleAssertionsTest() +#elif NUNIT + [Test] + public void MultipleAssertionsTest() +#elif MSTEST + [TestMethod] + public void MultipleAssertionsTest() +#endif + { + var text = "Hello, World!"; + var numbers = new[] { 1, 2, 3, 4, 5 }; + +#if TUNIT + await Assert.That(text).IsNotNull(); + await Assert.That(text.Length).IsEqualTo(13); + await Assert.That(text).Contains("World"); + + await Assert.That(numbers).HasCount(5); + await Assert.That(numbers.Sum()).IsEqualTo(15); + await Assert.That(numbers).Contains(3); +#elif XUNIT + Assert.NotNull(text); + Assert.Equal(13, text.Length); + Assert.Contains("World", text); + + Assert.Equal(5, numbers.Length); + Assert.Equal(15, numbers.Sum()); + Assert.Contains(3, numbers); +#elif NUNIT + Assert.That(text, Is.Not.Null); + Assert.That(text.Length, Is.EqualTo(13)); + Assert.That(text, Does.Contain("World")); + + Assert.That(numbers.Length, Is.EqualTo(5)); + Assert.That(numbers.Sum(), Is.EqualTo(15)); + Assert.That(numbers, Does.Contain(3)); +#elif MSTEST + Assert.IsNotNull(text); + Assert.AreEqual(13, text.Length); + Assert.IsTrue(text.Contains("World")); + + Assert.AreEqual(5, numbers.Length); + Assert.AreEqual(15, numbers.Sum()); + CollectionAssert.Contains(numbers, 3); +#endif + } + +#if TUNIT + [Test] + public async Task CollectionOperationsTest() +#elif XUNIT + [Fact] + public void CollectionOperationsTest() +#elif NUNIT + [Test] + public void CollectionOperationsTest() +#elif MSTEST + [TestMethod] + public void CollectionOperationsTest() +#endif + { + var items = Enumerable.Range(1, 100).ToList(); + var filtered = items.Where(x => x % 2 == 0).ToList(); + var sum = filtered.Sum(); + +#if TUNIT + await Assert.That(filtered).HasCount(50); + await Assert.That(sum).IsEqualTo(2550); + await Assert.That(filtered.First()).IsEqualTo(2); + await Assert.That(filtered.Last()).IsEqualTo(100); +#elif XUNIT + Assert.Equal(50, filtered.Count); + Assert.Equal(2550, sum); + Assert.Equal(2, filtered.First()); + Assert.Equal(100, filtered.Last()); +#elif NUNIT + Assert.That(filtered.Count, Is.EqualTo(50)); + Assert.That(sum, Is.EqualTo(2550)); + Assert.That(filtered.First(), Is.EqualTo(2)); + Assert.That(filtered.Last(), Is.EqualTo(100)); +#elif MSTEST + Assert.AreEqual(50, filtered.Count); + Assert.AreEqual(2550, sum); + Assert.AreEqual(2, filtered.First()); + Assert.AreEqual(100, filtered.Last()); +#endif + } + +#if TUNIT + [Test] + public async Task StringManipulationTest() +#elif XUNIT + [Fact] + public void StringManipulationTest() +#elif NUNIT + [Test] + public void StringManipulationTest() +#elif MSTEST + [TestMethod] + public void StringManipulationTest() +#endif + { +#if TUNIT + var input = " Hello, TUnit Testing Framework! "; +#elif XUNIT + var input = " Hello, xUnit Testing Framework! "; +#elif NUNIT + var input = " Hello, NUnit Testing Framework! "; +#elif MSTEST + var input = " Hello, MSTest Testing Framework! "; +#endif + var trimmed = input.Trim(); + var upper = trimmed.ToUpper(); + var words = trimmed.Split(' '); + +#if TUNIT + await Assert.That(trimmed).IsEqualTo("Hello, TUnit Testing Framework!"); + await Assert.That(upper).IsEqualTo("HELLO, TUNIT TESTING FRAMEWORK!"); + await Assert.That(words).HasCount(4); + await Assert.That(words[1]).IsEqualTo("TUnit"); +#elif XUNIT + Assert.Equal("Hello, xUnit Testing Framework!", trimmed); + Assert.Equal("HELLO, XUNIT TESTING FRAMEWORK!", upper); + Assert.Equal(4, words.Length); + Assert.Equal("xUnit", words[1]); +#elif NUNIT + Assert.That(trimmed, Is.EqualTo("Hello, NUnit Testing Framework!")); + Assert.That(upper, Is.EqualTo("HELLO, NUNIT TESTING FRAMEWORK!")); + Assert.That(words.Length, Is.EqualTo(4)); + Assert.That(words[1], Is.EqualTo("NUnit")); +#elif MSTEST + Assert.AreEqual("Hello, MSTest Testing Framework!", trimmed); + Assert.AreEqual("HELLO, MSTEST TESTING FRAMEWORK!", upper); + Assert.AreEqual(4, words.Length); + Assert.AreEqual("MSTest", words[1]); +#endif + } + +#if TUNIT + [Test] + public async Task DictionaryOperationsTest() +#elif XUNIT + [Fact] + public void DictionaryOperationsTest() +#elif NUNIT + [Test] + public void DictionaryOperationsTest() +#elif MSTEST + [TestMethod] + public void DictionaryOperationsTest() +#endif + { + var dictionary = new Dictionary(); + for (var i = 0; i < 50; i++) + { + dictionary[$"key{i}"] = i * i; + } + +#if TUNIT + await Assert.That(dictionary).HasCount(50); + await Assert.That(dictionary["key10"]).IsEqualTo(100); + await Assert.That(dictionary.ContainsKey("key25")).IsTrue(); + await Assert.That(dictionary.Values.Sum()).IsEqualTo(40425); +#elif XUNIT + Assert.Equal(50, dictionary.Count); + Assert.Equal(100, dictionary["key10"]); + Assert.True(dictionary.ContainsKey("key25")); + Assert.Equal(40425, dictionary.Values.Sum()); +#elif NUNIT + Assert.That(dictionary.Count, Is.EqualTo(50)); + Assert.That(dictionary["key10"], Is.EqualTo(100)); + Assert.That(dictionary.ContainsKey("key25"), Is.True); + Assert.That(dictionary.Values.Sum(), Is.EqualTo(40425)); +#elif MSTEST + Assert.AreEqual(50, dictionary.Count); + Assert.AreEqual(100, dictionary["key10"]); + Assert.IsTrue(dictionary.ContainsKey("key25")); + Assert.AreEqual(40425, dictionary.Values.Sum()); +#endif + } + + private int CalculateSum(int a, int b) => a + b; +} \ No newline at end of file diff --git a/tools/speed-comparison/UnifiedTests/DataDrivenTests.cs b/tools/speed-comparison/UnifiedTests/DataDrivenTests.cs new file mode 100644 index 0000000000..483b78e9d1 --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/DataDrivenTests.cs @@ -0,0 +1,282 @@ +using System.Collections; +using System.Threading.Tasks; + +namespace UnifiedTests; + +#if MSTEST +[TestClass] +#elif NUNIT +[TestFixture] +#endif +public class DataDrivenTests +{ +#if TUNIT + [Test] + [Arguments(1, 2, 3)] + [Arguments(10, 20, 30)] + [Arguments(-5, 5, 0)] + [Arguments(100, 200, 300)] + public async Task ParameterizedAdditionTest(int a, int b, int expected) +#elif XUNIT + [Theory] + [InlineData(1, 2, 3)] + [InlineData(10, 20, 30)] + [InlineData(-5, 5, 0)] + [InlineData(100, 200, 300)] + public void ParameterizedAdditionTest(int a, int b, int expected) +#elif NUNIT + [TestCase(1, 2, 3)] + [TestCase(10, 20, 30)] + [TestCase(-5, 5, 0)] + [TestCase(100, 200, 300)] + public void ParameterizedAdditionTest(int a, int b, int expected) +#elif MSTEST + [TestMethod] + [DataRow(1, 2, 3)] + [DataRow(10, 20, 30)] + [DataRow(-5, 5, 0)] + [DataRow(100, 200, 300)] + public void ParameterizedAdditionTest(int a, int b, int expected) +#endif + { + var result = a + b; +#if TUNIT + await Assert.That(result).IsEqualTo(expected); +#elif XUNIT + Assert.Equal(expected, result); +#elif NUNIT + Assert.That(result, Is.EqualTo(expected)); +#elif MSTEST + Assert.AreEqual(expected, result); +#endif + } + +#if TUNIT + [Test] + [Arguments("hello", "HELLO")] + [Arguments("world", "WORLD")] + [Arguments("TUnit", "TUNIT")] + [Arguments("Testing", "TESTING")] + [Arguments("Framework", "FRAMEWORK")] + public async Task ParameterizedStringTest(string input, string expected) +#elif XUNIT + [Theory] + [InlineData("hello", "HELLO")] + [InlineData("world", "WORLD")] + [InlineData("xUnit", "XUNIT")] + [InlineData("Testing", "TESTING")] + [InlineData("Framework", "FRAMEWORK")] + public void ParameterizedStringTest(string input, string expected) +#elif NUNIT + [TestCase("hello", "HELLO")] + [TestCase("world", "WORLD")] + [TestCase("NUnit", "NUNIT")] + [TestCase("Testing", "TESTING")] + [TestCase("Framework", "FRAMEWORK")] + public void ParameterizedStringTest(string input, string expected) +#elif MSTEST + [TestMethod] + [DataRow("hello", "HELLO")] + [DataRow("world", "WORLD")] + [DataRow("MSTest", "MSTEST")] + [DataRow("Testing", "TESTING")] + [DataRow("Framework", "FRAMEWORK")] + public void ParameterizedStringTest(string input, string expected) +#endif + { + var result = input.ToUpper(); +#if TUNIT + await Assert.That(result).IsEqualTo(expected); + await Assert.That(result.Length).IsEqualTo(input.Length); +#elif XUNIT + Assert.Equal(expected, result); + Assert.Equal(input.Length, result.Length); +#elif NUNIT + Assert.That(result, Is.EqualTo(expected)); + Assert.That(result.Length, Is.EqualTo(input.Length)); +#elif MSTEST + Assert.AreEqual(expected, result); + Assert.AreEqual(input.Length, result.Length); +#endif + } + +#if TUNIT + [Test] + [MethodDataSource(nameof(ComplexTestData))] + public async Task DataSourceTest(TestData data) +#elif XUNIT + [Theory] + [MemberData(nameof(ComplexTestData))] + public void DataSourceTest(TestData data) +#elif NUNIT + [Test] + [TestCaseSource(nameof(ComplexTestData))] + public void DataSourceTest(TestData data) +#elif MSTEST + [TestMethod] + [DynamicData(nameof(ComplexTestData), DynamicDataSourceType.Method)] + public void DataSourceTest(TestData data) +#endif + { + var result = ProcessTestData(data); + +#if TUNIT + await Assert.That(result.Id).IsEqualTo(data.Id); + await Assert.That(result.ProcessedValue).IsEqualTo(data.Value * 2); + await Assert.That(result.IsValid).IsTrue(); +#elif XUNIT + Assert.Equal(data.Id, result.Id); + Assert.Equal(data.Value * 2, result.ProcessedValue); + Assert.True(result.IsValid); +#elif NUNIT + Assert.That(result.Id, Is.EqualTo(data.Id)); + Assert.That(result.ProcessedValue, Is.EqualTo(data.Value * 2)); + Assert.That(result.IsValid, Is.True); +#elif MSTEST + Assert.AreEqual(data.Id, result.Id); + Assert.AreEqual(data.Value * 2, result.ProcessedValue); + Assert.IsTrue(result.IsValid); +#endif + } + +#if TUNIT + [Test] + [Arguments(new int[] { 1, 2, 3, 4, 5 }, 15)] + [Arguments(new int[] { 10, 20, 30 }, 60)] + [Arguments(new int[] { -5, 0, 5 }, 0)] + [Arguments(new int[] { 100 }, 100)] + public async Task ArrayParameterTest(int[] numbers, int expectedSum) +#elif XUNIT + [Theory] + [InlineData(new int[] { 1, 2, 3, 4, 5 }, 15)] + [InlineData(new int[] { 10, 20, 30 }, 60)] + [InlineData(new int[] { -5, 0, 5 }, 0)] + [InlineData(new int[] { 100 }, 100)] + public void ArrayParameterTest(int[] numbers, int expectedSum) +#elif NUNIT + [TestCase(new int[] { 1, 2, 3, 4, 5 }, 15)] + [TestCase(new int[] { 10, 20, 30 }, 60)] + [TestCase(new int[] { -5, 0, 5 }, 0)] + [TestCase(new int[] { 100 }, 100)] + public void ArrayParameterTest(int[] numbers, int expectedSum) +#elif MSTEST + [TestMethod] + [DataRow(new int[] { 1, 2, 3, 4, 5 }, 15)] + [DataRow(new int[] { 10, 20, 30 }, 60)] + [DataRow(new int[] { -5, 0, 5 }, 0)] + [DataRow(new int[] { 100 }, 100)] + public void ArrayParameterTest(int[] numbers, int expectedSum) +#endif + { + var sum = numbers.Sum(); + var average = numbers.Average(); + +#if TUNIT + await Assert.That(sum).IsEqualTo(expectedSum); + await Assert.That(average).IsEqualTo((double)expectedSum / numbers.Length); + await Assert.That(numbers).IsNotEmpty(); +#elif XUNIT + Assert.Equal(expectedSum, sum); + Assert.Equal((double)expectedSum / numbers.Length, average); + Assert.NotEmpty(numbers); +#elif NUNIT + Assert.That(sum, Is.EqualTo(expectedSum)); + Assert.That(average, Is.EqualTo((double)expectedSum / numbers.Length)); + Assert.That(numbers, Is.Not.Empty); +#elif MSTEST + Assert.AreEqual(expectedSum, sum); + Assert.AreEqual((double)expectedSum / numbers.Length, average); + Assert.IsTrue(numbers.Length > 0); +#endif + } + +#if TUNIT + public static IEnumerable> ComplexTestData() + { + yield return () => new TestData { Id = 1, Value = 10, Name = "Test1" }; + yield return () => new TestData { Id = 2, Value = 20, Name = "Test2" }; + yield return () => new TestData { Id = 3, Value = 30, Name = "Test3" }; + yield return () => new TestData { Id = 4, Value = 40, Name = "Test4" }; + yield return () => new TestData { Id = 5, Value = 50, Name = "Test5" }; + } +#elif XUNIT + public static IEnumerable ComplexTestData() + { + yield return new object[] { new TestData { Id = 1, Value = 10, Name = "Test1" } }; + yield return new object[] { new TestData { Id = 2, Value = 20, Name = "Test2" } }; + yield return new object[] { new TestData { Id = 3, Value = 30, Name = "Test3" } }; + yield return new object[] { new TestData { Id = 4, Value = 40, Name = "Test4" } }; + yield return new object[] { new TestData { Id = 5, Value = 50, Name = "Test5" } }; + } +#elif NUNIT + public static IEnumerable ComplexTestData() + { + yield return new TestData { Id = 1, Value = 10, Name = "Test1" }; + yield return new TestData { Id = 2, Value = 20, Name = "Test2" }; + yield return new TestData { Id = 3, Value = 30, Name = "Test3" }; + yield return new TestData { Id = 4, Value = 40, Name = "Test4" }; + yield return new TestData { Id = 5, Value = 50, Name = "Test5" }; + } +#elif MSTEST + public static IEnumerable ComplexTestData() + { + yield return new object[] { new TestData { Id = 1, Value = 10, Name = "Test1" } }; + yield return new object[] { new TestData { Id = 2, Value = 20, Name = "Test2" } }; + yield return new object[] { new TestData { Id = 3, Value = 30, Name = "Test3" } }; + yield return new object[] { new TestData { Id = 4, Value = 40, Name = "Test4" } }; + yield return new object[] { new TestData { Id = 5, Value = 50, Name = "Test5" } }; + } +#endif + + private ProcessedData ProcessTestData(TestData data) + { + return new ProcessedData + { + Id = data.Id, + ProcessedValue = data.Value * 2, + IsValid = true + }; + } + + public class TestData + { + public int Id { get; set; } + public int Value { get; set; } + public string Name { get; set; } = ""; + } + + public class ProcessedData + { + public int Id { get; set; } + public int ProcessedValue { get; set; } + public bool IsValid { get; set; } + } + +#if XUNIT + public class TestDataProvider : IEnumerable + { + public IEnumerator GetEnumerator() + { + yield return new object[] { 1, "First", true }; + yield return new object[] { 2, "Second", true }; + yield return new object[] { 3, "Third", true }; + yield return new object[] { 4, "Fourth", true }; + yield return new object[] { 5, "Fifth", true }; + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } +#elif TUNIT + public class TestDataProvider : DataSourceGeneratorAttribute + { + protected override IEnumerable> GenerateDataSources(DataGeneratorMetadata dataGeneratorMetadata) + { + yield return () => (1, "First", true); + yield return () => (2, "Second", true); + yield return () => (3, "Third", true); + yield return () => (4, "Fourth", true); + yield return () => (5, "Fifth", true); + } + } +#endif +} \ No newline at end of file diff --git a/tools/speed-comparison/TUnitTimer/TUnitTimer/FixtureTests.cs b/tools/speed-comparison/UnifiedTests/FixtureTests.cs similarity index 51% rename from tools/speed-comparison/TUnitTimer/TUnitTimer/FixtureTests.cs rename to tools/speed-comparison/UnifiedTests/FixtureTests.cs index ce5c5e66d9..ec560e94d4 100644 --- a/tools/speed-comparison/TUnitTimer/TUnitTimer/FixtureTests.cs +++ b/tools/speed-comparison/UnifiedTests/FixtureTests.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace TUnitTimer; +namespace UnifiedTests; public interface ITestDatabase { @@ -34,31 +34,74 @@ public void Dispose() } } +#if MSTEST +[TestClass] public class FixtureTests : IDisposable +#elif NUNIT +[TestFixture] +public class FixtureTests : IDisposable +#elif XUNIT +public class FixtureTests : IDisposable, IClassFixture +#else +public class FixtureTests : IDisposable +#endif { private readonly ITestDatabase _database; private readonly List _testKeys; +#if XUNIT + public FixtureTests(TestDatabase database) + { + _database = database; + _testKeys = new List(); + SetupTest(); + } +#else public FixtureTests() { _database = new TestDatabase(); _testKeys = new List(); } +#endif +#if TUNIT [Before(Test)] public void SetupTest() +#elif MSTEST + [TestInitialize] + public void SetupTest() +#elif NUNIT + [SetUp] + public void SetupTest() +#elif XUNIT + private void SetupTest() +#endif { _testKeys.Clear(); for (var i = 0; i < 10; i++) { +#if XUNIT + var key = $"test_{Guid.NewGuid()}_{i}"; +#else var key = $"test_{i}"; +#endif _testKeys.Add(key); _database.Add(key, $"test_value_{i}"); } } +#if TUNIT [After(Test)] public void CleanupTest() +#elif MSTEST + [TestCleanup] + public void CleanupTest() +#elif NUNIT + [TearDown] + public void CleanupTest() +#elif XUNIT + private void CleanupTest() +#endif { foreach (var key in _testKeys) { @@ -67,83 +110,53 @@ public void CleanupTest() _testKeys.Clear(); } +#if TUNIT [Test] public async Task TestDatabaseOperations() +#elif XUNIT + [Fact] + public void TestDatabaseOperations() +#elif NUNIT + [Test] + public void TestDatabaseOperations() +#elif MSTEST + [TestMethod] + public void TestDatabaseOperations() +#endif { +#if TUNIT await Assert.That(_database.Count).IsGreaterThanOrEqualTo(110); - var value = _database.Get("test_5"); await Assert.That(value).IsEqualTo("test_value_5"); +#elif XUNIT + Assert.True(_database.Count >= 110); + var value = _database.Get(_testKeys[5]); + Assert.Equal("test_value_5", value); +#elif NUNIT + Assert.That(_database.Count, Is.GreaterThanOrEqualTo(110)); + var value = _database.Get("test_5"); + Assert.That(value, Is.EqualTo("test_value_5")); +#elif MSTEST + Assert.IsTrue(_database.Count >= 110); + var value = _database.Get("test_5"); + Assert.AreEqual("test_value_5", value); +#endif _database.Add("custom_key", "custom_value"); +#if TUNIT await Assert.That(_database.Get("custom_key")).IsEqualTo("custom_value"); - } - - [Test] - public async Task TestFixtureIsolation() - { - var initialCount = _database.Count; - - for (var i = 0; i < 5; i++) - { - _database.Add($"isolation_{i}", $"value_{i}"); - } - - await Assert.That(_database.Count).IsEqualTo(initialCount + 5); - await Assert.That(_database.Get("isolation_2")).IsEqualTo("value_2"); - } - - [Test] - [Repeat(3)] - public async Task TestRepeatedWithFixture() - { - await Assert.That(_testKeys).HasCount(10); - await Assert.That(_database.Get("test_0")).IsNotNull(); - await Assert.That(_database.Get("test_9")).IsNotNull(); - - var sum = _testKeys.Count + _database.Count; - await Assert.That(sum).IsGreaterThan(100); +#elif XUNIT + Assert.Equal("custom_value", _database.Get("custom_key")); + CleanupTest(); +#elif NUNIT + Assert.That(_database.Get("custom_key"), Is.EqualTo("custom_value")); +#elif MSTEST + Assert.AreEqual("custom_value", _database.Get("custom_key")); +#endif } public void Dispose() { (_database as IDisposable)?.Dispose(); } -} - -public class SharedFixtureTests -{ - private static readonly TestDatabase SharedDatabase = new(); - private readonly string _instanceId = Guid.NewGuid().ToString(); - - [Test] - public async Task TestWithSharedResource1() - { - var key = $"shared_{_instanceId}_1"; - SharedDatabase.Add(key, "value1"); - - await Assert.That(SharedDatabase.Get(key)).IsEqualTo("value1"); - await Assert.That(SharedDatabase.Count).IsGreaterThan(100); - } - - [Test] - public async Task TestWithSharedResource2() - { - var key = $"shared_{_instanceId}_2"; - SharedDatabase.Add(key, "value2"); - - await Assert.That(SharedDatabase.Get(key)).IsEqualTo("value2"); - await Assert.That(SharedDatabase.Count).IsGreaterThan(100); - } - - [Test] - public async Task TestWithSharedResource3() - { - var count = SharedDatabase.Count; - var key = $"shared_{_instanceId}_3"; - SharedDatabase.Add(key, "value3"); - - await Assert.That(SharedDatabase.Count).IsEqualTo(count + 1); - await Assert.That(SharedDatabase.Get(key)).IsNotNull(); - } -} +} \ No newline at end of file diff --git a/tools/speed-comparison/UnifiedTests/GlobalUsings.cs b/tools/speed-comparison/UnifiedTests/GlobalUsings.cs new file mode 100644 index 0000000000..12f60412ab --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/GlobalUsings.cs @@ -0,0 +1,9 @@ +#if TUNIT +global using TUnit.Core; +#elif XUNIT +global using Xunit; +#elif NUNIT +global using NUnit.Framework; +#elif MSTEST +global using Microsoft.VisualStudio.TestTools.UnitTesting; +#endif \ No newline at end of file diff --git a/tools/speed-comparison/UnifiedTests/ParallelTests.cs b/tools/speed-comparison/UnifiedTests/ParallelTests.cs new file mode 100644 index 0000000000..1a239c835b --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/ParallelTests.cs @@ -0,0 +1,416 @@ +using System.Collections.Concurrent; +using System.Threading.Tasks; + +namespace UnifiedTests; + +#if MSTEST +[TestClass] +#elif NUNIT +[TestFixture] +[Parallelizable(ParallelScope.All)] +#endif +public class ParallelTests +{ + private static readonly object _lock = new(); + private static int _sharedCounter = 0; + +#if TUNIT + [Test] + public async Task ParallelTest1() +#elif XUNIT + [Fact] + public void ParallelTest1() +#elif NUNIT + [Test] + public void ParallelTest1() +#elif MSTEST + [TestMethod] + public void ParallelTest1() +#endif + { + var localData = ProcessData(Enumerable.Range(1, 1000).ToList()); +#if TUNIT + await Assert.That(localData.Sum()).IsEqualTo(500500); +#elif XUNIT + Assert.Equal(500500, localData.Sum()); +#elif NUNIT + Assert.That(localData.Sum(), Is.EqualTo(500500)); +#elif MSTEST + Assert.AreEqual(500500, localData.Sum()); +#endif + + lock (_lock) + { + _sharedCounter++; + } + } + +#if TUNIT + [Test] + public async Task ParallelTest2() +#elif XUNIT + [Fact] + public void ParallelTest2() +#elif NUNIT + [Test] + public void ParallelTest2() +#elif MSTEST + [TestMethod] + public void ParallelTest2() +#endif + { + var localData = ProcessData(Enumerable.Range(1001, 1000).ToList()); +#if TUNIT + await Assert.That(localData.Sum()).IsEqualTo(1500500); +#elif XUNIT + Assert.Equal(1500500, localData.Sum()); +#elif NUNIT + Assert.That(localData.Sum(), Is.EqualTo(1500500)); +#elif MSTEST + Assert.AreEqual(1500500, localData.Sum()); +#endif + + lock (_lock) + { + _sharedCounter++; + } + } + +#if TUNIT + [Test] + public async Task ParallelTest3() +#elif XUNIT + [Fact] + public void ParallelTest3() +#elif NUNIT + [Test] + public void ParallelTest3() +#elif MSTEST + [TestMethod] + public void ParallelTest3() +#endif + { + var localData = ProcessData(Enumerable.Range(2001, 1000).ToList()); +#if TUNIT + await Assert.That(localData.Sum()).IsEqualTo(2500500); +#elif XUNIT + Assert.Equal(2500500, localData.Sum()); +#elif NUNIT + Assert.That(localData.Sum(), Is.EqualTo(2500500)); +#elif MSTEST + Assert.AreEqual(2500500, localData.Sum()); +#endif + + lock (_lock) + { + _sharedCounter++; + } + } + +#if TUNIT + [Test] + public async Task ParallelTest4() +#elif XUNIT + [Fact] + public void ParallelTest4() +#elif NUNIT + [Test] + public void ParallelTest4() +#elif MSTEST + [TestMethod] + public void ParallelTest4() +#endif + { + var localData = ProcessData(Enumerable.Range(3001, 1000).ToList()); +#if TUNIT + await Assert.That(localData.Sum()).IsEqualTo(3500500); +#elif XUNIT + Assert.Equal(3500500, localData.Sum()); +#elif NUNIT + Assert.That(localData.Sum(), Is.EqualTo(3500500)); +#elif MSTEST + Assert.AreEqual(3500500, localData.Sum()); +#endif + + lock (_lock) + { + _sharedCounter++; + } + } + +#if TUNIT + [Test] + public async Task ParallelTest5() +#elif XUNIT + [Fact] + public void ParallelTest5() +#elif NUNIT + [Test] + public void ParallelTest5() +#elif MSTEST + [TestMethod] + public void ParallelTest5() +#endif + { + var localData = ProcessData(Enumerable.Range(4001, 1000).ToList()); +#if TUNIT + await Assert.That(localData.Sum()).IsEqualTo(4500500); +#elif XUNIT + Assert.Equal(4500500, localData.Sum()); +#elif NUNIT + Assert.That(localData.Sum(), Is.EqualTo(4500500)); +#elif MSTEST + Assert.AreEqual(4500500, localData.Sum()); +#endif + + lock (_lock) + { + _sharedCounter++; + } + } + + private List ProcessData(List input) + { + // Simulate some CPU work + var result = new List(input.Count); + foreach (var item in input) + { + result.Add(item); + } + result.Sort(); + return result; + } +} + +#if TUNIT +[NotInParallel("sequential-group")] +public class SequentialTests +#elif NUNIT +[TestFixture] +[NonParallelizable] +public class SequentialTests +#elif MSTEST +[TestClass] +[DoNotParallelize] +public class SequentialTests +#elif XUNIT +[Collection("Sequential")] +public class SequentialTests +#endif +{ + private static int _sequentialCounter = 0; + private static readonly List _executionOrder = new(); + +#if TUNIT + [Test] + [NotInParallel("sequential-group")] + public async Task SequentialTest1() +#elif XUNIT + [Fact] + public void SequentialTest1() +#elif NUNIT + [Test] + public void SequentialTest1() +#elif MSTEST + [TestMethod] + public void SequentialTest1() +#endif + { + _executionOrder.Add(1); + _sequentialCounter++; + +#if TUNIT + await Assert.That(_sequentialCounter).IsEqualTo(_executionOrder.Count); +#elif XUNIT + Assert.Equal(_executionOrder.Count, _sequentialCounter); +#elif NUNIT + Assert.That(_sequentialCounter, Is.EqualTo(_executionOrder.Count)); +#elif MSTEST + Assert.AreEqual(_executionOrder.Count, _sequentialCounter); +#endif + Thread.Sleep(5); // Simulate work + } + +#if TUNIT + [Test] + [NotInParallel("sequential-group")] + public async Task SequentialTest2() +#elif XUNIT + [Fact] + public void SequentialTest2() +#elif NUNIT + [Test] + public void SequentialTest2() +#elif MSTEST + [TestMethod] + public void SequentialTest2() +#endif + { + _executionOrder.Add(2); + _sequentialCounter++; + +#if TUNIT + await Assert.That(_sequentialCounter).IsEqualTo(_executionOrder.Count); +#elif XUNIT + Assert.Equal(_executionOrder.Count, _sequentialCounter); +#elif NUNIT + Assert.That(_sequentialCounter, Is.EqualTo(_executionOrder.Count)); +#elif MSTEST + Assert.AreEqual(_executionOrder.Count, _sequentialCounter); +#endif + Thread.Sleep(5); // Simulate work + } + +#if TUNIT + [Test] + [NotInParallel("sequential-group")] + public async Task SequentialTest3() +#elif XUNIT + [Fact] + public void SequentialTest3() +#elif NUNIT + [Test] + public void SequentialTest3() +#elif MSTEST + [TestMethod] + public void SequentialTest3() +#endif + { + _executionOrder.Add(3); + _sequentialCounter++; + +#if TUNIT + await Assert.That(_sequentialCounter).IsEqualTo(_executionOrder.Count); +#elif XUNIT + Assert.Equal(_executionOrder.Count, _sequentialCounter); +#elif NUNIT + Assert.That(_sequentialCounter, Is.EqualTo(_executionOrder.Count)); +#elif MSTEST + Assert.AreEqual(_executionOrder.Count, _sequentialCounter); +#endif + Thread.Sleep(5); // Simulate work + } +} + +#if MSTEST +[TestClass] +#elif NUNIT +[TestFixture] +#endif +public class ThreadSafeTests +{ + private static readonly ConcurrentDictionary _concurrentData = new(); + private static readonly ConcurrentBag _processedItems = new(); + +#if TUNIT + [Test] + [Arguments(1)] + [Arguments(2)] + [Arguments(3)] + [Arguments(4)] + [Arguments(5)] + public async Task ConcurrentCollectionTest(int id) +#elif XUNIT + [Theory] + [InlineData(1)] + [InlineData(2)] + [InlineData(3)] + [InlineData(4)] + [InlineData(5)] + public void ConcurrentCollectionTest(int id) +#elif NUNIT + [TestCase(1)] + [TestCase(2)] + [TestCase(3)] + [TestCase(4)] + [TestCase(5)] + public void ConcurrentCollectionTest(int id) +#elif MSTEST + [TestMethod] + [DataRow(1)] + [DataRow(2)] + [DataRow(3)] + [DataRow(4)] + [DataRow(5)] + public void ConcurrentCollectionTest(int id) +#endif + { + var key = Thread.CurrentThread.ManagedThreadId * 1000 + id; + _concurrentData[key] = $"Thread_{Thread.CurrentThread.ManagedThreadId}_Item_{id}"; + _processedItems.Add(key); + +#if TUNIT + await Assert.That(_concurrentData.ContainsKey(key)).IsTrue(); + await Assert.That(_concurrentData[key]).Contains($"Item_{id}"); +#elif XUNIT + Assert.True(_concurrentData.ContainsKey(key)); + Assert.Contains($"Item_{id}", _concurrentData[key]); +#elif NUNIT + Assert.That(_concurrentData.ContainsKey(key), Is.True); + Assert.That(_concurrentData[key], Does.Contain($"Item_{id}")); +#elif MSTEST + Assert.IsTrue(_concurrentData.ContainsKey(key)); + Assert.IsTrue(_concurrentData[key].Contains($"Item_{id}")); +#endif + + // Simulate some work + var sum = Enumerable.Range(1, 100).Select(x => x * id).Sum(); +#if TUNIT + await Assert.That(sum).IsEqualTo(5050 * id); +#elif XUNIT + Assert.Equal(5050 * id, sum); +#elif NUNIT + Assert.That(sum, Is.EqualTo(5050 * id)); +#elif MSTEST + Assert.AreEqual(5050 * id, sum); +#endif + } + +#if TUNIT + [Test] + public async Task ParallelAsyncTest() +#elif XUNIT + [Fact] + public async Task ParallelAsyncTest() +#elif NUNIT + [Test] + public async Task ParallelAsyncTest() +#elif MSTEST + [TestMethod] + public async Task ParallelAsyncTest() +#endif + { + var tasks = Enumerable.Range(1, 5).Select(async i => + { + await Task.Yield(); + var result = await ProcessAsync(i); + return result; + }); + + var results = await Task.WhenAll(tasks); + +#if TUNIT + await Assert.That(results.Sum()).IsEqualTo(55); + await Assert.That(results).HasCount(5); + await Assert.That(results.All(r => r > 0)).IsTrue(); +#elif XUNIT + Assert.Equal(55, results.Sum()); + Assert.Equal(5, results.Length); + Assert.True(results.All(r => r > 0)); +#elif NUNIT + Assert.That(results.Sum(), Is.EqualTo(55)); + Assert.That(results.Length, Is.EqualTo(5)); + Assert.That(results.All(r => r > 0), Is.True); +#elif MSTEST + Assert.AreEqual(55, results.Sum()); + Assert.AreEqual(5, results.Length); + Assert.IsTrue(results.All(r => r > 0)); +#endif + } + + private async Task ProcessAsync(int value) + { + await Task.Delay(1); + return value * value; + } +} \ No newline at end of file diff --git a/tools/speed-comparison/UnifiedTests/RepeatTests.cs b/tools/speed-comparison/UnifiedTests/RepeatTests.cs new file mode 100644 index 0000000000..e814d4bc33 --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/RepeatTests.cs @@ -0,0 +1,175 @@ +using System.Threading.Tasks; + +namespace UnifiedTests; + +#if MSTEST +[TestClass] +#elif NUNIT +[TestFixture] +#endif +public class RepeatTests +{ + private static int _counter = 0; + + // Note: xUnit doesn't have built-in repeat functionality + // MSTest doesn't have built-in repeat, but we can simulate with DataRow + // NUnit has Repeat attribute + // TUnit has Repeat attribute + +#if TUNIT + [Test] + [Repeat(100)] + public async Task RepeatedCalculationTest() +#elif NUNIT + [Test] + [Repeat(100)] + public void RepeatedCalculationTest() +#elif XUNIT + // xUnit doesn't have Repeat, so we use Theory with range data + [Theory] + [MemberData(nameof(RepeatData), 100)] + public void RepeatedCalculationTest(int _) +#elif MSTEST + // MSTest doesn't have Repeat, simulate with multiple DataRows (limited example) + [TestMethod] + [DataRow(1)] + [DataRow(2)] + [DataRow(3)] + [DataRow(4)] + [DataRow(5)] + public void RepeatedCalculationTest(int _) +#endif + { + var localCounter = Interlocked.Increment(ref _counter); + var result = PerformCalculation(localCounter); + +#if TUNIT + await Assert.That(result).IsGreaterThan(0); + await Assert.That(result).IsEqualTo(localCounter * (localCounter + 1) / 2); +#elif XUNIT + Assert.True(result > 0); + Assert.Equal(localCounter * (localCounter + 1) / 2, result); +#elif NUNIT + Assert.That(result, Is.GreaterThan(0)); + Assert.That(result, Is.EqualTo(localCounter * (localCounter + 1) / 2)); +#elif MSTEST + Assert.IsTrue(result > 0); + Assert.AreEqual(localCounter * (localCounter + 1) / 2, result); +#endif + } + +#if TUNIT + [Test] + [Repeat(50)] + public async Task RepeatedAsyncTest() +#elif NUNIT + [Test] + [Repeat(50)] + public async Task RepeatedAsyncTest() +#elif XUNIT + [Theory] + [MemberData(nameof(RepeatData), 50)] + public async Task RepeatedAsyncTest(int _) +#elif MSTEST + [TestMethod] + [DataRow(1)] + [DataRow(2)] + [DataRow(3)] + public async Task RepeatedAsyncTest(int _) +#endif + { + var taskId = Guid.NewGuid(); + var result = await ProcessDataAsync(taskId); + +#if TUNIT + await Assert.That(result).IsNotNull(); + await Assert.That(result.Length).IsEqualTo(36); // GUID length + await Assert.That(result).IsEqualTo(taskId.ToString()); +#elif XUNIT + Assert.NotNull(result); + Assert.Equal(36, result.Length); + Assert.Equal(taskId.ToString(), result); +#elif NUNIT + Assert.That(result, Is.Not.Null); + Assert.That(result.Length, Is.EqualTo(36)); + Assert.That(result, Is.EqualTo(taskId.ToString())); +#elif MSTEST + Assert.IsNotNull(result); + Assert.AreEqual(36, result.Length); + Assert.AreEqual(taskId.ToString(), result); +#endif + } + +#if TUNIT + [Test] + [Repeat(25)] + public async Task RepeatedStringOperationTest() +#elif NUNIT + [Test] + [Repeat(25)] + public void RepeatedStringOperationTest() +#elif XUNIT + [Theory] + [MemberData(nameof(RepeatData), 25)] + public void RepeatedStringOperationTest(int _) +#elif MSTEST + [TestMethod] + [DataRow(1)] + [DataRow(2)] + public void RepeatedStringOperationTest(int _) +#endif + { + var iteration = Interlocked.Increment(ref _counter); + var text = $"Iteration_{iteration}"; + var processed = ProcessString(text); + +#if TUNIT + await Assert.That(processed).Contains("PROCESSED"); + await Assert.That(processed).Contains(iteration.ToString()); + await Assert.That(processed.Length).IsGreaterThan(text.Length); +#elif XUNIT + Assert.Contains("PROCESSED", processed); + Assert.Contains(iteration.ToString(), processed); + Assert.True(processed.Length > text.Length); +#elif NUNIT + Assert.That(processed, Does.Contain("PROCESSED")); + Assert.That(processed, Does.Contain(iteration.ToString())); + Assert.That(processed.Length, Is.GreaterThan(text.Length)); +#elif MSTEST + Assert.IsTrue(processed.Contains("PROCESSED")); + Assert.IsTrue(processed.Contains(iteration.ToString())); + Assert.IsTrue(processed.Length > text.Length); +#endif + } + + private int PerformCalculation(int input) + { + var result = 0; + for (var i = 1; i <= input; i++) + { + result += i; + } + return result; + } + + private async Task ProcessDataAsync(Guid id) + { + await Task.Yield(); + return id.ToString(); + } + + private string ProcessString(string input) + { + return $"PROCESSED_{input.ToUpper()}_{input.Length}"; + } + +#if XUNIT + public static IEnumerable RepeatData(int count) + { + for (int i = 0; i < count; i++) + { + yield return new object[] { i }; + } + } +#endif +} \ No newline at end of file diff --git a/tools/speed-comparison/UnifiedTests/SetupTeardownTests.cs b/tools/speed-comparison/UnifiedTests/SetupTeardownTests.cs new file mode 100644 index 0000000000..676278c403 --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/SetupTeardownTests.cs @@ -0,0 +1,179 @@ +using System.Threading.Tasks; + +namespace UnifiedTests; + +#if MSTEST +[TestClass] +public class SetupTeardownTests : IDisposable +#elif NUNIT +[TestFixture] +public class SetupTeardownTests : IDisposable +#elif XUNIT +public class SetupTeardownTests : IDisposable +#else +public class SetupTeardownTests : IDisposable +#endif +{ + private List _testData; + private Dictionary _cache; + private int _setupCounter; + + public SetupTeardownTests() + { + // Constructor acts as setup + _testData = new List(); + _cache = new Dictionary(); + _setupCounter = 0; + } + +#if TUNIT + [Before(Test)] + public void BeforeEachTest() +#elif MSTEST + [TestInitialize] + public void BeforeEachTest() +#elif NUNIT + [SetUp] + public void BeforeEachTest() +#elif XUNIT + private void BeforeEachTest() +#endif + { + _setupCounter++; + _testData.Clear(); + _testData.AddRange(new[] { "Apple", "Banana", "Cherry", "Date", "Elderberry" }); + + _cache.Clear(); + for (var i = 0; i < 10; i++) + { + _cache[i] = $"Value_{i}"; + } + } + +#if TUNIT + [After(Test)] + public void AfterEachTest() +#elif MSTEST + [TestCleanup] + public void AfterEachTest() +#elif NUNIT + [TearDown] + public void AfterEachTest() +#elif XUNIT + private void AfterEachTest() +#endif + { + _testData.Clear(); + _cache.Clear(); + } + +#if TUNIT + [Test] + public async Task TestWithSetupData() +#elif XUNIT + [Fact] + public void TestWithSetupData() +#elif NUNIT + [Test] + public void TestWithSetupData() +#elif MSTEST + [TestMethod] + public void TestWithSetupData() +#endif + { +#if XUNIT + BeforeEachTest(); +#endif + +#if TUNIT + await Assert.That(_testData).HasCount(5); + await Assert.That(_testData[0]).IsEqualTo("Apple"); + await Assert.That(_cache).HasCount(10); + await Assert.That(_cache[5]).IsEqualTo("Value_5"); +#elif XUNIT + Assert.Equal(5, _testData.Count); + Assert.Equal("Apple", _testData[0]); + Assert.Equal(10, _cache.Count); + Assert.Equal("Value_5", _cache[5]); +#elif NUNIT + Assert.That(_testData.Count, Is.EqualTo(5)); + Assert.That(_testData[0], Is.EqualTo("Apple")); + Assert.That(_cache.Count, Is.EqualTo(10)); + Assert.That(_cache[5], Is.EqualTo("Value_5")); +#elif MSTEST + Assert.AreEqual(5, _testData.Count); + Assert.AreEqual("Apple", _testData[0]); + Assert.AreEqual(10, _cache.Count); + Assert.AreEqual("Value_5", _cache[5]); +#endif + + _testData.Add("Fig"); +#if TUNIT + await Assert.That(_testData).HasCount(6); +#elif XUNIT + Assert.Equal(6, _testData.Count); + AfterEachTest(); +#elif NUNIT + Assert.That(_testData.Count, Is.EqualTo(6)); +#elif MSTEST + Assert.AreEqual(6, _testData.Count); +#endif + } + +#if TUNIT + [Test] + public async Task TestDataIsolation() +#elif XUNIT + [Fact] + public void TestDataIsolation() +#elif NUNIT + [Test] + public void TestDataIsolation() +#elif MSTEST + [TestMethod] + public void TestDataIsolation() +#endif + { +#if XUNIT + BeforeEachTest(); +#endif + +#if TUNIT + await Assert.That(_testData).HasCount(5); + await Assert.That(_cache).HasCount(10); +#elif XUNIT + Assert.Equal(5, _testData.Count); + Assert.Equal(10, _cache.Count); +#elif NUNIT + Assert.That(_testData.Count, Is.EqualTo(5)); + Assert.That(_cache.Count, Is.EqualTo(10)); +#elif MSTEST + Assert.AreEqual(5, _testData.Count); + Assert.AreEqual(10, _cache.Count); +#endif + + _testData.RemoveAt(0); + _cache.Remove(0); + +#if TUNIT + await Assert.That(_testData).HasCount(4); + await Assert.That(_cache).HasCount(9); +#elif XUNIT + Assert.Equal(4, _testData.Count); + Assert.Equal(9, _cache.Count); + AfterEachTest(); +#elif NUNIT + Assert.That(_testData.Count, Is.EqualTo(4)); + Assert.That(_cache.Count, Is.EqualTo(9)); +#elif MSTEST + Assert.AreEqual(4, _testData.Count); + Assert.AreEqual(9, _cache.Count); +#endif + } + + public void Dispose() + { + _testData?.Clear(); + _cache?.Clear(); + } +} \ No newline at end of file diff --git a/tools/speed-comparison/UnifiedTests/UnifiedTests.csproj b/tools/speed-comparison/UnifiedTests/UnifiedTests.csproj new file mode 100644 index 0000000000..c08597248e --- /dev/null +++ b/tools/speed-comparison/UnifiedTests/UnifiedTests.csproj @@ -0,0 +1,60 @@ + + + + net8.0;net9.0 + enable + enable + false + true + Exe + + + + + $(DefineConstants);TUNIT + $(DefineConstants);XUNIT + $(DefineConstants);NUNIT + $(DefineConstants);MSTEST + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + + + + + + + + + true + true + + + + true + true + + + \ No newline at end of file diff --git a/tools/speed-comparison/prepare-aot.bat b/tools/speed-comparison/prepare-aot.bat new file mode 100644 index 0000000000..1c32069b1b --- /dev/null +++ b/tools/speed-comparison/prepare-aot.bat @@ -0,0 +1,10 @@ +@echo off +REM Script to prepare AOT builds for benchmarking + +set FRAMEWORK=%1 +if "%FRAMEWORK%"=="" set FRAMEWORK=net8.0 + +echo Building TUnit AOT version for %FRAMEWORK%... +dotnet publish UnifiedTests\UnifiedTests.csproj -c Release -p:TestFramework=TUNIT -p:PublishAot=true --framework %FRAMEWORK% + +echo AOT build complete. Output in: UnifiedTests\bin\Release\%FRAMEWORK%\publish\ \ No newline at end of file diff --git a/tools/speed-comparison/prepare-aot.ps1 b/tools/speed-comparison/prepare-aot.ps1 new file mode 100644 index 0000000000..bbb5d2ab28 --- /dev/null +++ b/tools/speed-comparison/prepare-aot.ps1 @@ -0,0 +1,9 @@ +# Script to prepare AOT builds for benchmarking +param( + [string]$Framework = "net8.0" +) + +Write-Host "Building TUnit AOT version for $Framework..." +dotnet publish UnifiedTests/UnifiedTests.csproj -c Release -p:TestFramework=TUNIT -p:PublishAot=true --framework $Framework + +Write-Host "AOT build complete. Output in: UnifiedTests/bin/Release/$Framework/publish/" \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/.gitignore b/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/.gitignore deleted file mode 100644 index 138867d9eb..0000000000 --- a/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Rider ignored files -/contentModel.xml -/projectSettingsUpdater.xml -/.idea.xUnitTimer.iml -/modules.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/encodings.xml b/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/encodings.xml deleted file mode 100644 index df87cf951f..0000000000 --- a/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/material_theme_project_new.xml b/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/material_theme_project_new.xml deleted file mode 100644 index a4167976b0..0000000000 --- a/tools/speed-comparison/xUnitTimer/.idea/.idea.xUnitTimer/.idea/material_theme_project_new.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer.sln b/tools/speed-comparison/xUnitTimer/xUnitTimer.sln deleted file mode 100644 index 8ce1129b44..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer.sln +++ /dev/null @@ -1,16 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "xUnitTimer", "xUnitTimer\xUnitTimer.csproj", "{0A2C2D47-7551-446C-BD63-41D4FEE1CBA5}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0A2C2D47-7551-446C-BD63-41D4FEE1CBA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0A2C2D47-7551-446C-BD63-41D4FEE1CBA5}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0A2C2D47-7551-446C-BD63-41D4FEE1CBA5}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0A2C2D47-7551-446C-BD63-41D4FEE1CBA5}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection -EndGlobal diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/AssertionTests.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/AssertionTests.cs deleted file mode 100644 index 9a6177e319..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/AssertionTests.cs +++ /dev/null @@ -1,162 +0,0 @@ -namespace xUnitTimer; - -public class AssertionTests -{ - [Fact] - public void NumericAssertionsTest() - { - var value = 42; - var pi = 3.14159; - var negative = -10; - - Assert.Equal(42, value); - Assert.True(value > 40); - Assert.True(value < 50); - Assert.InRange(value, 40, 45); - - Assert.Equal(3.14159, pi); - Assert.True(pi > 3.0); - Assert.NotEqual(3.14, pi); - - Assert.True(negative < 0); - Assert.True(negative < 0); - } - - [Fact] - public void StringAssertionsTest() - { - var text = "Hello, xUnit Framework!"; - var empty = ""; - var whitespace = " "; - - Assert.NotNull(text); - Assert.NotEmpty(text); - Assert.Contains("xUnit", text); - Assert.StartsWith("Hello", text); - Assert.EndsWith("!", text); - Assert.Equal(23, text.Length); - - Assert.Empty(empty); - Assert.NotEmpty(whitespace); - Assert.DoesNotContain("TUnit", text); - } - - [Fact] - public void CollectionAssertionsTest() - { - var numbers = new List { 1, 2, 3, 4, 5 }; - var empty = new List(); - var duplicates = new[] { 1, 2, 2, 3, 3, 3 }; - - Assert.NotNull(numbers); - Assert.NotEmpty(numbers); - Assert.Equal(5, numbers.Count); - Assert.Contains(3, numbers); - Assert.DoesNotContain(10, numbers); - - Assert.Empty(empty); - Assert.Equal(0, empty.Count); - - Assert.Contains(2, duplicates); - Assert.Equal(3, duplicates.Distinct().Count()); - } - - [Fact] - public void BooleanAssertionsTest() - { - var isTrue = true; - var isFalse = false; - var condition = 10 > 5; - - Assert.True(isTrue); - Assert.False(isFalse); - Assert.True(condition); - Assert.False(!condition); - - Assert.True(string.IsNullOrEmpty("")); - Assert.False(string.IsNullOrEmpty("text")); - } - - [Fact] - public void ObjectAssertionsTest() - { - var obj1 = new TestObject { Id = 1, Name = "Test" }; - var obj2 = new TestObject { Id = 1, Name = "Test" }; - var obj3 = obj1; - TestObject? nullObj = null; - - Assert.NotNull(obj1); - Assert.Null(nullObj); - Assert.Equal(obj1, obj2); // Equals comparison - Assert.Same(obj3, obj1); - Assert.NotSame(obj2, obj1); - - Assert.Equal(typeof(TestObject), obj1.GetType()); - } - - [Fact] - public void ComplexAssertionsTest() - { - var data = GenerateTestData(); - - Assert.NotNull(data); - Assert.True(data.Count > 0); - - var firstItem = data.First(); - Assert.Equal(1, firstItem.Id); - Assert.NotEmpty(firstItem.Values); - Assert.Equal(15, firstItem.Values.Sum()); - - var allValid = data.All(x => x.IsValid); - Assert.True(allValid); - - var totalSum = data.SelectMany(x => x.Values).Sum(); - Assert.Equal(120, totalSum); - } - - [Theory] - [InlineData(new[] { 1, 2, 3 }, 6)] - [InlineData(new[] { 10, 20, 30 }, 60)] - [InlineData(new[] { -5, 0, 5 }, 0)] - public void ParameterizedAssertionsTest(int[] values, int expectedSum) - { - Assert.NotNull(values); - Assert.NotEmpty(values); - Assert.Equal(expectedSum, values.Sum()); - Assert.True(values.Length > 0); - Assert.Equal((double)expectedSum / values.Length, values.Average()); - } - - private List GenerateTestData() - { - return new List - { - new() { Id = 1, Name = "First", Values = new[] { 1, 2, 3, 4, 5 }, IsValid = true }, - new() { Id = 2, Name = "Second", Values = new[] { 6, 7, 8, 9, 10 }, IsValid = true }, - new() { Id = 3, Name = "Third", Values = new[] { 11, 12, 13, 14, 15 }, IsValid = true } - }; - } - - private class TestObject : IEquatable - { - public int Id { get; set; } - public string Name { get; set; } = ""; - - public bool Equals(TestObject? other) - { - if (other is null) return false; - return Id == other.Id && Name == other.Name; - } - - public override bool Equals(object? obj) => Equals(obj as TestObject); - public override int GetHashCode() => HashCode.Combine(Id, Name); - } - - private class ComplexTestObject - { - public int Id { get; set; } - public string Name { get; set; } = ""; - public int[] Values { get; set; } = Array.Empty(); - public bool IsValid { get; set; } - } -} \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/AsyncTests.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/AsyncTests.cs deleted file mode 100644 index ad43ceed4f..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/AsyncTests.cs +++ /dev/null @@ -1,167 +0,0 @@ -namespace xUnitTimer; - -public class AsyncTests -{ - [Fact] - public async Task SimpleAsyncTest() - { - var result = await ComputeAsync(10); - Assert.Equal(100, result); - - var text = await ProcessTextAsync("hello"); - Assert.Equal("HELLO", text); - } - - [Fact] - public async Task AsyncStreamOperationsTest() - { - using var stream = new MemoryStream(); - using var writer = new StreamWriter(stream); - using var reader = new StreamReader(stream); - - await writer.WriteLineAsync("Line 1"); - await writer.WriteLineAsync("Line 2"); - await writer.WriteLineAsync("Line 3"); - await writer.FlushAsync(); - - stream.Position = 0; - - var lines = new List(); - string? line; - while ((line = await reader.ReadLineAsync()) != null) - { - lines.Add(line); - } - - Assert.Equal(3, lines.Count); - Assert.Equal("Line 1", lines[0]); - Assert.Equal("Line 3", lines[2]); - } - - [Fact] - public async Task ConcurrentTasksTest() - { - var tasks = new[] - { - ComputeAsync(5), - ComputeAsync(10), - ComputeAsync(15), - ComputeAsync(20) - }; - - var results = await Task.WhenAll(tasks); - - Assert.Equal(4, results.Length); - Assert.Equal(25, results[0]); - Assert.Equal(100, results[1]); - Assert.Equal(225, results[2]); - Assert.Equal(400, results[3]); - Assert.Equal(750, results.Sum()); - } - - [Fact] - public async Task AsyncEnumerableTest() - { - var sum = 0; - var count = 0; - - await foreach (var value in GenerateValuesAsync()) - { - sum += value; - count++; - } - - Assert.Equal(10, count); - Assert.Equal(55, sum); - } - - [Fact] - public async Task AsyncFileSimulationTest() - { - var data = await SimulateFileReadAsync("test.txt"); - var lines = data.Split('\n'); - - Assert.Equal(5, lines.Length); - Assert.Equal("Header: Test File", lines[0]); - Assert.Equal("Footer: End of File", lines[4]); - - var processed = await SimulateFileProcessAsync(data); - Assert.Contains("PROCESSED", processed); - } - - [Theory] - [InlineData(10)] - [InlineData(20)] - [InlineData(30)] - public async Task ParameterizedAsyncTest(int input) - { - var result = await ComputeAsync(input); - Assert.Equal(input * input, result); - - var delayed = await DelayedComputeAsync(input, 10); - Assert.Equal(input + 10, delayed); - } - - [Fact] - public async Task AsyncExceptionHandlingTest() - { - try - { - var result = await SafeComputeAsync(10); - Assert.Equal(100, result); - - result = await SafeComputeAsync(-1); - Assert.Equal(0, result); - } - catch - { - Assert.True(false, "Should not throw"); - } - } - - private async Task ComputeAsync(int value) - { - await Task.Yield(); - return value * value; - } - - private async Task ProcessTextAsync(string text) - { - await Task.Yield(); - return text.ToUpper(); - } - - private async IAsyncEnumerable GenerateValuesAsync() - { - for (var i = 1; i <= 10; i++) - { - await Task.Yield(); - yield return i; - } - } - - private async Task SimulateFileReadAsync(string filename) - { - await Task.Yield(); - return $"Header: Test File\nLine 1: Data\nLine 2: More Data\nLine 3: Even More Data\nFooter: End of File"; - } - - private async Task SimulateFileProcessAsync(string content) - { - await Task.Yield(); - return $"PROCESSED: {content.Length} characters"; - } - - private async Task DelayedComputeAsync(int value, int delay) - { - await Task.Delay(1); - return value + delay; - } - - private async Task SafeComputeAsync(int value) - { - await Task.Yield(); - if (value < 0) return 0; - return value * value; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/BasicTests.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/BasicTests.cs deleted file mode 100644 index 47d14d094d..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/BasicTests.cs +++ /dev/null @@ -1,70 +0,0 @@ -namespace xUnitTimer; - -public class BasicTests -{ - [Fact] - public void SimpleTest() - { - var result = CalculateSum(5, 10); - Assert.Equal(15, result); - } - - [Fact] - public void MultipleAssertionsTest() - { - var text = "Hello, World!"; - var numbers = new[] { 1, 2, 3, 4, 5 }; - - Assert.NotNull(text); - Assert.Equal(13, text.Length); - Assert.Contains("World", text); - - Assert.Equal(5, numbers.Length); - Assert.Equal(15, numbers.Sum()); - Assert.Contains(3, numbers); - } - - [Fact] - public void CollectionOperationsTest() - { - var items = Enumerable.Range(1, 100).ToList(); - var filtered = items.Where(x => x % 2 == 0).ToList(); - var sum = filtered.Sum(); - - Assert.Equal(50, filtered.Count); - Assert.Equal(2550, sum); - Assert.Equal(2, filtered.First()); - Assert.Equal(100, filtered.Last()); - } - - [Fact] - public void StringManipulationTest() - { - var input = " Hello, xUnit Testing Framework! "; - var trimmed = input.Trim(); - var upper = trimmed.ToUpper(); - var words = trimmed.Split(' '); - - Assert.Equal("Hello, xUnit Testing Framework!", trimmed); - Assert.Equal("HELLO, XUNIT TESTING FRAMEWORK!", upper); - Assert.Equal(4, words.Length); - Assert.Equal("xUnit", words[1]); - } - - [Fact] - public void DictionaryOperationsTest() - { - var dictionary = new Dictionary(); - for (var i = 0; i < 50; i++) - { - dictionary[$"key{i}"] = i * i; - } - - Assert.Equal(50, dictionary.Count); - Assert.Equal(100, dictionary["key10"]); - Assert.True(dictionary.ContainsKey("key25")); - Assert.Equal(40425, dictionary.Values.Sum()); - } - - private int CalculateSum(int a, int b) => a + b; -} \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/DataDrivenTests.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/DataDrivenTests.cs deleted file mode 100644 index 0e8575e621..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/DataDrivenTests.cs +++ /dev/null @@ -1,113 +0,0 @@ -using System.Collections; - -namespace xUnitTimer; - -public class DataDrivenTests -{ - [Theory] - [InlineData(1, 2, 3)] - [InlineData(10, 20, 30)] - [InlineData(-5, 5, 0)] - [InlineData(100, 200, 300)] - public void ParameterizedAdditionTest(int a, int b, int expected) - { - var result = a + b; - Assert.Equal(expected, result); - } - - [Theory] - [InlineData("hello", "HELLO")] - [InlineData("world", "WORLD")] - [InlineData("xUnit", "XUNIT")] - [InlineData("Testing", "TESTING")] - [InlineData("Framework", "FRAMEWORK")] - public void ParameterizedStringTest(string input, string expected) - { - var result = input.ToUpper(); - Assert.Equal(expected, result); - Assert.Equal(input.Length, result.Length); - } - - [Theory] - [MemberData(nameof(ComplexTestData))] - public void MemberDataSourceTest(TestData data) - { - var result = ProcessTestData(data); - - Assert.Equal(data.Id, result.Id); - Assert.Equal(data.Value * 2, result.ProcessedValue); - Assert.True(result.IsValid); - } - - [Theory] - [ClassData(typeof(TestDataProvider))] - public void ClassDataSourceTest(int value, string text, bool flag) - { - Assert.True(value > 0); - Assert.NotNull(text); - Assert.True(text.Length > 0); - Assert.True(flag); - } - - [Theory] - [InlineData(new int[] { 1, 2, 3, 4, 5 }, 15)] - [InlineData(new int[] { 10, 20, 30 }, 60)] - [InlineData(new int[] { -5, 0, 5 }, 0)] - [InlineData(new int[] { 100 }, 100)] - public void ArrayParameterTest(int[] numbers, int expectedSum) - { - var sum = numbers.Sum(); - var average = numbers.Average(); - - Assert.Equal(expectedSum, sum); - Assert.Equal((double)expectedSum / numbers.Length, average); - Assert.NotEmpty(numbers); - } - - public static IEnumerable ComplexTestData() - { - yield return new object[] { new TestData { Id = 1, Value = 10, Name = "Test1" } }; - yield return new object[] { new TestData { Id = 2, Value = 20, Name = "Test2" } }; - yield return new object[] { new TestData { Id = 3, Value = 30, Name = "Test3" } }; - yield return new object[] { new TestData { Id = 4, Value = 40, Name = "Test4" } }; - yield return new object[] { new TestData { Id = 5, Value = 50, Name = "Test5" } }; - } - - private ProcessedData ProcessTestData(TestData data) - { - return new ProcessedData - { - Id = data.Id, - ProcessedValue = data.Value * 2, - IsValid = true - }; - } - - public class TestData - { - public int Id { get; set; } - public int Value { get; set; } - public string Name { get; set; } = ""; - } - - public class ProcessedData - { - public int Id { get; set; } - public int ProcessedValue { get; set; } - public bool IsValid { get; set; } - } - - public class TestDataProvider : IEnumerable - { - public IEnumerator GetEnumerator() - { - yield return new object[] { 1, "First", true }; - yield return new object[] { 2, "Second", true }; - yield return new object[] { 3, "Third", true }; - yield return new object[] { 4, "Fourth", true }; - yield return new object[] { 5, "Fifth", true }; - } - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } -} diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/FixtureTests.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/FixtureTests.cs deleted file mode 100644 index 1c46f986eb..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/FixtureTests.cs +++ /dev/null @@ -1,183 +0,0 @@ -namespace xUnitTimer; - -public interface ITestDatabase -{ - void Add(string key, string value); - string? Get(string key); - int Count { get; } - void Clear(); -} - -public class TestDatabase : ITestDatabase, IDisposable -{ - private readonly Dictionary _data = new(); - - public TestDatabase() - { - // Simulate expensive initialization - for (var i = 0; i < 100; i++) - { - _data[$"init_{i}"] = $"value_{i}"; - } - } - - public void Add(string key, string value) => _data[key] = value; - public string? Get(string key) => _data.TryGetValue(key, out var value) ? value : null; - public int Count => _data.Count; - public void Clear() => _data.Clear(); - - public void Dispose() - { - _data.Clear(); - } -} - -public class FixtureTests : IDisposable, IClassFixture -{ - private readonly ITestDatabase _database; - private readonly List _testKeys; - - public FixtureTests(TestDatabase database) - { - _database = database; - _testKeys = new List(); - SetupTest(); - } - - private void SetupTest() - { - _testKeys.Clear(); - for (var i = 0; i < 10; i++) - { - var key = $"test_{Guid.NewGuid()}_{i}"; - _testKeys.Add(key); - _database.Add(key, $"test_value_{i}"); - } - } - - private void CleanupTest() - { - foreach (var key in _testKeys) - { - _database.Add(key, "cleaned"); - } - _testKeys.Clear(); - } - - [Fact] - public void TestDatabaseOperations() - { - Assert.True(_database.Count >= 110); - - var value = _database.Get(_testKeys[5]); - Assert.Equal("test_value_5", value); - - _database.Add("custom_key", "custom_value"); - Assert.Equal("custom_value", _database.Get("custom_key")); - - CleanupTest(); - } - - [Fact] - public void TestFixtureIsolation() - { - SetupTest(); // Reset for this test - var initialCount = _database.Count; - - for (var i = 0; i < 5; i++) - { - _database.Add($"isolation_{i}", $"value_{i}"); - } - - Assert.Equal(initialCount + 5, _database.Count); - Assert.Equal("value_2", _database.Get("isolation_2")); - - CleanupTest(); - } - - [Fact] - public void TestRepeatedWithFixture() - { - for (var i = 0; i < 3; i++) - { - SetupTest(); // Reset for each iteration - - Assert.Equal(10, _testKeys.Count); - Assert.NotNull(_database.Get(_testKeys[0])); - Assert.NotNull(_database.Get(_testKeys[9])); - - var sum = _testKeys.Count + _database.Count; - Assert.True(sum > 100); - - CleanupTest(); - } - } - - public void Dispose() - { - CleanupTest(); - } -} - -public class SharedDatabaseFixture : IDisposable -{ - public TestDatabase Database { get; } - - public SharedDatabaseFixture() - { - Database = new TestDatabase(); - } - - public void Dispose() - { - Database.Dispose(); - } -} - -[CollectionDefinition("Database collection")] -public class DatabaseCollection : ICollectionFixture -{ -} - -[Collection("Database collection")] -public class SharedFixtureTests -{ - private readonly SharedDatabaseFixture _fixture; - private readonly string _instanceId = Guid.NewGuid().ToString(); - - public SharedFixtureTests(SharedDatabaseFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestWithSharedResource1() - { - var key = $"shared_{_instanceId}_1"; - _fixture.Database.Add(key, "value1"); - - Assert.Equal("value1", _fixture.Database.Get(key)); - Assert.True(_fixture.Database.Count > 100); - } - - [Fact] - public void TestWithSharedResource2() - { - var key = $"shared_{_instanceId}_2"; - _fixture.Database.Add(key, "value2"); - - Assert.Equal("value2", _fixture.Database.Get(key)); - Assert.True(_fixture.Database.Count > 100); - } - - [Fact] - public void TestWithSharedResource3() - { - var count = _fixture.Database.Count; - var key = $"shared_{_instanceId}_3"; - _fixture.Database.Add(key, "value3"); - - Assert.Equal(count + 1, _fixture.Database.Count); - Assert.NotNull(_fixture.Database.Get(key)); - } -} \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/GlobalUsings.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/GlobalUsings.cs deleted file mode 100644 index 8c927eb747..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/GlobalUsings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Xunit; \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/ParallelTests.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/ParallelTests.cs deleted file mode 100644 index 7be98cb936..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/ParallelTests.cs +++ /dev/null @@ -1,167 +0,0 @@ -using System.Collections.Concurrent; - -namespace xUnitTimer; - -public class ParallelTests -{ - private static readonly object _lock = new(); - private static int _sharedCounter = 0; - - [Fact] - public void ParallelTest1() - { - var localData = ProcessData(Enumerable.Range(1, 1000).ToList()); - Assert.Equal(500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Fact] - public void ParallelTest2() - { - var localData = ProcessData(Enumerable.Range(1001, 1000).ToList()); - Assert.Equal(1500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Fact] - public void ParallelTest3() - { - var localData = ProcessData(Enumerable.Range(2001, 1000).ToList()); - Assert.Equal(2500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Fact] - public void ParallelTest4() - { - var localData = ProcessData(Enumerable.Range(3001, 1000).ToList()); - Assert.Equal(3500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - [Fact] - public void ParallelTest5() - { - var localData = ProcessData(Enumerable.Range(4001, 1000).ToList()); - Assert.Equal(4500500, localData.Sum()); - - lock (_lock) - { - _sharedCounter++; - } - } - - private List ProcessData(List input) - { - // Simulate some CPU work - var result = new List(input.Count); - foreach (var item in input) - { - result.Add(item); - } - result.Sort(); - return result; - } -} - -[Collection("Sequential")] -public class SequentialTests -{ - private static int _sequentialCounter = 0; - private static readonly List _executionOrder = new(); - - [Fact] - public void SequentialTest1() - { - _executionOrder.Add(1); - _sequentialCounter++; - - Assert.Equal(_executionOrder.Count, _sequentialCounter); - Thread.Sleep(5); // Simulate work - } - - [Fact] - public void SequentialTest2() - { - _executionOrder.Add(2); - _sequentialCounter++; - - Assert.Equal(_executionOrder.Count, _sequentialCounter); - Thread.Sleep(5); // Simulate work - } - - [Fact] - public void SequentialTest3() - { - _executionOrder.Add(3); - _sequentialCounter++; - - Assert.Equal(_executionOrder.Count, _sequentialCounter); - Thread.Sleep(5); // Simulate work - } -} - -public class ThreadSafeTests -{ - private static readonly ConcurrentDictionary _concurrentData = new(); - private static readonly ConcurrentBag _processedItems = new(); - - [Theory] - [InlineData(1)] - [InlineData(2)] - [InlineData(3)] - [InlineData(4)] - [InlineData(5)] - public void ConcurrentCollectionTest(int id) - { - var key = Thread.CurrentThread.ManagedThreadId * 1000 + id; - _concurrentData[key] = $"Thread_{Thread.CurrentThread.ManagedThreadId}_Item_{id}"; - _processedItems.Add(key); - - Assert.True(_concurrentData.ContainsKey(key)); - Assert.Contains($"Item_{id}", _concurrentData[key]); - - // Simulate some work - var sum = Enumerable.Range(1, 100).Select(x => x * id).Sum(); - Assert.Equal(5050 * id, sum); - } - - [Fact] - public async Task ParallelAsyncTest() - { - var tasks = Enumerable.Range(1, 5).Select(async i => - { - await Task.Yield(); - var result = await ProcessAsync(i); - return result; - }); - - var results = await Task.WhenAll(tasks); - - Assert.Equal(55, results.Sum()); - Assert.Equal(5, results.Length); - Assert.All(results, r => Assert.True(r > 0)); - } - - private async Task ProcessAsync(int value) - { - await Task.Delay(1); - return value * value; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/RepeatTests.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/RepeatTests.cs deleted file mode 100644 index 6ba35b88cb..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/RepeatTests.cs +++ /dev/null @@ -1,78 +0,0 @@ -namespace xUnitTimer; - -public class RepeatTests -{ - private static int _counter = 0; - - public static IEnumerable RepeatData100() - { - return Enumerable.Range(0, 100).Select(i => new object[] { i }); - } - - public static IEnumerable RepeatData50() - { - return Enumerable.Range(0, 50).Select(i => new object[] { i }); - } - - public static IEnumerable RepeatData25() - { - return Enumerable.Range(0, 25).Select(i => new object[] { i }); - } - - [Theory] - [MemberData(nameof(RepeatData100))] - public void RepeatedCalculationTest(int iteration) - { - var localCounter = Interlocked.Increment(ref _counter); - var result = PerformCalculation(localCounter); - - Assert.True(result > 0); - Assert.Equal(localCounter * (localCounter + 1) / 2, result); - } - - [Theory] - [MemberData(nameof(RepeatData50))] - public async Task RepeatedAsyncTest(int iteration) - { - var taskId = Guid.NewGuid(); - var result = await ProcessDataAsync(taskId); - - Assert.NotNull(result); - Assert.Equal(36, result.Length); // GUID length - Assert.Equal(taskId.ToString(), result); - } - - [Theory] - [MemberData(nameof(RepeatData25))] - public void RepeatedStringOperationTest(int iteration) - { - var localIteration = Interlocked.Increment(ref _counter); - var text = $"Iteration_{localIteration}"; - var processed = ProcessString(text); - - Assert.Contains("PROCESSED", processed); - Assert.Contains(localIteration.ToString(), processed); - Assert.True(processed.Length > text.Length); - } - - private int PerformCalculation(int input) - { - var result = 0; - for (var i = 1; i <= input; i++) - { - result += i; - } - return result; - } - - private async Task ProcessDataAsync(Guid id) - { - await Task.Yield(); - return id.ToString(); - } - - private string ProcessString(string input) - { - return $"PROCESSED_{input.ToUpper()}_{input.Length}"; - } -} \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/SetupTeardownTests.cs b/tools/speed-comparison/xUnitTimer/xUnitTimer/SetupTeardownTests.cs deleted file mode 100644 index 46df22f550..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/SetupTeardownTests.cs +++ /dev/null @@ -1,160 +0,0 @@ -namespace xUnitTimer; - -public class SetupTeardownTests : IDisposable -{ - private readonly List _testData; - private readonly Dictionary _cache; - private int _setupCounter; - - public SetupTeardownTests() - { - // Constructor acts as setup - _testData = new List(); - _cache = new Dictionary(); - _setupCounter = 0; - - // Setup test data - BeforeEachTest(); - } - - private void BeforeEachTest() - { - _setupCounter++; - _testData.Clear(); - _testData.AddRange(new[] { "Apple", "Banana", "Cherry", "Date", "Elderberry" }); - - _cache.Clear(); - for (var i = 0; i < 10; i++) - { - _cache[i] = $"Value_{i}"; - } - } - - private void AfterEachTest() - { - _testData.Clear(); - _cache.Clear(); - } - - [Fact] - public void TestWithSetupData() - { - Assert.Equal(5, _testData.Count); - Assert.Equal("Apple", _testData[0]); - Assert.Equal(10, _cache.Count); - Assert.Equal("Value_5", _cache[5]); - - _testData.Add("Fig"); - Assert.Equal(6, _testData.Count); - - AfterEachTest(); - } - - [Fact] - public void TestDataIsolation() - { - BeforeEachTest(); // Reset for this test - - Assert.Equal(5, _testData.Count); - Assert.Equal(10, _cache.Count); - - _testData.RemoveAt(0); - _cache.Remove(0); - - Assert.Equal(4, _testData.Count); - Assert.Equal(9, _cache.Count); - - AfterEachTest(); - } - - [Fact] - public void TestWithDataManipulation() - { - BeforeEachTest(); // Reset for this test - - var sorted = _testData.OrderBy(x => x).ToList(); - var reversed = _testData.AsEnumerable().Reverse().ToList(); - - Assert.Equal("Apple", sorted[0]); - Assert.Equal("Elderberry", sorted[4]); - Assert.Equal("Elderberry", reversed[0]); - Assert.Equal("Apple", reversed[4]); - - AfterEachTest(); - } - - public void Dispose() - { - _testData?.Clear(); - _cache?.Clear(); - } -} - -public class ClassFixtureTests : IClassFixture -{ - private readonly SharedTestFixture _fixture; - private readonly string _instanceId = Guid.NewGuid().ToString(); - - public ClassFixtureTests(SharedTestFixture fixture) - { - _fixture = fixture; - } - - [Fact] - public void TestUsingClassData1() - { - Assert.True(_fixture.IsInitialized); - Assert.Equal(100, _fixture.SharedData.Count); - Assert.Equal(5050, _fixture.SharedData.Sum()); - } - - [Fact] - public void TestUsingClassData2() - { - Assert.True(_fixture.IsInitialized); - var evens = _fixture.SharedData.Where(x => x % 2 == 0).ToList(); - Assert.Equal(50, evens.Count); - Assert.Equal(2550, evens.Sum()); - } - - [Fact] - public void TestUsingClassData3() - { - Assert.True(_fixture.IsInitialized); - var primes = _fixture.SharedData.Where(IsPrime).ToList(); - Assert.Equal(25, primes.Count); - Assert.Equal(2, primes.First()); - } - - private static bool IsPrime(int n) - { - if (n <= 1) return false; - if (n <= 3) return true; - if (n % 2 == 0 || n % 3 == 0) return false; - - for (var i = 5; i * i <= n; i += 6) - { - if (n % i == 0 || n % (i + 2) == 0) - return false; - } - return true; - } -} - -public class SharedTestFixture : IDisposable -{ - public List SharedData { get; } - public bool IsInitialized { get; private set; } - - public SharedTestFixture() - { - IsInitialized = true; - SharedData = Enumerable.Range(1, 100).ToList(); - } - - public void Dispose() - { - IsInitialized = false; - SharedData.Clear(); - } -} \ No newline at end of file diff --git a/tools/speed-comparison/xUnitTimer/xUnitTimer/xUnitTimer.csproj b/tools/speed-comparison/xUnitTimer/xUnitTimer/xUnitTimer.csproj deleted file mode 100644 index 1dbcbe3f1a..0000000000 --- a/tools/speed-comparison/xUnitTimer/xUnitTimer/xUnitTimer.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - net8.0;net9.0 - enable - enable - false - true - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - \ No newline at end of file