Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kirill_Shestakov/Person_Age_Calcularot_with_tests #57

Open
wants to merge 1 commit into
base: Kirill_Shestakov
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions CourseApp.Tests/PersonAgeCalculatorTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
36 changes: 36 additions & 0 deletions CourseApp/PersonAgeCalculator.cs
Original file line number Diff line number Diff line change
@@ -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(
"┈┈┈☆☆☆☆☆☆☆┈┈┈" +
"┈┈╭┻┻┻┻┻┻┻┻┻╮┈┈" +
"┈┈┃╱╲╱╲╱╲╱╲╱┃┈┈" +
"┈╭┻━━━━━━━━━┻╮┈" +
"┈┃╱╲╱╲╱╲╱╲╱╲╱┃┈" +
"┈┗━━━━━━━━━━━┛┈");
}
Comment on lines +25 to +34
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I use this in tests?

}
}