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
54 changes: 54 additions & 0 deletions CourseApp.Tests/AnimalsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace CourseApp.Tests
{
using Xunit;

public class AnimalsTest
{
[Theory]
[InlineData("Animals", "Animals")]
[InlineData("Бычок", "Бычок")]
public void TestName(string a, string exp)
{
Pig actualResult = new Pig(a, 1);
Assert.Equal(exp, actualResult.Name);
}

[Theory]
[InlineData(88, 88)]
[InlineData(-20, 0)]
public void TestWeight(int a, int exp)
{
Pig actual = new Pig(" ", a);
Assert.Equal(exp, actual.Weight);
}

[Theory]
[InlineData(0, 0)]
[InlineData(-1, 0)]
[InlineData(88, 88)]
public void TestFat(int a, int expected)
{
Pig actual = new Pig(" ", 0, a);
Assert.Equal(expected, actual.Lard);
}

[Theory]
[InlineData(0, 0)]
[InlineData(-1, 0)]
[InlineData(8, 8)]
public void TestAge(int a, int expected)
{
Pig actual = new Pig(" ", 0, a, 88);
Assert.Equal(expected, actual.Age);
}

[Theory]
[InlineData("Бычок", 5, "Из Бычок можно получить 5 сала\n")]
[InlineData("Бычок", 0, "Бычок Без сала\n")]
public void TestToString(string n, int a, string expected)
{
Bull actual = new Bull(n, 8, a);
Assert.Equal(expected, actual.ToString());
}
}
}
53 changes: 51 additions & 2 deletions CourseApp.Tests/DemoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,58 @@ namespace CourseApp.Tests
public class DemoTest
{
[Fact]
public void Test1()
public void Test()
{
Assert.True(true);
}

[Fact]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please - use Inline data to check multiple cases

public void TestIntSum()
{
int firstNumber = 2;
int secondNumber = 3;
int expected = 5;
var calc = new Calculator();
var actual = calc.GetSum(firstNumber, secondNumber);

Assert.Equal(expected, actual);
}

[Fact]
public void TestIntProduct()
{
int firstNumber = 2;
int secondNumber = 3;
int expected = 6;
var calc = new Calculator();
var actual = calc.GetProduct(firstNumber, secondNumber);

Assert.Equal(expected, actual);
}

[Fact]
public void TestDoubleQuotient()
{
double firstNumber = 5;
double secondNumber = 2;
double expected = 2.5;
var calc = new Calculator();
var actual = calc.GetQuotient(firstNumber, secondNumber);

Assert.Equal(expected, actual);
}

[Fact]
public void TestDoubleQuotientNull()
{
var calc = new Calculator();
double firstNumber = 5;
double secondNumber = 0;
double expected = double.PositiveInfinity;

var actual = calc.GetQuotient(firstNumber, secondNumber);

Assert.Equal(expected, actual);
}
}
}
}
20 changes: 20 additions & 0 deletions CourseApp.Tests/MyProgTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace CourseApp.Tests
{
using Xunit;

public class MyProgTests
{
[Fact]
public void Sum1_And2_Returned3()
{
int x = 1;
int y = 2;
int expected = 3;

MyProg c = new MyProg();
int actual = c.Sum(x, y);

Assert.Equal(expected, actual);
}
}
}
117 changes: 117 additions & 0 deletions CourseApp/Animals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
namespace CourseApp
{
/* using System; */
/* using System.Collections.Generic;*/

public abstract class Animals
{
private int lard;
private int weight;
private int age;

public Animals()
: this("неизвестного животного", 10, 12, 13)
{
}

public Animals(string name, int weight)
: this(name, weight, 0, 0)
{
}

public Animals(string name, int weight, int lard)
: this(name, weight, 0, lard)
{
}

public Animals(string name, int weight, int age, int lard)
{
Name = name;
Lard = lard;
Age = age;
Weight = weight;
}
Comment on lines +12 to +33
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need that much of constructors?


public string Name
{
get;
set;
}

public int Weight
{
get
{
return weight;
}

set
{
if (value < 0)
{
weight = 0;
}
else
{
weight = value;
}
Comment on lines +50 to +57
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's throw exception here

}
}

public int Age
{
get
{
return age;
}

set
{
if (value < 0)
{
age = 0;
}
else
{
age = value;
}
}
}

public int Lard
{
get
{
return lard;
}

set
{
if (value < 0)
{
lard = 0;
}
else
{
lard = value;
}
}
}

public override string ToString()
{
if (lard == 0)
{
return $"{Name} Без сала\n";
}
else
{
return $"Из {Name} можно получить {Lard} сала\n";
}
}
Comment on lines +101 to +111
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Прям с любого животного? что-то не так с абстракциями


public abstract string Died();

public abstract string MakePhrase(string[] phraseArray);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Этот метод тут не нужен (да и в дочерних тоже)

}
}
44 changes: 44 additions & 0 deletions CourseApp/Bull.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
namespace CourseApp
{
using System;
/* using System.Collections.Generic;*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove commented code


public class Bull : Animals
{
private Random random = new Random();

public Bull()
: base()
{
}

public Bull(string name, int weight)
: base(name, weight)
{
}

public Bull(string name, int weight, int lard)
: base(name, weight, lard)
{
}

public Bull(string name, int weight, int age, int lard)
: base(name, weight, age, lard)
{
}

public override string Died()
{
int lard = Lard;
Lard = 0;
return $"{Name} убит\nПолучено {lard} сала\n";
}
Comment on lines +30 to +35
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

? Сало? same as for pig?


public override string MakePhrase(string[] phraseArray)
{
int index = random.Next(0, 3);
string phrase = phraseArray[index];
return $"{phrase}";
}
}
}
25 changes: 25 additions & 0 deletions CourseApp/Calculator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace CourseApp
{
public class Calculator
{
public int GetSum(int a, int b)
{
return a + b;
}

public double GeSum(double a, double b)
{
return a + b;
}

public int GetProduct(int a, int b)
{
return a * b;
}

public double GetQuotient(double a, double b)
{
return a / b;
}
}
}
18 changes: 3 additions & 15 deletions CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

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

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

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

</Project>
31 changes: 0 additions & 31 deletions CourseApp/CourseApp.sln

This file was deleted.

Loading