diff --git a/CourseApp.Tests/FoxTest.cs b/CourseApp.Tests/FoxTest.cs new file mode 100644 index 0000000..be96d91 --- /dev/null +++ b/CourseApp.Tests/FoxTest.cs @@ -0,0 +1,73 @@ +using System; +using Xunit; +using Fauna; + +namespace CourseApp.Tests +{ + public class FoxTest + { + [Fact] + public void Test1() + { + Fox africa = new Fox("Neznaem", "White", 25, 30); + Assert.Equal("Unknow", africa.Gender); + Assert.Equal("White", africa.Color); + Assert.Equal(25, africa.Weight); + Assert.Equal(30, africa.Growth); + } + + [Fact] + public void Test2() + { + Fox europe = new Fox("Female", -15); + Assert.Equal("Female", europe.Gender); + Assert.Equal(0, europe.Weight); + } + + [Fact] + public void Test3() + { + Fox europe = new Fox("Koshka", -3); + Assert.Equal("Unknow", europe.Gender); + Assert.Equal(0, europe.Weight); + } + + [Fact] + public void Test4() + { + Fox europe = new Fox("Male", 28); + Assert.Equal("Male", europe.Gender); + Assert.Equal(28, europe.Weight); + } + + [Fact] + public void Test5() + { + Fox africa = new Fox("Male", "Blond", 13, -5); + Assert.Equal("Male", africa.Gender); + Assert.Equal("Blond", africa.Color); + Assert.Equal(13, africa.Weight); + Assert.Equal(0, africa.Growth); + } + + [Fact] + public void Test6() + { + Fox africa = new Fox("Neznaem", "", -25, -30); + Assert.Equal("Unknow", africa.Gender); + Assert.Equal("UnknowColor", africa.Color); + Assert.Equal(0, africa.Weight); + Assert.Equal(0, africa.Growth); + } + + [Fact] + public void Test7() + { + Fox africa = new Fox("Male", "555", 15, 20); + Assert.Equal("Male", africa.Gender); + Assert.Equal("UnknowColor", africa.Color); + Assert.Equal(15, africa.Weight); + Assert.Equal(20, africa.Growth); + } + } +} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index fbd0c9d..bb8d278 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -1,4 +1,4 @@ - + Exe diff --git a/CourseApp/CourseApp.sln b/CourseApp/CourseApp.sln new file mode 100644 index 0000000..23ea1c4 --- /dev/null +++ b/CourseApp/CourseApp.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.168 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp", "CourseApp.csproj", "{C95F0266-E3E5-484C-858A-D4C61EC6A4AA}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp.Tests", "..\CourseApp.Tests\CourseApp.Tests.csproj", "{22805653-2FE6-40B8-B856-4D9884187751}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C95F0266-E3E5-484C-858A-D4C61EC6A4AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C95F0266-E3E5-484C-858A-D4C61EC6A4AA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C95F0266-E3E5-484C-858A-D4C61EC6A4AA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C95F0266-E3E5-484C-858A-D4C61EC6A4AA}.Release|Any CPU.Build.0 = Release|Any CPU + {22805653-2FE6-40B8-B856-4D9884187751}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {22805653-2FE6-40B8-B856-4D9884187751}.Debug|Any CPU.Build.0 = Debug|Any CPU + {22805653-2FE6-40B8-B856-4D9884187751}.Release|Any CPU.ActiveCfg = Release|Any CPU + {22805653-2FE6-40B8-B856-4D9884187751}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0DEB2E85-CECB-44FB-B010-E7DF83EC7B26} + EndGlobalSection +EndGlobal diff --git a/CourseApp/Fox.cs b/CourseApp/Fox.cs new file mode 100644 index 0000000..0dd4f6f --- /dev/null +++ b/CourseApp/Fox.cs @@ -0,0 +1,100 @@ +using System; + +namespace Fauna +{ + public class Fox + { + private string gender; + private string color; + private int weight; + private int growth; + + public Fox(string gender, string color, int weight, int growth) + { + + + this.Gender = gender; + this.Color = color; + this.Weight = weight; + this.Growth = growth; + } + + public Fox(string gender, int weight) + : this(gender, string.Empty, weight, 0) + { + } + + public string Gender + { + get => gender; + set + { + if (value == $"Male") + { + gender = value; + } + else if (value == $"Female") + { + gender = value; + } + else + { + gender = $"Unknow"; + } + + } + + + } + + public string Color + { + get => color; + set + { + if (value == $"White") + { + color = value; + } + else if (value == $"Blond") + { + color = value; + } + else if (value == $"Red") + + { + color = value; + } + else if (value == string.Empty) + { + color = $"UnknowColor"; + } + else + { + color = $"UnknowColor"; + } + + } + } + + public int Weight + { + get => weight; + set + { + weight = value > 0 ? value : 0; + } + } + + public int Growth + { + get => growth; + set + { + growth = value > 0 ? value : 0; + } + } + + public void GetInfo() => Console.WriteLine($"Пол: {gender} Цвет: {color} Вес: {weight} Рост: {growth}"); + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 1914879..1307d9e 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,7 +1,10 @@ -using System; +using System; +using Fauna; + namespace Matem + { public class Program { @@ -34,6 +37,15 @@ static void Main(string[] args) { Console.WriteLine($"Для x = {i}\t y = {y(i, a, b)}"); } + + + Fox africa = new Fox($"Male", $"White", 25, 30); + Fox europe = new Fox($"Female", 15); + africa.GetInfo(); + europe.GetInfo(); + + Console.ReadKey(); + } } } \ No newline at end of file