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

Anzhelika Gudkova #61

Open
wants to merge 3 commits into
base: Anzhelika_Gudkova
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
58 changes: 58 additions & 0 deletions CourseApp.Tests/DogTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using Xunit;

namespace CourseApp.Tests
{
public class DogTest
{
[Fact]
public void TestEmptyConstructor()
{
var dog = new Dog();
Assert.Equal(0, dog.Age);
Assert.Equal("Untitled", dog.Name);
Assert.True(dog.IsMale);
}

[Fact]
public void TestConstructor()
{
var item = new Dog(12, "Nancy", false);
Assert.Equal(12, item.Age);
Assert.Equal("Nancy", item.Name);
Assert.False(item.IsMale);
}

[Fact]
public void TestBarking()
{
var item = new Dog();
Assert.Equal("gav-gav", item.Barking());
}

[Fact]
public void TestSetAge()
{
var item = new Dog();
item.Age = 7;
Assert.Equal(7, item.Age);
}

[Fact]
public void TestIncorrectSetAge()
{
var item = new Dog();
item.Age = 22;
Assert.Equal(0, item.Age);
}

[Fact]
public void TestCorrectIncorrectSetAge()
{
var item = new Dog();
item.Age = 8;
item.Age = -15;
Assert.Equal(8, item.Age);
}
}
}
50 changes: 50 additions & 0 deletions CourseApp/Dog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;

namespace CourseApp
{
public class Dog
{
private int age;

public Dog()
: this(0, "Untitled", true)
{
}

public Dog(int age, string name, bool isMale)
{
Name = name;
Age = age;
IsMale = isMale;
}

public string Name { get; set; }

public int Age
{
get
{
return this.age;
}

set
{
if (value >= 0 && value < 15)
{
this.age = value;
}
else
{
Console.WriteLine("Age should be > 0 and < than 15");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Необходимо выбрасывать исключение в этом месте

}
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Добавьте переопределение базового метода toString и возвращайте строковое значение, содержащее например имя и возраст

public bool IsMale { get; set; }

public string Barking()
{
return "gav-gav";
}
}
}