Skip to content
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
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.1</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>
33 changes: 33 additions & 0 deletions CourseApp.Tests/DateTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using Xunit;
using CourseApp;

namespace CourseApp.Tests
{
public class DateTest
{
[Fact]
public void Test1()
{
DateTime dr = new DateTime(1990, 9, 17);
var time = Date.DateB(dr);
Assert.Equal("Год: 28 Месяц: 05 День: 20", Date.DateB(dr));
}

[Fact]
public void Test2()
{
DateTime dr = new DateTime(2010, 2, 2);
var time = Date.DateB(dr);
Assert.Equal("Год: 09 Месяц: 01 День: 04", Date.DateB(dr));
}

[Fact]
public void Test3()
{
DateTime dr = new DateTime(11, 11, 11);
var time = Date.DateB(dr);
Assert.Equal("Год: 07 Месяц: 03 День: 26", Date.DateB(dr));
}
}
}
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);
}
}
}
36 changes: 36 additions & 0 deletions CourseApp/Cavy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace CourseApp
{
public class Cavy : Pet
{
public override void NewPet()
Copy link
Contributor

Choose a reason for hiding this comment

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

Опять же это теперь делает базовый класс, можно убирать

{
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();
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("Введите имена родителй морской свинки: ");
Copy link
Contributor

Choose a reason for hiding this comment

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

А саму логику создания и внесения родителей следует унести в конструктор класса

Pearent1 = Console.ReadLine();
Pearent2 = Console.ReadLine();
Spisok.Add(Name, new NewPet(Pearent1, Pearent2, "cavy"));
foreach(string i in Spisok.Keys)
{
if(Pearent1 == i )
{
Spisok.Add(Pearent1, new NewPet(Name, "cavy"));
}

if(Pearent2 == i)
{
Spisok.Add(Pearent2, new NewPet(Name, "cavy"));
}
}
}

public override string GetInfo()
{
return $"Морская свинка: {Name} ";
}
}
}
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>
12 changes: 12 additions & 0 deletions CourseApp/Date.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace CourseApp
{
public class Date
{
public static string DateB(DateTime dr)
{
return DateTime.Today.AddYears(-dr.Year).AddMonths(-dr.Month).AddDays(-dr.Day).ToString("Год: yy Месяц: MM День: dd");
}
}
}
37 changes: 37 additions & 0 deletions CourseApp/Krolik.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace CourseApp
{
public class Krolik : Pet
{

public override void NewPet()
Copy link
Contributor

Choose a reason for hiding this comment

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

Это теперь делает базовый класс, только передавайте

{
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();
Spisok.Add(Name, new NewPet(Pearent1, Pearent2, "rabbit"));
foreach(string i in Spisok.Keys)
{
if(Pearent1 == i )
{
Spisok.Add(Pearent1, new NewPet(Name, "rabbit"));
}

if(Pearent2 == i)
{
Spisok.Add(Pearent2, new NewPet(Name, "rabbit"));
}
}
}

public override string GetInfo()
{
return $"Кролик: {Name} ";
}
}
}
Loading