I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with MSTest. My program is below. I just need screen shots of the unit test code in Visual Studio 2019 with MSTest. Please and thank you.
using System;
namespace SelectionSortAlgorithm
{
public class SelectionSort
{
public static void Main(string[] args)
{
int[] dataSet = new int[5] { 2, 99, 27, 68, 3 }; // 5 element array
initialized
int n = 5; // variable declar for elements in loop /
initialized
for (int i = 0; i < n; i++) //iterates elements in
dataSet
{
Console.WriteLine(dataSet[i]); // prints unsorted data
}
int sortedElements, lowestValue; //variable declar / used in next
lines of code for sorting elements
// After every iteration, the unsorted array reduces by 1
for (int i = 0; i < n - 1; i++)
{
lowestValue = i; // initialize variable / used for lowest value element
// As array is being sorted, add 1 element to sorted array
for (int j = i + 1; j < n; j++)
{
if (dataSet[j] < dataSet[lowestValue])
{
lowestValue = j;
}
}
sortedElements = dataSet[lowestValue];
dataSet[lowestValue] = dataSet[i];
dataSet[i] = sortedElements;
}
for (int i = 0; i < n; i++)
{
Console.WriteLine(dataSet[i]);
}
}
}
}
// TestSorting.cs using Microsoft.VisualStudio.TestTools.UnitTesting; [TestClass] public class TestSorting { [TestMethod] public void arr() { int[] data = new int[] { 5, 3, 7, 2, 4 }; SelectionSortAlgorithm.SelectionSort.sort(data); CollectionAssert.AreEqual(new int[] { 2, 3, 4, 5, 7 }, data); } [TestMethod] public void testBlankArray() { int[] data = new int[] { }; SelectionSortAlgorithm.SelectionSort.sort(data); CollectionAssert.AreEqual(new int[] { }, data); } [TestMethod] public void testSingleElement() { int[] data = new int[] { 10 }; SelectionSortAlgorithm.SelectionSort.sort(data); CollectionAssert.AreEqual(new int[] { 10 }, data); } [TestMethod] public void testWithNegativeElements() { int[] data = new int[] { -22, 10, -3, -8, 4, 9 }; SelectionSortAlgorithm.SelectionSort.sort(data); CollectionAssert.AreEqual(new int[] { -22, -8, -3, 4, 9, 10 }, data); } }
Get Answers For Free
Most questions answered within 1 hours.