Hi everyone I have a problem with generate test cases for TestCaseSource. I wrote this code for tests:
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
namespace HeapSort.Tests
{
[TestFixture]
public class Tests
{
[Test, TestCaseSource(typeof(TestsGenerator),"TestCases")]
public void IsEqualCollections(int[] received, int[] expected)
{
CollectionAssert.AreEqual(received, expected);
}
}
public class TestsGenerator
{
public static IEnumerable<TestCaseData> TestCases
{
get
{
for (var i = 0; i < 25; i++)
{
int[] t1 = GenerateCollection(i), t2 = t1.ToArray();
HeapSort.Sort(t1);
Array.Sort(t2);
yield return new TestCaseData(t1, t2);
}
}
}
private static int[] GenerateCollection(int seed)
{
var rnd = new Random(seed+DateTime.Now.Millisecond);
int size = rnd.Next(100, 10000);
int[] array = new int[size];
for (var i = 0; i < size; i++)
array[i] = rnd.Next(-100, 100);
return array;
// return Enumerable
// .Repeat(100, rnd.Next(100, 10000))
// .Select(i => rnd.Next(-100, 100))
// .ToArray();
}
}
}
Is there a problem? Instead of getting 25 tests I get from 1 to 8, and often at the initial point of testing it shows that the tests are 7/8, and at the end there is only one test case.
How i can solver it?
P.S. Sorry for my bad English.
Perhaps it is worth mentioning that I work on Ubuntu in Rider
Aucun commentaire:
Enregistrer un commentaire