Question

In: Computer Science

Please write unit tests for the main method below. The unit tests must be used in...

Please write unit tests for the main method below. The unit tests must be used in MSTest for Visual Studio.

C#

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

//sortData method called for sorting the above unsorted array
sortData(dataSet);

//iterating the sorted array
for (int i = 0; i < dataSet.Length; i++)
{
//writing the sorted array to the console
Console.WriteLine(dataSet[i]);
}
}//end method

Solutions

Expert Solution

Done accordingly. Comment for further help.Please uprate.

Go to solution explorer of your project-->new-->project--> mstest project-->add reference of main project to this new project copy code and continue

Code:

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.IO;

namespace Tester
{
[TestClass]
public class UnitTest1
{
  
[TestMethod]
public void TestMethod1()
{
int[] dataSet = new int[5] { 2, 3, 27, 68, 99 };
String expected = "";
for (int i = 0; i < 5; i++)
{
expected = expected + dataSet[i] + "\r\n";
}
using (var sw =new StringWriter())
{
Console.SetOut(sw);
String[] x=new String[4];
TestingCode.Program.Main(x);
var result = sw.ToString().Trim();
expected= expected.ToString().Trim();
Assert.AreEqual(expected, result);
}
}
}
}


Related Solutions

Question - Write a Client class with a main method that tests the data structures as...
Question - Write a Client class with a main method that tests the data structures as follows: For the ArrayStack, LinkedStack, ArrayQueue, LinkedQueue, and ArrayList: Perform a timing test for each of these data structures. Each timing test should measure in nanoseconds how long it takes to add and remove N Integers from the structure. N should vary from 10 to 1,000,000,000 increasing N by a factor of 10 for each test. Depending on your system you may run out...
ou must write tests for the following: You must write tests for the following (which may...
ou must write tests for the following: You must write tests for the following (which may include Custom Exceptions): BankAccount Class Tests are written such that any deposit that is made greater than 10000 is not accepted. Tests are written such that balance in the BankAccount does not go below 0. Care should be taken for above tests at the time of Initial Deposit and at the time of Withdrawal and future Deposits. Tests should be written such that the...
Write a class called CheckUserName. CheckUserName must have a main method. Your program must ask for...
Write a class called CheckUserName. CheckUserName must have a main method. Your program must ask for a user name. If the name is on the list below (Liam, for example) greet the user saying: welcome back: Liam If the user is an admin (like Benkamin, for example) print: welcome back: Benjamin you have admin privileges Your program must accept upper case or lower case: emacs% java CheckUserName enter a user name: Liam welcome back: Liam emacs% java CheckUserName enter a...
Write a class called WhereIsMyNumber. WhereIsMyNumber must have a main method. Your program must ask for...
Write a class called WhereIsMyNumber. WhereIsMyNumber must have a main method. Your program must ask for a number (it must work if user enters numbers with decimal point of not). Then your program must print number is negative -- if humber is negative number in [0,10) -- if it is between 0 and 10, not including the 10 number in [10,100) -- if it is between 10 and 100, not including the 100 number in [100,1000) -- if it is...
Write a class called CheckUserName. CheckUserName must have a main method. Your program must ask for...
Write a class called CheckUserName. CheckUserName must have a main method. Your program must ask for a user name. If the name is on the list below (Liam, for example) greet the user saying: welcome back: Liam If the user is an admin (like Benkamin, for example) print: welcome back: Benjamin you have admin privileges Your program must accept upper case or lower case: emacs% java CheckUserName enter a user name: Liam welcome back: Liam emacs% java CheckUserName enter a...
Please write a main method that creates 2 pizzas and uses the toString() method to test...
Please write a main method that creates 2 pizzas and uses the toString() method to test this program. public class PizzaOrder { private Pizza[] order; private int numPizzas; public PizzaOrder() { order = new Pizza[1]; order[0] = new Pizza("Cheese", 0); numPizzas = 1; } public PizzaOrder(int count) { order = new Pizza[count]; this.numPizzas = 0; } public void addPizza(Pizza pizza) { for (int i = 0; i < order.length; i++) { if (order[i] == null) { order[i] = pizza; System.out.println("Pizza...
c# Please write unit tests for this code, at least one or two that I can...
c# Please write unit tests for this code, at least one or two that I can understand how to write it. using System; namespace PrimeNumberFactors { class Program { static void Main(string[] args) { Console.Write("Enter a number you want to check: ");    if (int.TryParse(Console.ReadLine(), out int num)) { PrimeFactors(num); } else { Console.WriteLine("Invalid input!!"); } Console.ReadKey(); } public static void PrimeFactors(int num) { Console.Write($"Prime Factors of {num} are: ");    while (num % 2 == 0) { Console.Write("2 ");...
Please write in Java and have two methods: the main method and the reverse word Write...
Please write in Java and have two methods: the main method and the reverse word Write a method that reads a line and reverses the words in the line (not the characters) using a stack. For example, given the following input: The quick brown fox jumps over the lazy dog you should get the following output: dog lazy the over jumps fox brown quick The Then create a main method to prompt the user to enter a line of words...
You must write tests for the following: all tests must be written in JUnit 5. Customer...
You must write tests for the following: all tests must be written in JUnit 5. Customer Class Checking that the customer number autoincrements with each new customer object created Order Class Checking that the order number autoincrements with each new order object created Adding a product that is already in the order Removing a product that is in the order - quantity less than the quantity in the order Removing a product that is in the order - quantity that...
Write a program that contains a main method and another method named userName. The main method...
Write a program that contains a main method and another method named userName. The main method should prompt the user to enter a full name. The userName method takes the full name as an argument and prints the name in reverse order and returns the number of characters in the name. See Sample Output (input shown in blue). Sample Output Please enter your FULL name Billy Joe McCallister Here is the name Billy Joe McCallister in reverse: retsillaCcM eoJ ylliB...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT