Question

In: Computer Science

I need a few unit tests done on my SelectionSort program in Visual Studio 2019 with...

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.

so easentially I need someone to write some unit tests with my program in MSTest visual studio 2019. Then I need the unit tests supplied as answers.


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]);
}



}


  
}
}


Solutions

Expert Solution

// SelectionSort.cs
using System;

namespace SelectionSortAlgorithm
{
    public class SelectionSort
    {
        public static void sort(int[] dataSet)
        {
            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 < dataSet.Length - 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 < dataSet.Length; j++)
                {
                    if (dataSet[j] < dataSet[lowestValue])
                    {
                        lowestValue = j;
                    }
                }
                sortedElements = dataSet[lowestValue];
                dataSet[lowestValue] = dataSet[i];
                dataSet[i] = sortedElements;
            }
        }

        public static void Main(string[] args)
        {
            int[] dataSet = new int[5] { 2, 99, 27, 68, 3 }; // 5 element array initialized

            sort(dataSet);

            for (int i = 0; i < dataSet.Length; i++)
            {
                Console.WriteLine(dataSet[i]);
            }
        }
    }
}


// SelectionSortTest.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class SelectionSortTest
{
    [TestMethod]
    public void testSorting()
    {
        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);
    }
}
**************************************************
I Have changed SelectionSort class to a little, because While testing, You should have a method, That automatically does the sorting.. Earlier, Your method was taking the input from console, which is not possible in case of unit testing.

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.


Related Solutions

Hi, I am running C# in Vis. Studio 2019 community. Trying to get my program to...
Hi, I am running C# in Vis. Studio 2019 community. Trying to get my program to populate the username in the program after entered. I can enter a name and the three scores and average them as the program needs but the name is not adding next to the "Students name: " in the program. Any help would be appreciated and please place a note for what I am doing wrong. Thank you using System; using System.Collections.Generic; using System.Linq; using...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...
USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some time and still can't quite figure it out. I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number...
I need the code for following in C++ working for Visual studio please. Thanks Use a...
I need the code for following in C++ working for Visual studio please. Thanks Use a Struct to create a structure for a Player. The Player will have the following data that it needs maintain: Struct Player int health int level string playerName double gameComplete bool isGodMode Create the 2 functions that will do the following: 1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct health= 100 level= 1 playerName = aPlayerName gameComplete = 0...
This is continue from my last post. I will need it to be done in the...
This is continue from my last post. I will need it to be done in the next hour. Please answer in short answer and explain. What value is contained in the integer variable count after the following statements are executed? count = 4; count - count % 4; count = count * 10; count = count + 10; 7. What value is contained in the floating point variable area after the following statements are executed? area = 3.14; area =...
MUST BE DONE IN C++ Use qsort( ) function in Visual Studio to sort the following...
MUST BE DONE IN C++ Use qsort( ) function in Visual Studio to sort the following three arrays: int array1 [] = { 3, 4, 2, 1, 7}; float array2 [] = {0.3, 0.1, 5.5, 4.3, 7.8}; char array3 [] = {‘c’, ‘d’, ‘a’, ‘b’, ‘f’};                                     Develop a driver function to print out the sorted results and put the screenshot into the word document. Note that you have to use qsort( ) provided by Visual Studio. What is the...
My bacteria is staphylococcus epidermidis and these are the tests I need some help with:
# Microbiology  My bacteria is staphylococcus epidermidis and these are the tests I need some help with: PR-mannitol PR-raffinose I need to describe what results I would expect to get if I was completing this test in the lab.
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You...
Make a Program in Visual Studio / Console App (.NET Framework) # language Visual Basic You will be simulating an ATM machine as much as possible Pretend you have an initial deposit of 1000.00. You will Prompt the user with a Main menu: Enter 1 to deposit Enter 2 to Withdraw Enter 3 to Print Balance Enter 4 to quit When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount....
Below is my C++ program of a student record system. I have done the program through...
Below is my C++ program of a student record system. I have done the program through structures. Please do the same program using classes this time and dont use structures. Also, please make the menu function clean and beautiful if you can. So the output will look good at the end. Thanks. #include<iostream> #include<string> using namespace std; struct StudentRecord {    string name;    int roll_no;    string department;    StudentRecord *next; }; StudentRecord *head = NULL; StudentRecord *get_data() {...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class: a)   Declare class Paragraph_Analysis b)   Member Function: SearchWord (to search for a particular word) c)   Member Function: SearchLetter (to search for a particular letter) d)   Member Function: WordCount (to count total words) e)   Member Function: LetterCount (ONLY to count all...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT