using System;
namespace Solution
{
public class Calculator
{
public int Add(int a, int b)
{
return a + b;
}
}
class Program
{
static void Main(string[] args)
{
var calculator = new Calculator();
if (args.Length >= 2 &&
int.TryParse(args[0], out int a) &&
int.TryParse(args[1], out int b))
{
Console.WriteLine(calculator.Add(a, b));
}
else
{
Console.WriteLine("Please provide two integer arguments.");
}
}
}
}
Test Code (CalculatorTests.cs)
using Xunit;
using Solution;
namespace Solution.Tests
{
public class CalculatorTests
{
private readonly Calculator _calculator = new Calculator();
[Fact]
public void Add_WithPositiveNumbers_ReturnsSum()
{
Assert.Equal(3, _calculator.Add(1, 2));
}
[Fact]
public void Add_WithNegativeNumbers_ReturnsSum()
{
Assert.Equal(-3, _calculator.Add(-1, -2));
}
[Fact]
public void Add_WithStringInput_ThrowsFormatException()
{
// Since the Add method expects integers, handling of strings should be done in the Program.cs
// Here we can test the Calculator directly which doesn't handle strings
// So this test might not be applicable unless input parsing is included in the Calculator
// Alternatively, you can test the Program.Main method with string inputs using a different approach
Assert.True(true); // Placeholder
}
}
}
Launch example
Example query:
Example generation:
csproj
File (Solution.csproj
)Source Code (
Program.cs
)Test Code (
CalculatorTests.cs
)Example Install Dependencies
Example Launch Compilation
Example Launch Test