Skip to content
Open
Show file tree
Hide file tree
Changes from 21 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
30 changes: 30 additions & 0 deletions CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

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

<PropertyGroup>
<CodeAnalysisRuleSet>../stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../stylecop/stylecop.json" />
</ItemGroup>

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

namespace CourseApp.Tests
{
public class DemoTest
{
[Fact]
public void Test1()
{
Assert.True(true);
}
}
}
58 changes: 58 additions & 0 deletions CourseApp.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using Xunit;
using CourseApp;

namespace CourseApp.Tests
{
public class UnitTest1
{

[Fact]
public void Test1()
{
var res = Program.Fan(0.7,1.2,0.48);
Assert.Equal(0.326, res, 3);
}

[Fact]
public void Test2()
{
var res = Program.Fan(1.0,1.2,0.48);
Assert.Equal(0.584, res, 3);
}

[Fact]
public void Test3()
{
var res = Program.Fan(1.3,1.2,0.48);
Assert.Equal(0.968, res, 3);
}

[Fact]
public void Test4()
{
var res = Program.Fan(1.6,1.2,0.48);
Assert.Equal(Double.NaN, res, 3);
}

[Fact]
public void Test5()
{
var res = Program.Fan(1.9,1.2,0.48);
Assert.Equal(Double.NaN, res, 3);
}

double[] xx = {0.25, 0.36, 0.56, 0.94, 1.28};

[Fact]
public void Test6()
{
double[] o = new double[5] {0.082,0.122,0.229,0.528,0.930};
foreach (int i in xx)
{
var res = Program.Fan(xx[i],1.2,0.48);
Assert.Equal(o[i], res, 3);
}
}
}
}
82 changes: 82 additions & 0 deletions CourseApp.Tests/UnitTest2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using System;
using Xunit;
using CourseApp;
using System.Collections.Generic;
using System.Collections;

namespace CourseApp.Tests
{
public class UnitTest2
{
[Fact]
public void Test1()
{
var krosh = new InfoRabbit();
var N ="momo";
krosh.RabbitInfo(N);
Assert.Equal("momo",N);
Copy link
Contributor

Choose a reason for hiding this comment

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

этот тест не проверяет ващ класс - он только проверяет что переменная N, объявленная в тесте = "momo"

}
[Fact]
public void Test2()
{
var krosh = new InfoRabbit();
var N ="momo";
var P1 = "mu";
var P2 = "nu";
krosh.RabbitInfo(N);
Assert.Equal("momo",N);
Copy link
Contributor

Choose a reason for hiding this comment

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

Та же беда - вы проверяете не свойство класса, а проверяете значение переменных, которые объявлены в тесте

Assert.Equal("mu",P1);
Assert.Equal("nu",P2);
}
[Fact]
public void Test3()
{
var krosh = new InfoRabbit();
var N ="momo";
var P1 = "mu";
var P2 = "nu";
List<string> ch=new List<string> {"Mura","Gura","Fedya"};
krosh.RabbitInfo(N,P1,P2,ch);
Assert.Equal("momo",N);
Assert.Equal("mu",P1);
Assert.Equal("nu",P2);
Assert.Equal("Mura",ch[0]);
Assert.Equal("Gura",ch[1]);
Assert.Equal("Fedya",ch[2]);
}
[Fact]
public void Test4()
{
Menu ferma = new Menu();
ferma.Name = "Boo";
Assert.Equal("Boo",ferma.Name);
} [Fact]
public void Test5()
{
Menu ferma = new Menu();
ferma.klet.Add("Boo");
Assert.Equal("Boo",ferma.klet[0]);
}
[Fact]
public void Test6()
{
Menu ferma = new Menu();
ferma.menu("Stl");
ferma.Name="Boo";
ferma.Pearent1="Buu";
ferma.Pearent2="Buuu";
Assert.Equal("Boo",ferma.klet[0]);
Assert.Equal("Buu",ferma.klet[0]);
Assert.Equal("Buuu",ferma.klet[0]);
}
[Fact]
public void Test7()
{
Menu ferma = new Menu();
var go="heip";
var osh="Такой команды не существует. help - узнать список команд.";
ferma.menu(go);
Assert.Equal(osh);
}
}
}
15 changes: 15 additions & 0 deletions CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../stylecop/stylecop.json" />
</ItemGroup>

</Project>
36 changes: 36 additions & 0 deletions CourseApp/Info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;

