-
Notifications
You must be signed in to change notification settings - Fork 23
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
kubic12
wants to merge
8
commits into
ISUCT:Anna_Kubova
Choose a base branch
from
kubic12:birthday
base: Anna_Kubova
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c20b782
remove code style ref
dethreeka 3fd25f0
add table class and update tests
dethreeka 097ac0c
add abstract class and chair class
dethreeka 1a99710
updated tests
dethreeka 5e7df77
fixed line in test
dethreeka 89df6b4
fixed params in test
dethreeka 1ef11cb
added birthday calculate class
dethreeka a983e55
added new function for calc years and mounth
dethreeka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
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()); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это вообще бы должно развалиться