diff --git a/CourseApp.Tests/PersonAgeCalculatorTests.cs b/CourseApp.Tests/PersonAgeCalculatorTests.cs new file mode 100644 index 00000000..cb414d34 --- /dev/null +++ b/CourseApp.Tests/PersonAgeCalculatorTests.cs @@ -0,0 +1,21 @@ +namespace CourseApp.Tests +{ + using System; + using Xunit; + + public class PersonAgeCalculatorTests + { + [Theory] + [InlineData(new[] { 2003, 5, 20 }, new[] { 2021, 5, 20 }, "You are 18th years.")] + [InlineData(new[] { 2003, 5, 20 }, new[] { 2021, 11, 10 }, "You are 18 years, 5 months and 23 days")] + [InlineData(new[] { 2003, 5, 20 }, new[] { 2022, 5, 3 }, "You are 18 years, 11 months and 14 days")] + public void CalculatingAPersonsAge(int[] born, int[] end, string exp) + { + var mike = new PersonAgeCalculator(); + + var res = mike.CalculatingAge(new DateTime(born[0], born[1], born[2]), new DateTime(end[0], end[1], end[2])); + + Assert.Equal(exp, res); + } + } +} \ No newline at end of file diff --git a/CourseApp/PersonAgeCalculator.cs b/CourseApp/PersonAgeCalculator.cs new file mode 100644 index 00000000..51535099 --- /dev/null +++ b/CourseApp/PersonAgeCalculator.cs @@ -0,0 +1,36 @@ +namespace CourseApp +{ + using System; + + public class PersonAgeCalculator + { + public string CalculatingAge(DateTime born) + { + return CalculatingAge(born, DateTime.Today); + } + + public string CalculatingAge(DateTime born, DateTime end) + { + DateTime date = DateTime.MinValue.AddTicks(end.Ticks - born.Ticks); + if ((date.Day - 2) == 0 && (date.Month - 1) == 0) + { + return "You are " + (date.Year - 1) + "th" + " years."; + } + else + { + return "You are " + (date.Year - 1) + " years, " + (date.Month - 1) + " months and " + (date.Day - 2) + " days"; + } + } + + public void CakeIsALie() + { + Console.WriteLine( + "┈┈┈☆☆☆☆☆☆☆┈┈┈" + + "┈┈╭┻┻┻┻┻┻┻┻┻╮┈┈" + + "┈┈┃╱╲╱╲╱╲╱╲╱┃┈┈" + + "┈╭┻━━━━━━━━━┻╮┈" + + "┈┃╱╲╱╲╱╲╱╲╱╲╱┃┈" + + "┈┗━━━━━━━━━━━┛┈"); + } + } +}