-
Notifications
You must be signed in to change notification settings - Fork 24
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
base: Kornilich_Ksenija_Sergeevna
Are you sure you want to change the base?
Class task #18
Changes from 8 commits
7d24737
6e6e4d9
471649d
b8a500e
6b45f55
fdaacb2
4ee98c3
99b8b39
b5ea18f
8052e31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace CourseApp.Tests | ||
{ | ||
using CourseApp.Entities; | ||
using Xunit; | ||
|
||
public class PetTest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1 - для каждого класса можно создать свой отдельный файл теста |
||
{ | ||
[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()); | ||
} | ||
} | ||
} |
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_/_____ | ||
|| || | ||
||"; | ||
} | ||
} | ||
} |
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 ) | ||
> ^ <"; | ||
} | ||
} |
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( | ||
{ (_) } | ||
`-^-' | ||
"; | ||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. закомментированный текст обычно удаляем |
||
} | ||
} |
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()); | ||
} | ||
} | ||
} | ||
} |
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.
а точно наш шаблон использовали? что-то не запускаются проверки (надо будет посмотреть)