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

Ермаков Александр 2/147 #10

Open
wants to merge 6 commits into
base: master
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
433 changes: 433 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions ExamApp.Tests/ExamApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ExamApp\ExamApp.csproj" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions ExamApp.Tests/LionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using Xunit;

namespace ExamApp.Tests
{
public class LionTests
{
[Fact]
public void ZeroParameters()
{
Lion simba = new Lion();
string location = simba.Location;
string boundaries = simba.Boundaries;
Assert.Equal("World",location);
Assert.Equal("Unknown",boundaries);
}
[Fact]
public void Create()
{
Lion simba = new Lion("Africa","Savanna");
string location = simba.Location;
string boundaries = simba.Boundaries;
Assert.Equal("Africa", location);
Assert.Equal("Savanna", boundaries);
}
[Fact]
public void TestMethods()
{
Lion simba = new Lion("Africa","Savana");
Assert.Equal("Lion is asleep.",simba.Sleep());
Assert.Equal("A lion has caught a Zebra and is eating it.",simba.Eat());
Assert.Equal("The lion roars.",simba.MakeNoise());
string location = simba.Location;
string boundaries = simba.Boundaries;
Assert.Equal($"Lion roams - {location},{boundaries}.",simba.Roam());
}
[Fact]
public void TestNull()
{
Lion simba = new Lion("Africa","Savana");
simba.Boundaries = null;
simba.Location = null;
Assert.Equal("Africa",simba.Location);
Assert.Equal("Savana",simba.Boundaries);
}
}
}
47 changes: 47 additions & 0 deletions ExamApp.Tests/WolfTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using Xunit;

namespace ExamApp.Tests
{
public class WolfTests
{
[Fact]
public void ZeroParameters()
{
Wolf wolf = new Wolf();
string location = wolf.Location;
string boundaries = wolf.Boundaries;
Assert.Equal("World",location);
Assert.Equal("Unknown",boundaries);
}
[Fact]
public void Create()
{
Wolf wolf = new Wolf("Russia","Forest");
string location = wolf.Location;
string boundaries = wolf.Boundaries;
Assert.Equal("Russia", location);
Assert.Equal("Forest", boundaries);
}
[Fact]
public void TestMethods()
{
Wolf wolf = new Wolf("Russia","Forest");
Assert.Equal("Wolf is asleep.",wolf.Sleep());
Assert.Equal("The wolf eats the rabbit.",wolf.Eat());
Assert.Equal("The wolf howls at the moon.",wolf.MakeNoise());
string location = wolf.Location;
string boundaries = wolf.Boundaries;
Assert.Equal($"Wolf roams - {location},{boundaries}.",wolf.Roam());
}
[Fact]
public void TestNull()
{
Wolf wolf = new Wolf("Russia","Forest");
wolf.Boundaries = null;
wolf.Location = null;
Assert.Equal("Russia",wolf.Location);
Assert.Equal("Forest",wolf.Boundaries);
}
}
}
65 changes: 65 additions & 0 deletions ExamApp/Animals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;

namespace ExamApp
{
public abstract class Animals
{
private string location;
private string boundaries;

public string Location
{
get
{
return location;
}

set
{
if (value != null)
{
this.location = value;
}
}
}
public string Boundaries
{
get
{
return boundaries;
}

set
{
if (value != null)
{
this.boundaries = value;
}
}
}

public Animals()
{
Location = "World";
Boundaries = "Unknown";
}

public Animals(string location, string boundaries)
{
Location = location;
Boundaries = boundaries;
}

public virtual string Sleep()
{
return "Animal is asleep.";
}

public virtual string Roam()
{
return "Animal roams.";
}
public abstract string Eat();
public abstract string MakeNoise();
}
}
8 changes: 8 additions & 0 deletions ExamApp/ExamApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>
32 changes: 32 additions & 0 deletions ExamApp/Lion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;

namespace ExamApp
{
public class Lion : Animals
{
public Lion()
:base()
{}
public Lion(string location, string boundaries)
:base(location, boundaries)
{}

public override string Sleep()
{
return "Lion is asleep.";
}

public override string Roam()
{
return $"Lion roams - {Location},{Boundaries}.";
}
public override string Eat()
{
return "A lion has caught a Zebra and is eating it.";
}
public override string MakeNoise()
{
return "The lion roars.";
}
}
}
24 changes: 24 additions & 0 deletions ExamApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace ExamApp
{
class Program
{
static void Main(string[] args)
{
Lion simba = new Lion("Africa","Savannah");
Console.WriteLine("Lion:");
Console.WriteLine(simba.Sleep());
Console.WriteLine(simba.Roam());
Console.WriteLine(simba.Eat());
Console.WriteLine(simba.MakeNoise());

Wolf akela = new Wolf("India","Jungle");
Console.WriteLine("Wolf:");
Console.WriteLine(akela.Sleep());
Console.WriteLine(akela.Roam());
Console.WriteLine(akela.Eat());
Console.WriteLine(akela.MakeNoise());
}
}
}
30 changes: 30 additions & 0 deletions ExamApp/Wolf.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace ExamApp
{
public class Wolf : Animals
{
public Wolf()
:base()
{}
public Wolf(string location, string boundaries)
:base(location, boundaries)
{}

public override string Sleep()
{
return "Wolf is asleep.";
}

public override string Roam()
{
return $"Wolf roams - {Location},{Boundaries}.";
}
public override string Eat()
{
return "The wolf eats the rabbit.";
}
public override string MakeNoise()
{
return "The wolf howls at the moon.";
}
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# exam_147_2020
# Ермаков Александр 2/147

Создайте абстрактный класс животные, содержащие поля location и boundaries. Методы sleep и roam, а также абстрактные методы makeNoize и Eat, классы наследующие класс животное — Lion и Woolf. Оба класса наследника переопределяют методы базового класса. Приведите пример использования классов наследников.