0 day streak
csharp / beginner
Snippet

Elementary Result Verification

Simple testing involves comparing actual results against expected outcomes to ensure your code works as intended.

snippet.cs
csharp
1
2
3
4
5
6
7
8
9
public class CalculatorTests {
public void TestAddition() {
int result = 2 + 2;
if (result != 4) {
throw new System.Exception("Test Failed: Expected 4 but got " + result);
}
System.Console.WriteLine("Test Passed!");
}
}
Breakdown
1
if (result != 4)
Checks if the calculated value matches the requirement.
2
throw new System.Exception(...)
Signals a failure if the condition is not met.