Question

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.

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


}

  
}
}

Homework Answers

Answer #1
// 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);
    }
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a MIPS assembly program that sorts an array using bubble sort translating the C code...
Write a MIPS assembly program that sorts an array using bubble sort translating the C code int main(void) { int array[] = {10, 2, 7, 5, 15, 30, 8, 6}; // input array int arraySize = sizeof(array)/sizeof(array[0]); bool swapped = true; int j = 0; int tmp; while (swapped) { swapped = false; //Note : "j" , "arraySize - j" are optimizations to the bubble sort algorithm j++; // j= sorted elements int i=0; /* "arraySize - j" is used...
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
Microsoft Visual Studio in C#: I have this code and need to loop through each element...
Microsoft Visual Studio in C#: I have this code and need to loop through each element of the patient's array and add to a listbox (lbAccountDisplay) each property of the patient's object. This is the 2nd time to ask this question; it should have all the detail you need to help me. It is a piece of a project and I am trying not to give you the whole project. How do I use a foreach loop to loop through...
Hello, I feel like I am super close but I can not figure out why my...
Hello, I feel like I am super close but I can not figure out why my C++ code it not displaying the proper medium. Thank you! Here is an example of the output: Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7} Output : Mean = 4.5 Median = 4.5 Code so far:   #include <iostream> using namespace std; int main() { int a[100]; int n,i,sum=0; float mean, medium; //read array size // read array cout<<"Enter array size:...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity  ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity   Code   Description   Project   File   Line   Suppression State Warning   C6385   Reading invalid data from 'DynamicStack': the readable size is '(unsigned int)*28+4' bytes, but '56' bytes may be read.   Here is the C++ code were I'm having the warning. // Sstack.cpp #include "SStack.h" // Constructor SStack::SStack(int cap) : Capacity(cap), used(0) {    DynamicStack = new string[Capacity]; } // Copy Constructor SStack::SStack(const SStack& s) : Capacity(s.Capacity), used(s.used)...
Program C++ (use visual studio) Q1. What default copy constructor does the compiler insert in the...
Program C++ (use visual studio) Q1. What default copy constructor does the compiler insert in the following class? class Student { string name; string id; double grade; }; =========================== Q2 .What is the factor transfer method used when the f() function is called from? void f(int n[]); int main() { int m[3]= {1, 2, 3}; f(m); } ================================== Q3. Write a program that produces a bigger() with a prototype as shown below and outputs a large value by inputting two...
If you cant answer this please dont waste my question. thank you. This cryptographic program run...
If you cant answer this please dont waste my question. thank you. This cryptographic program run and produce text screen output. You are to create a GUI that uses the program. Your program (GUI) must allow a user to input of a message to be coded. It must also have an area to show the plaintext, the ciphertext, and the decrypted text. If required by your choice of cryptographic method, the user should have an area to input a key....
What is wrong with my recursive Binary Search code? For some reason my 'middle' value is...
What is wrong with my recursive Binary Search code? For some reason my 'middle' value is always zero? Please fix and explain! #include <stdio.h> #include <stdlib.h> #include <stdbool.h> int BinarySearch(const int A[],const int L,const int R,const int key) {              if (R >= 1){           int middle = L + (R-1)/2;                              if (A[middle] == key)        return A[middle];               if (A[middle] > key){...
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
I need to get the Min and Max value of an array when a user inputs...
I need to get the Min and Max value of an array when a user inputs values into the array. problem is, my Max value is right but my min value is ALWAYS 0. how do i fix this? any help please!!! _________________________________________________________________________________________________ import java.util.Scanner; public class ArrayMenu{ static int count; static Scanner kb = new Scanner(System.in);             public static void main(){ int item=0; int[] numArray=new int[100]; count=0;       while (item !=8){ menu(); item = kb.nextInt();...