using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
public ValidationResult Validate(string[] args)
if (args.Length == 0) return ValidationResult.Invalid;
if (args[0] == "--help" && args.Length == 1) return ValidationResult.HelpRequested;
if (args.Length % 2 != 0) return ValidationResult.Invalid;
bool nameChecked = false;
bool surnameChecked = false;
for (int i=0;i<args.Length;i+=2)
string command = args[i];
if(nameChecked) return ValidationResult.Invalid;
Regex nameRegex = new Regex("^[A-Z][a-z]+$");
if (!nameRegex.IsMatch(userInput)) return ValidationResult.Invalid;
else if(command == "--surname")
if(surnameChecked) return ValidationResult.Invalid;
Regex surnameRegex = new Regex("^[A-Z][a-z]*(('|-)[A-Z])?[a-z]*$");
if (userInput.Length == 1 || !surnameRegex.IsMatch(userInput)) return ValidationResult.Invalid;
else if(command == "--age")
if(ageChecked) return ValidationResult.Invalid;
bool ageCheck = Int32.TryParse(userInput, out parsedNumber);
if (parsedNumber < 1 || parsedNumber > 150) return ValidationResult.Invalid;
return ValidationResult.Invalid;
return ValidationResult.Invalid;
return ValidationResult.Valid;
static void Main(string[] args)
var sw = new Stopwatch();
var tests = new UnitTests();
tests.Test(new string[] { "--name", "Mike" }, ValidationResult.Valid);
tests.Test(new string[] { "--name", "Mikelangelloverrylongnammeo" }, ValidationResult.Valid);
tests.Test(new string[] { "--name", "mike" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "M1ke" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike " }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "M" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", " Mike" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "-Mike" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike_" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mik$e" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike Mike" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "MikeWazowski" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "Wazowski" }, ValidationResult.Valid);
tests.Test(new string[] { "--surname", "O'Sullivan" }, ValidationResult.Valid);
tests.Test(new string[] { "--surname", "Mike-Wazowski" }, ValidationResult.Valid);
tests.Test(new string[] { "--surname", "Oh'Sullivan" }, ValidationResult.Valid);
tests.Test(new string[] { "--surname", "Sullivan'O" }, ValidationResult.Valid);
tests.Test(new string[] { "--surname", "Wazow$ki" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "O'Sullivan-Wazowski" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "Sullivan-O'Wazowski" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "O' Sullivan" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "O'Hara'Sullivan" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "O'sullivan" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "'Sullivan" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "-Sullivan" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "Sullivan'" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "Sullivan-" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "Mike - Wazowski" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "Mike-Wazowski-Sullivan" }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "wazowski " }, ValidationResult.Invalid);
tests.Test(new string[] { "--surname", "wazowski" }, ValidationResult.Invalid);
tests.Test(new string[] { "--age", "29" }, ValidationResult.Valid);
tests.Test(new string[] { "--age", "1" }, ValidationResult.Valid);
tests.Test(new string[] { "--age", "150" }, ValidationResult.Valid);
tests.Test(new string[] { "--age", "0" }, ValidationResult.Invalid);
tests.Test(new string[] { "--age", "8.5" }, ValidationResult.Invalid);
tests.Test(new string[] { "--age", "0.99" }, ValidationResult.Invalid);
tests.Test(new string[] { "--age", "8,5" }, ValidationResult.Invalid);
tests.Test(new string[] { "--age", "-29" }, ValidationResult.Invalid);
tests.Test(new string[] { "--age", "Mike" }, ValidationResult.Invalid);
tests.Test(new string[] { "--help" }, ValidationResult.HelpRequested);
tests.Test(new string[] { "--help", "me please" }, ValidationResult.Invalid);
tests.Test(new string[] { "--help", "--name", "Mike" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike", "--help" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike", "--surname", "Wazowski" }, ValidationResult.Valid);
tests.Test(new string[] { "--name", "Mike", "--surname", "Wazowski", "--age", "149" }, ValidationResult.Valid);
tests.Test(new string[] { "--surname", "Wazowski", "--age", "149", "--name", "Mike" }, ValidationResult.Valid);
tests.Test(new string[] { }, ValidationResult.Invalid);
tests.Test(new string[] { "name", "Mike" }, ValidationResult.Invalid);
tests.Test(new string[] { "--mane", "Mike" }, ValidationResult.Invalid);
tests.Test(new string[] { "Mike", "--name" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike", "--surname" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "mike", "--surname", "Wazowski" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike", "--surname", "wazowski" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike", "--surname", "Wazowski", "--age" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "Mike", "--surname", "wazowski", "--age", "149" }, ValidationResult.Invalid);
tests.Test(new string[] { "--name", "--surname" }, ValidationResult.Invalid);
Console.WriteLine($"Elapsed time: {sw.ElapsedMilliseconds}ms");
private List<string> results = new List<string>();
public void Test(string[] args, ValidationResult expectedValidationResult)
var validator = new Validator();
var actualValidationResult = validator.Validate(args);
var result = actualValidationResult == expectedValidationResult ? "pass" : "fail";
Console.WriteLine($"{result} | Expected: {expectedValidationResult} - Actual: {actualValidationResult} | {String.Join(' ', args)}");
public void PostResults()
var passed = results.Count(x => x == "pass");
var percentage = (decimal)passed / (decimal)all;
Console.WriteLine($"Final result: {passed}/{all} {percentage:P1}");