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

Vladislav Savchenko(Добавление интерфейса к заданию на классы) #97

Open
wants to merge 49 commits into
base: Vladislav_Savchenko
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
aeb27bc
Sample of 1st lab
Oct 10, 2019
0247220
Tests samples
Oct 17, 2019
d514055
Added actions file
jskonst Oct 24, 2019
b29aa60
Fixed run steps (#28)
jskonst Oct 24, 2019
dbae387
Test actions on PR (#30)
jskonst Oct 24, 2019
953427e
Added tests and sample A|B tasks
jskonst Oct 24, 2019
62b5d9e
Added class task example, added vscode conf
Nov 7, 2019
aa0b4b1
Merge branch 'master' of https://github.com/ISUCT/Tprogramming_147_2019
Nov 7, 2019
60071cf
lab
DeC0re Nov 14, 2019
178c0e0
lab1.1
DeC0re Nov 14, 2019
967def0
Merge branch 'master' into Vladislav_Savchenko
DeC0re Nov 14, 2019
1faf0dc
lav1.2
DeC0re Nov 14, 2019
a623cd7
lab1.3
DeC0re Nov 14, 2019
9df31ec
lab1.3
DeC0re Nov 14, 2019
d54fe38
Добавил классы+тесты
DeC0re Nov 22, 2019
70ea92a
Fix error
DeC0re Nov 22, 2019
270ac22
Fix error 1.2
DeC0re Nov 22, 2019
78512a3
Fix error 1.3
DeC0re Nov 22, 2019
1dcfc75
Full
DeC0re Dec 9, 2019
cfec148
fix error
DeC0re Dec 9, 2019
23d768b
Full lab v2
DeC0re Dec 9, 2019
5fcb268
Исправил
DeC0re Dec 16, 2019
7aafca5
Update Dog.cs
DeC0re Dec 16, 2019
f676422
Age
DeC0re Dec 17, 2019
665629c
test
DeC0re Dec 18, 2019
c66f6ac
Merge branch 'Vladislav_Savchenko' of https://github.com/DeC0re/Tprog…
DeC0re Dec 26, 2019
7235232
Суровый полиморфизм и иерархия наследования
DeC0re Dec 29, 2019
3ec6807
Merge branch 'Vladislav_Savchenko' into Vladislav_Savchenko
DeC0re Dec 29, 2019
75edeab
Update dotnetcore.yml
DeC0re Dec 29, 2019
b412163
Fix
DeC0re Dec 29, 2019
90f52e7
Merge branch 'Vladislav_Savchenko' of https://github.com/DeC0re/Tprog…
DeC0re Dec 29, 2019
7a3fe0d
Fix
DeC0re Jan 5, 2020
b27bf86
Merge branch 'Vladislav_Savchenko' of https://github.com/DeC0re/Tprog…
DeC0re Jan 5, 2020
aad514c
Исправления 3.0
DeC0re Jan 5, 2020
94e0eb1
Update dotnetcore.yml
DeC0re Jan 5, 2020
871c2d4
interfec
DeC0re Apr 13, 2020
2948911
Merge branch 'Vladislav_Savchenko' of https://github.com/DeC0re/Tprog…
DeC0re Apr 13, 2020
7563a42
Merge branch 'Vladislav_Savchenko' into Vladislav_Savchenko
DeC0re Apr 13, 2020
e2f268a
Update CourseApp.csproj
DeC0re Apr 13, 2020
e6d706e
Update CourseApp.Tests.csproj
DeC0re Apr 13, 2020
9869934
Update CourseApp.Tests.csproj
DeC0re Apr 13, 2020
1f4129b
Update CourseApp.csproj
DeC0re Apr 13, 2020
3e2035d
Update dotnetcore.yml
DeC0re Apr 13, 2020
a919c39
Update dotnetcore.yml
DeC0re Apr 13, 2020
06a5776
Update dotnetcore.yml
DeC0re Apr 13, 2020
60c070c
Update CourseApp.Tests.csproj
DeC0re Apr 13, 2020
b1d2689
Update CourseApp.csproj
DeC0re Apr 13, 2020
fa1392d
Update CourseApp.Tests.csproj
DeC0re Apr 13, 2020
186c63a
Update CourseApp.csproj
DeC0re Apr 13, 2020
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
13 changes: 13 additions & 0 deletions CourseApp.Tests/AnimalsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,18 @@ public void ToStringTesting()
Assert.Equal("Собака по имени White. Её возраст - 5, пол - женский", animals[0].ToString());
Assert.Equal("Кот по имени Black. Его возраст - 2, пол - мужской", animals[1].ToString());
}

[Fact]
public void ToCompareTest()
{
Animals[] animals = new Animals[3];
animals[0] = new Dog("White", 5, "female");
animals[1] = new Cat("Black", 2, "male");
animals[2] = new Dog("Black");
if (animals[0].CompareTo(animals[1]) == 1 && animals[1].CompareTo(animals[2]) == 0)
{
Assert.True(true);
}
}
}
}
4 changes: 2 additions & 2 deletions CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp 3.1</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
Expand All @@ -27,4 +27,4 @@
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
</Project>
26 changes: 26 additions & 0 deletions CourseApp/Animals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace CourseApp
{
public abstract class Animals : IComparable, IMovable
public abstract class Animals
{
private string sex;
Expand Down Expand Up @@ -58,5 +59,30 @@ public virtual void AgeUp()
{
this.Age++;
}

public virtual void Move()
{
Console.WriteLine("Животное идёт");
}

public int CompareTo(object o)
{
Animals animal = o as Animals;
if (animal != null)
{
if (animal.Name == this.Name)
{
return 0;
}
else
{
return 1;
}
}
else
{
throw new Exception("Невозможно сравнить два объекта");
}
}
}
}
6 changes: 6 additions & 0 deletions CourseApp/Cat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public override int Age
}
}

public override void Move()
{
Console.WriteLine("Кот крадётся");
}

public override string RunningSpeed()
{
return "Средняя скорость домашнего кота во время бега - 43 - 45 км/ч, максимальная - до 50 км/ч";
Expand All @@ -56,6 +61,7 @@ public override void Info()
{
Console.WriteLine(this.ToString());
Console.WriteLine(this.RunningSpeed());
this.Move();
}
}
}
4 changes: 2 additions & 2 deletions CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp 3.1</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705;</NoWarn>
</PropertyGroup>
Expand All @@ -20,4 +20,4 @@
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
</Project>
1 change: 1 addition & 0 deletions CourseApp/Dog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public override void Info()
{
Console.WriteLine(this.ToString());
Console.WriteLine(this.RunningSpeed());
this.Move();
}
}
}
9 changes: 9 additions & 0 deletions CourseApp/IComparable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace CourseApp
{
public interface IComparable
{
int CompareTo(object o);
}
}
9 changes: 9 additions & 0 deletions CourseApp/IMovable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace CourseApp
{
public interface IMovable
{
void Move();
}
}
15 changes: 12 additions & 3 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public static void Main(string[] args)
Console.WriteLine("Задание В:");
Console.WriteLine("==========");
foreach (var item in taskBRes)
{
Console.WriteLine($"y1 = {item}");
}
{
Console.WriteLine($"y1 = {item}");
}

Console.WriteLine("==========");
Animals[] animals = new Animals[2];
Expand All @@ -70,6 +70,15 @@ public static void Main(string[] args)
animal.Info();
Console.WriteLine();
}

if (animals[0].CompareTo(animals[1]) == 0)
{
Console.WriteLine("Животные имеют одинаковую кличку");
}
else
{
Console.WriteLine("Животные имеют разные клички");
}
}
}
}