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...
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.
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...
I have a few questions from a lab experiment that my class has done for Acid-Base...
I have a few questions from a lab experiment that my class has done for Acid-Base Titrations. Objective: To use titration to determine in Part 1, the concentration (molarity) of an unknown acid solution and in Part 2, the purity of a sample of KHP acid. Background: Titration is a volumetric technique used to determine the concentrations of solutions, molar masses of solids, and purity of samples. A titration inolves the addition of a titrant (a solution of known concentration)...
write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
Why are my questions not answered? I am waiting and waiting and desperately need it done....
Why are my questions not answered? I am waiting and waiting and desperately need it done. Here: A new business client comes to your office. There are three owners of the business. The three individuals, Alan, Bob, and Carol, are thinking about forming a partnership. Alan is only investing $1 million in cash. He will not have anything to do with the daily activities of the business. Bob has had some experience in the business and will be responsible for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT