Skip to content

Anna Kubova (Вычисление возраста человека) #74

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

Open
wants to merge 8 commits into
base: Anna_Kubova
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
42 changes: 42 additions & 0 deletions CourseApp.Tests/BirthdayTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace CourseApp.Tests
{
public class BirthdayTest
{
[Fact]
public void TestBirthdayEqualsCurrentDate()
{
var ecString = "Years 0, month 0, days 0";
Birthday birthday = new Birthday(DateTime.Now);
Assert.Equal(ecString, birthday.ToString());
}

[Fact]
public void TestBirthdayBeforeCurrentDate()
{
var ecString = "Years 18, month 219, days 6690";
Birthday birthday = new Birthday(new DateTime(2001, 9, 12));
Assert.Equal(ecString, birthday.ToString());
}

[Fact]
public void TestBirthdayAfterCurrentDate()
{
var ecString = "Years 0, month 0, days 0";
Birthday birthday = new Birthday(new DateTime(3002, 9, 12));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Это вообще бы должно развалиться

Assert.Equal(ecString, birthday.ToString());
}

[Fact]
public void TestFullYearsAndMonth()
{
var ecString = "Years 18, month 3, days 6";
Birthday birthday = new Birthday(new DateTime(2001, 9, 12));
Assert.Equal(ecString, birthday.CalculateFullCountYearsAndMonth());
}
}
}
3 changes: 0 additions & 3 deletions CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CourseApp\CourseApp.csproj" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../_stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
85 changes: 58 additions & 27 deletions CourseApp.Tests/PlatypusTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,81 @@ namespace CourseApp.Tests
public class PlatypusTest
{
[Fact]
public void TestEmptyConstructor()
public void TestCreateTable()
{
var item = new Platypus();
Assert.Equal(0, item.Age);
Assert.Equal("Untitled", item.Name);
Assert.True(item.IsMale);
var item = new Table(12, 13, "white");
Assert.Equal(12, item.Weight);
Assert.Equal(13, item.Height);
Assert.Equal("white", item.Color);
}

[Fact]
public void TestView()
public void TestCreateTableWithoutColor()
{
var item = new Platypus();
var view = @"
_.-^~~^^^`~-,_,,~''''''```~,''``~'``~,
______,' -o :. _ . ; ,'`, `.
( -\.._,.;;'._ ,( } _`_-_,, `, `,
``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~'
";
Assert.Equal(view, item.View());
var item = new Table(12, 13);
Assert.Equal(12, item.Weight);
Assert.Equal(13, item.Height);
Assert.Equal("black", item.Color);
}

[Fact]
public void TestSetAge()
public void TestGetToString()
{
var item = new Platypus();
item.Age = 5;
Assert.Equal(5, item.Age);
var ecString = "Table: Weigh = 400, Height = 400, Color = red, Count legs = 4";
var item = new Table(400, 400, "red");
Assert.Equal(ecString, item.ToString());
}

[Fact]
public void TestIncorrectSetAge()
public void TestCreateTableWithWrongWeigth()
{
var item = new Platypus();
item.Age = -5;
Assert.Equal(0, item.Age);
try
{
var item = new Table(0, 12, "red");
}
catch (Exception exc)
{
Assert.Equal("Value does not fall within the expected range.", exc.Message);
}
}

[Fact]
public void TestCorrectIncorrectSetAge()
public void TestCreateTableWithWrongHeigth()
{
var item = new Platypus();
item.Age = 10;
item.Age = -5;
Assert.Equal(10, item.Age);
try
{
var item = new Table(12, 0, "red");
}
catch (Exception exc)
{
Assert.Equal("Value does not fall within the expected range.", exc.Message);
}
}

[Fact]
public void TestCreateTableWithWrongColorNull()
{
try
{
var item = new Table(12, 12, null);
}
catch (Exception exc)
{
Assert.Equal("Value does not fall within the expected range.", exc.Message);
}
}

[Fact]
public void TestCreateTableWithWrongColorEmpty()
{
try
{
var item = new Table(12, 12, string.Empty);
}
catch (Exception exc)
{
Assert.Equal("Value does not fall within the expected range.", exc.Message);
}
}
}
}
56 changes: 56 additions & 0 deletions CourseApp/Birthday.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;

namespace CourseApp
{
public class Birthday
{
private DateTime birthday;

public Birthday(DateTime birthday)
{
this.birthday = birthday;
}

public int CalculateCountYear()
{
int years = DateTime.Now.Year - birthday.Year;
if (DateTime.Now.Month < birthday.Month)
{
years--;
}
years = years < 0 ? 0 : years;
return years;
}

public int CalculateCountMonth()
{
if (birthday > DateTime.Now || (birthday.Year == DateTime.Now.Year && birthday.Month == DateTime.Now.Month && birthday.Day == DateTime.Now.Day))
{
return 0;
}
int monthes = (DateTime.Now.Year - birthday.Year - 1) * 12;
monthes += 12 - birthday.Month - 1;
monthes += DateTime.Now.Month;
return monthes;
}

public int CalculateCountDays()
{
int days = DateTime.Now.Subtract(birthday).Days;
return days > 0 ? days : 0;
}

public string CalculateFullCountYearsAndMonth()
{
var currentYear = CalculateCountYear();
var currentMonth = CalculateCountMonth() - CalculateCountYear() * 12;
var currentDays = DateTime.Now.Day;
return "Years " + currentYear + ", month " + currentMonth + ", days " + currentDays;
}

public override string ToString()
{
return "Years " + CalculateCountYear() + ", month " + CalculateCountMonth() + ", days " + CalculateCountDays();
}
}
}
23 changes: 23 additions & 0 deletions CourseApp/Chair.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace CourseApp
{
public class Chair : Furniture
{
public Chair(double weight, double height, string color = "white", int countLegs = 4): base(weight, height, color)
{
CountLegs = countLegs;
}

public double CountLegs { get; private set; }

public override void Build() {
Console.WriteLine("Build chair.");
}

public override string ToString()
{
return "Chair: Weigh = " + Weight + ", Height = " + Height + ", Color = " + Color + ", Count legs = " + CountLegs;
}
}
}
3 changes: 0 additions & 3 deletions CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../_stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
26 changes: 26 additions & 0 deletions CourseApp/Furniture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace CourseApp
{
public abstract class Furniture
{
public Furniture(double weight, double height, string color)
{
if (weight == 0 || height == 0 || string.IsNullOrEmpty(color))
{
throw new ArgumentException();
}
Weight = weight;
Height = height;
Color = color;
}

public double Weight { get; private set; }

public double Height { get; private set; }

public string Color { get; private set; }

public abstract void Build();
}
}
60 changes: 0 additions & 60 deletions CourseApp/Platypus.cs

This file was deleted.

Loading