I have one form: FormPrincipal.cs
In this form there is a public method called InsertionSort() taking 2 parameters: a int[] (representing a integer list) and a int represeting the size (number of elements) of the list.
This function simply orders the list using the algorithm “Insertion Sort”
The method doesn’t return anything (because in the logic of my application the list is just ordened and as an array is a point then the original list is just modified to be in the right order).
I’m trying to test if the function order the list.
I created a Unit Test in Visual Studio (not as a separate project) but it always says “failed” without displaying any message. What I’m doing wrong?
The code is like the following:
[TestMethod()]
public void InsertionSortTest()
{
FormPrincipal target = new FormPrincipal(<some parameters>);
target.loadData(); // function which load the list to be ordered
int[] list1 = new int[10];
list1 = {1,4,3,5,2,6,7,9,8,0);
target.InsertionSort(list1,10);
bool listaOrderedOrNot = isListOrdered(list1, 10); // isListOrder is just a function in the same file of the test where I loop the array checking if elements are growing.
Assert.Inconclusive("A method that does not return a value cannot be verified.");
// I tried to do the following assert command..
Assert.AreEqual(listaOrderedOrNot, true,"ordered");
Assert.IsTrue(listaOrderedOrNot, "ordered");
Assert.IsFalse(listaOrdenadaOrNot, "NOT ordered");
}
I suppose it may depends from the fact InsertionSort() doesn’t return anything but Visual Studio doesn’t give errors and no message (for example “ordered” or “NOT ordered”) is printed.
The test just fails when I run it
Thank you for any help
Remove
Assert.Inconclusive("A method that does not return a value cannot be verified.");.This basically tells VS that you didn’t implement your test.
When you have an array you can simply use
array.Lengthto get the size of the array, there is no need to pass the size.Your sort algorithm doesn’t belong into the form class.