namespace CourseApp
{
public class Info
{
public void PetInfo(string name, string pearent1, string pearent2, List<string> child, string vid)
{
Console.Write($"{vid} {name}, Родители: {pearent1} и {pearent2}, Дети: ");
foreach(var i in child)
{
Console.WriteLine($"{i} ");
}
}

public void PetInfo(string name, string pearent1, string pearent2, string vid)
{
Console.WriteLine($"{vid} {name}, Родители: {pearent1} и {pearent2}, Детей нет");
}

public void PetInfo(string name, string vid)
{
Console.WriteLine($"{vid} {name}, Родители: ??? и ???, Дети нет");
}

public void PetInfo(string name, List<string> child, string vid)
{
Console.Write($"{vid} {name}, Родители: ??? и ???, Дети: ");
foreach(var i in child)
{
Console.WriteLine($"{i} ");
}
}
}
}
33 changes: 33 additions & 0 deletions CourseApp/Krolik.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace CourseApp
{
public class Krolik : Zoo
Copy link
Contributor

Choose a reason for hiding this comment

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

Почему кролик наследует зоопарк? Тут с именованием явная беда - при наследовании у нас отошение is-A - "является" . Кролик вряд ли является зоопарком :(

{
public void BuyKrolik()
{
Console.Write("Введите имя купленного кролика: ");
Name = Console.ReadLine();
Copy link
Contributor

Choose a reason for hiding this comment

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

не не - это - плохая идея - обработку пользовательского ввода вести в классахз, фактически представляюзих модели данных - уберите, а Name передавайте как параметр метода. И сразу подумайте - а как это протестировать?

Klet.Add(new NewPet(Name));
}

public void NewKrolik()
{
Console.Write("Введите имя новорожденного кролика: ");
Copy link
Contributor

Choose a reason for hiding this comment

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

то же самое - вынесите в основную программу получение параметров, а здесь, только их проверьте

Name = Console.ReadLine();
Console.WriteLine("Введите имена родителй кролика: ");
Pearent1 = Console.ReadLine();
Pearent2 = Console.ReadLine();
Klet.Add(new NewPet(Name, Pearent1, Pearent2));
foreach(NewPet i in Klet)
{
if(Pearent1 == i.Name || Pearent2 == i.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

А как же первых добавить?

Copy link
Author

Choose a reason for hiding this comment

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

Покупая в магазине мы не знаем кто родители, потому иногда эти свойства могут отсутствовать.)

{
i.Child.Add(Name);
}
}
}
}
}
105 changes: 105 additions & 0 deletions CourseApp/Menu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace CourseApp
{
public class Menu : Zoo
{
public void MenuZoo(string go)
{
Info pInfo = new Info();
Krolik krosh = new Krolik();
switch (go)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Вот это максимально похоже а идею фабричного метода и его следует вынести отдельно, но пока для упрощения оставим как есть

case "Buy":
Console.WriteLine("Введите кого вы хоите купить: кролик/мышь");
Vid = Console.ReadLine();
if (Vid == "кролик")
{
krosh.BuyKrolik();
}

break;
case "Sel":
Copy link
Contributor

Choose a reason for hiding this comment

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

тут так просто не разобраться, попробую завтра переписать по другому

Console.WriteLine("Введите кого вы хоите разводить: кролик/мышь");
Vid = Console.ReadLine();
if (Vid == "кролик")
{
krosh.NewKrolik();
}

break;
case "Art":
Art();
break;
case "Inf":
Console.Write("Введите имя животного о котором хотите унать: ");
Copy link
Contributor

Choose a reason for hiding this comment

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

Это следует убрать - не дело меню про это знать

Name = Console.ReadLine();
foreach(NewPet i in Klet)
{
if(i.Name == Name)
{
if (i.Pearent1 == null && i.Child.Count == 0)
{
pInfo.PetInfo(i.Name, i.Vid);
}
else if(i.Pearent1 != null && i.Child.Count == 0)
{
pInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Vid);
}
else if(i.Pearent1 == null && i.Child.Count != 0)
{
pInfo.PetInfo(i.Name, i.Child, i.Vid);
}
else if(i.Pearent1 != null && i.Child.Count != 0)
{
pInfo.PetInfo(i.Name, i.Pearent1, i.Pearent2, i.Child, i.Vid);
}
}
}

break;
case "help":
Help();
break;
case "Info": int num = 1;
foreach(NewPet i in Klet)
{
Console.WriteLine($"{num++}){i.Vid} {i.Name}");
}

break;
default: if(go != "Stop")
{
Console.WriteLine("Такой команды не существует. help - узнать список команд.");
}

break;
}

Console.WriteLine("----------");
}

private static void Help()
{
Console.WriteLine(@"
Команды:
Stop - закончить программу;
Art - вывести рисунок кроликов;
Buy - купить нового кролика;
Sel - выростить нового кролика;
Info - узнать имена всех кроликов
Inf - узнать о конкретном кролике
");
}

private static void Art()
{
Console.WriteLine(@"
------/)/)------/),/)----(\__/)---(\.(\-----(\(\
-----(':'=)----(':'=)---(=';'=)---(=':')----(=':')
--(')('),,)-(')('),,)---(')_(')---(..(')(')-(..(')(') ");
}
}
}
Loading