diff --git a/CourseApp.Tests/CityTest.cs b/CourseApp.Tests/CityTest.cs new file mode 100644 index 0000000..a66e6aa --- /dev/null +++ b/CourseApp.Tests/CityTest.cs @@ -0,0 +1,87 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class CityTest + { + [Theory] + [InlineData("Name", 1, 18156)] + [InlineData("Name1", 3, 9547156)] + public void TestConstructorThreeParametrs(string name, int population, int square) + { + var item = new City(name, population, square); + Assert.Equal(population, item.Population); + Assert.Equal(name, item.Name); + Assert.Equal(square, item.Square); + } + + [Fact] + public void TestConstructorTwoParametrs() + { + var item = new City("Name", 300000); + Assert.Equal(300000, item.Population); + Assert.Equal("Name", item.Name); + Assert.Equal(0, item.Square); + } + + [Fact] + public void TestConstructorOneParametrs() + { + var item = new City("Name2"); + Assert.Equal(1, item.Population); + Assert.Equal("Name2", item.Name); + Assert.Equal(0, item.Square); + } + + [Fact] + public void TestEmptyConstructor() + { + var item = new City(); + Assert.Equal(1, item.Population); + Assert.Equal("Unnamed", item.Name); + Assert.Equal(0, item.Square); + } + + [Fact] + public void TestSetPopulation() + { + var item = new City(); + item.Population = 500000; + Assert.Equal(500000, item.Population); + } + + [Fact] + public void TestIncorrectSetPopulation() + { + try + { + var item = new City(); + item.Population = -5; + } + catch (System.Exception) + { + Console.WriteLine("Population should be > 1"); + Assert.True(true); + } + } + + [Fact] + public void TestCorrectIncorrectSetPopulation() + { + var item = new City(); + try + { + item.Population = 10; + item.Population = -5; + } + catch (System.Exception) + { + Console.WriteLine("Population should be > 1"); + Assert.True(true); + } + + Assert.Equal(10, item.Population); + } + } +} diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 58dffa3..668406b 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp2.1 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp.Tests/VillageTest.cs b/CourseApp.Tests/VillageTest.cs new file mode 100644 index 0000000..0fa3385 --- /dev/null +++ b/CourseApp.Tests/VillageTest.cs @@ -0,0 +1,87 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class VillageTest + { + [Theory] + [InlineData("Name", 1, 18156)] + [InlineData("Name1", 3, 95476)] + public void TestConstructorThreeParametrs(string name, int population, int square) + { + var item = new Village(name, population, square); + Assert.Equal(population, item.Population); + Assert.Equal(name, item.Name); + Assert.Equal(square, item.Square); + } + + [Fact] + public void TestConstructorTwoParametrs() + { + var item = new Village("Name", 300000); + Assert.Equal(300000, item.Population); + Assert.Equal("Name", item.Name); + Assert.Equal(0, item.Square); + } + + [Fact] + public void TestConstructorOneParametrs() + { + var item = new Village("Name2"); + Assert.Equal(1, item.Population); + Assert.Equal("Name2", item.Name); + Assert.Equal(0, item.Square); + } + + [Fact] + public void TestEmptyConstructor() + { + var item = new Village(); + Assert.Equal(1, item.Population); + Assert.Equal("Unnamed", item.Name); + Assert.Equal(0, item.Square); + } + + [Fact] + public void TestSetPopulation() + { + var item = new Village(); + item.Population = 354900; + Assert.Equal(354900, item.Population); + } + + [Fact] + public void TestIncorrectSetPopulation() + { + try + { + var item = new City(); + item.Population = -5; + } + catch (System.Exception) + { + Console.WriteLine("Population should be > 1"); + Assert.True(true); + } + } + + [Fact] + public void TestCorrectIncorrectSetPopulation() + { + var item = new Village(); + try + { + item.Population = 10; + item.Population = -5; + } + catch (System.Exception) + { + Console.WriteLine("Population should be > 1"); + Assert.True(true); + } + + Assert.Equal(10, item.Population); + } + } +} diff --git a/CourseApp/City.cs b/CourseApp/City.cs new file mode 100644 index 0000000..a005ec4 --- /dev/null +++ b/CourseApp/City.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CourseApp +{ + public class City : Settlement + { + public City() + : base("Unnamed") + { + } + + public City(string name) + : base(name, 1) + { + } + + public City(string name, int population) + : this(name, population, 0) + { + } + + public City(string name, int population, int square) + : this(name, population, square, false) + { + Name = name; + Population = population; + Square = square; + } + + public City(string name, int population, int square, bool isCapital) + : base(name, population, square) + { + Name = name; + Population = population; + Square = square; + IsCapital = isCapital; + } + + public bool IsCapital { get; set; } + + public override int Population + { + set + { + if (value >= 0 && value < 70000000) + { + base.Population = value; + } + else + { + throw new System.Exception("Wrong population"); + } + } + } + + public override int Square + { + get + { + return base.Square; + } + + set + { + if (value >= 0 && value <= 100000000) + { + base.Square = value; + } + else + { + throw new System.Exception("Wrong square"); + } + } + } + + public override string ToString() + { + return $"Name of City:{Name},Population of City:{Population}, Square of City:{Square}"; + } + } +} diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index dffae8d..b244e47 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp2.1 True 1573,1591,1701;1702;1705; diff --git a/CourseApp/Settlement.cs b/CourseApp/Settlement.cs new file mode 100644 index 0000000..b494442 --- /dev/null +++ b/CourseApp/Settlement.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CourseApp +{ + public abstract class Settlement + { + private int population; + private int square; + + public Settlement() + : this("Unnamed") + { + } + + public Settlement(string name) + : this(name, 1) + { + } + + public Settlement(string name, int population) + : this(name, population, 0) + { + } + + public Settlement(string name, int population, int square) + { + Name = name; + Population = population; + Square = square; + } + + public string Name { get; set; } + + public virtual int Population + { + get + { + return population; + } + + set + { + if (value >= 0) + { + population = value; + } + else + { + throw new System.Exception("Wrong population"); + } + } + } + + public virtual int Square + { + get + { + return square; + } + + set + { + if (value >= 0) + { + square = value; + } + else + { + throw new System.Exception("Wrong square"); + } + } + } + + public override string ToString() + { + return $"Name:{Name},Population:{Population}, Square:{Square}"; + } + } +} diff --git a/CourseApp/Village.cs b/CourseApp/Village.cs new file mode 100644 index 0000000..2e1b40d --- /dev/null +++ b/CourseApp/Village.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CourseApp +{ + public class Village : Settlement + { + public Village() + : base("Unnamed") + { + } + + public Village(string name) + : base(name, 1) + { + } + + public Village(string name, int population) + : this(name, population, 0) + { + } + + public Village(string name, int population, int square) + : base(name, population, square) + { + Name = name; + Population = population; + Square = square; + } + + public override int Population + { + set + { + if (value >= 0 && value < 500000) + { + base.Population = value; + } + else + { + throw new System.Exception("Wrong population"); + } + } + } + + public override int Square + { + get + { + return base.Square; + } + + set + { + if (value >= 0 && value <= 500000) + { + base.Square = value; + } + else + { + throw new System.Exception("Wrong square"); + } + } + } + + public override string ToString() + { + return $"Name of Village:{Name},Population of Village:{Population}, Square of Village:{Square}"; + } + } +} diff --git a/courseworkspace.code-workspace b/courseworkspace.code-workspace index 4f9af01..726e6d4 100644 --- a/courseworkspace.code-workspace +++ b/courseworkspace.code-workspace @@ -7,5 +7,11 @@ "path": "CourseApp.Tests" } ], - "settings": {} + "settings": { + "githubPullRequests.remotes": [ + "origin", + "upstream", + "isuct" + ] + } } \ No newline at end of file