How to resolve the algorithm Test a function step by step in the C# programming language
How to resolve the algorithm Test a function step by step in the C# programming language
Table of Contents
Problem Statement
Using a well-known testing-specific library/module/suite for your language, write some tests for your language's entry in Palindrome. If your language does not have a testing specific library well known to the language's community then state this or omit the language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Test a function step by step in the C# programming language
The provided C# code is a set of unit tests for a program that detects if a string is a palindrome.
-
The first set of tests uses Microsoft's
VisualStudio.TestTools.UnitTesting
framework while the second set uses theNUnit
framework. -
Both sets of tests have two test methods:
PalindromeDetectorCanUnderstandPalindrome
tests that the program correctly identifies palindromes (a string that reads the same forwards and backwards).PalindromeDetectorUnderstandsNonPalindrome
tests that the program correctly identifies non-palindromes.
-
In the
PalindromeDetectorCanUnderstandPalindrome
method, it defines as expected a boolean valuetrue
and then compares it with the actual result of theIsPalindrome
andIsPalindromeNonRecursive
functions. -
In the
PalindromeDetectorUnderstandNonPalindrome
method, it defines as expected a boolean valuetrue
and then compares it with the actual result of theIsPalindrome
andIsPalindromeNonRecursive
functions.
Source code in the csharp programming language
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PalindromeDetector.ConsoleApp;
namespace PalindromeDetector.VisualStudioTests
{
[TestClass]
public class VSTests
{
[TestMethod]
public void PalindromeDetectorCanUnderstandPalindrome()
{
//Microsoft.VisualStudio.QualityTools.UnitTestFramework v4.0.30319
bool expected = true;
bool actual;
actual = Program.IsPalindrome("1");
Assert.AreEqual(expected, actual);
actual = Program.IsPalindromeNonRecursive("1");
Assert.AreEqual(expected, actual);
actual = Program.IsPalindrome("ingirumimusnocteetconsumimurigni");
Assert.AreEqual(expected, actual);
actual = Program.IsPalindromeNonRecursive("ingirumimusnocteetconsumimurigni");
Assert.AreEqual(expected, actual);
}
[TestMethod]
public void PalindromeDetecotryCanUnderstandNonPalindrome()
{
bool notExpected = true;
bool actual = Program.IsPalindrome("ThisIsNotAPalindrome");
Assert.AreNotEqual(notExpected, actual);
actual = Program.IsPalindromeNonRecursive("ThisIsNotAPalindrome");
Assert.AreNotEqual(notExpected, actual);
}
}
}
using NUnit.Framework;
using PalindromeDetector.ConsoleApp;
namespace PalindromeDetector.VisualStudioTests
{
[TestFixture]
public class NunitTests
{
[Test]
public void PalindromeDetectorCanUnderstandPalindrome()
{
//nunit.framework v2.0.50727
bool expected = true;
bool actual;
actual = Program.IsPalindrome("1");
Assert.AreEqual(expected, actual);
actual = Program.IsPalindromeNonRecursive("1");
Assert.AreEqual(expected, actual);
actual = Program.IsPalindrome("ingirumimusnocteetconsumimurigni");
Assert.AreEqual(expected, actual);
actual = Program.IsPalindromeNonRecursive("ingirumimusnocteetconsumimurigni");
Assert.AreEqual(expected, actual);
}
[Test]
public void PalindromeDetectorUnderstandsNonPalindrome()
{
bool notExpected = true;
bool actual;
actual = Program.IsPalindrome("NotAPalindrome");
Assert.AreEqual(notExpected, actual);
actual = Program.IsPalindromeNonRecursive("NotAPalindrome");
Assert.AreEqual(notExpected, actual);
}
}
}
You may also check:How to resolve the algorithm Day of the week step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Null object step by step in the Dyalect programming language
You may also check:How to resolve the algorithm Queue/Definition step by step in the Oz programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the Lingo programming language
You may also check:How to resolve the algorithm Exceptions/Catch an exception thrown in a nested call step by step in the BBC BASIC programming language