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

Class task #18

Open
wants to merge 10 commits into
base: Kornilich_Ksenija_Sergeevna
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
47 changes: 47 additions & 0 deletions CourseApp.Tests/PetTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace CourseApp.Tests
Copy link
Contributor

Choose a reason for hiding this comment

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

а точно наш шаблон использовали? что-то не запускаются проверки (надо будет посмотреть)

{
using CourseApp.Entities;
using Xunit;

public class PetTest
Copy link
Contributor

Choose a reason for hiding this comment

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

1 - для каждого класса можно создать свой отдельный файл теста
2 - что-то подсказывает что методов у вас больше и на каждый метод где есть логика надо добавить тесты

{
[Fact]
public void BirdTest()
{
var bird = new Bird("Кеша", "зелёный", 5);
var expectedText = @" зелёный попугай Кеша
\\
\\ (o>
(o> //\
_(()_____V_/_____
|| ||
||";
Assert.Equal(expectedText, bird.GetInfo());
}

[Fact]
public void DogTest()
{
var dog = new Dog("Рэкс", "черный", 6);
var expectedText = @" черный пёс Рэкс
,-.___,-.
\\_/_ _\\_/
)O_O(
{ (_) }
`-^-'
";
Assert.Equal(expectedText, dog.GetInfo());
}

[Fact]
public void CatTest()
{
var cat = new Cat("Гаф", "чёрный", 5);
var expectedText = @" чёрный котёнок Гаф
/\_/\
( o.o )
> ^ <";
Assert.Equal(expectedText, cat.GetInfo());
}
}
}
23 changes: 23 additions & 0 deletions CourseApp/Entities/Bird.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace CourseApp.Entities
{
using System;

public class Bird : Pet
{
public Bird(string nick, string color, int age)
: base(nick, color, age)
{
}

public override string GetInfo()
{
return $" {Color} попугай {Nick}" + @"
\\
\\ (o>
(o> //\
_(()_____V_/_____
|| ||
||";
}
}
}
17 changes: 17 additions & 0 deletions CourseApp/Entities/Cat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace CourseApp.Entities;

public class Cat : Pet
{
public Cat(string nick, string color, int age)
: base(nick, color, age)
{
}

public override string GetInfo()
{
return $" {Color} котёнок {Nick}" + @"
/\_/\
( o.o )
> ^ <";
}
}
20 changes: 20 additions & 0 deletions CourseApp/Entities/Dog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace CourseApp.Entities;

public class Dog : Pet
{
public Dog(string nick, string color, int age)
: base(nick, color, age)
{
}

public override string GetInfo()
{
return $" {Color} пёс {Nick}" + @"
,-.___,-.
\\_/_ _\\_/
)O_O(
{ (_) }
`-^-'
";
}
}
43 changes: 43 additions & 0 deletions CourseApp/Entities/Pet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace CourseApp.Entities
{
using System;

public abstract class Pet
{
private int age; // поле

public Pet(string nick, string color, int age) // конструктор
{
Nick = nick;
Color = color;
Age = age;
}

public string Nick { get; set; } // свойство

public string Color { get; set; } // свойство

public int Age
Copy link
Contributor

Choose a reason for hiding this comment

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

вот на этот метод тест надо бы

{
get
{
return age;
}

set
{
if (value != 1 && value > 0)
{
this.age = value;
}
}
}

public virtual string GetInfo() => "It's a pet"; // крактая запись return, стрелочная функция, в JS пригодится)
/*
* public virtual string GetInfo() {
* return "It's a pet";
* }
*/
Comment on lines +37 to +41
Copy link
Contributor

Choose a reason for hiding this comment

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

закомментированный текст обычно удаляем

}
}
20 changes: 18 additions & 2 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
namespace CourseApp
{
using System;
using System.Collections.Generic;
using CourseApp.Entities; // эту штуку заставил создать семён, я не виновата, спасите

public class Program
{
public static void Main(string[] args)
public static void Main()
{
Console.WriteLine("Hello World");
Pet gaf = new Cat("Гаф", "чёрный", 5);
Pet rex = new Dog("Рэкс", "черный", 6);
Pet kesha = new Bird("Кеша", "зелёный", 2);

var petList = new List<Pet>
{
gaf,
rex,
kesha,
};

foreach (var pet in petList)
{
Console.WriteLine(pet.GetInfo());
}
}
}
}