From aaca16ed967bc8d992ba2148ab77daf0019caae1 Mon Sep 17 00:00:00 2001 From: Acerlaorion <52343449+Acerlaorion@users.noreply.github.com> Date: Wed, 18 Dec 2019 19:57:30 +0300 Subject: [PATCH 1/5] Superclass --- CourseApp.Tests/CityTest.cs | 87 ++++++++++++++++++++++++++++++++++ CourseApp.Tests/VillageTest.cs | 87 ++++++++++++++++++++++++++++++++++ CourseApp/City.cs | 66 ++++++++++++++++++++++++++ CourseApp/Settlement.cs | 75 +++++++++++++++++++++++++++++ CourseApp/Village.cs | 66 ++++++++++++++++++++++++++ 5 files changed, 381 insertions(+) create mode 100644 CourseApp.Tests/CityTest.cs create mode 100644 CourseApp.Tests/VillageTest.cs create mode 100644 CourseApp/City.cs create mode 100644 CourseApp/Settlement.cs create mode 100644 CourseApp/Village.cs 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/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..f51925c --- /dev/null +++ b/CourseApp/City.cs @@ -0,0 +1,66 @@ +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) + { + Name = name; + Population = population; + Square = square; + } + + 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"); + } + } + } + } +} diff --git a/CourseApp/Settlement.cs b/CourseApp/Settlement.cs new file mode 100644 index 0000000..25ae719 --- /dev/null +++ b/CourseApp/Settlement.cs @@ -0,0 +1,75 @@ +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) + { + Name = name; + Population = population; + } + + 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..9626a4a --- /dev/null +++ b/CourseApp/Village.cs @@ -0,0 +1,66 @@ +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) + { + 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"); + } + } + } + } +} From 375434636036d5e9d6d723e3e30f5241ed025f20 Mon Sep 17 00:00:00 2001 From: mahaikova Date: Sun, 22 Dec 2019 17:50:48 +0300 Subject: [PATCH 2/5] Fix --- CourseApp/City.cs | 5 +++++ CourseApp/Settlement.cs | 7 ++++++- CourseApp/Village.cs | 6 ++++++ courseworkspace.code-workspace | 8 +++++++- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CourseApp/City.cs b/CourseApp/City.cs index f51925c..ffd7c8a 100644 --- a/CourseApp/City.cs +++ b/CourseApp/City.cs @@ -22,6 +22,7 @@ public City(string name, int population) } public City(string name, int population, int square) + :base(name, population, square) { Name = name; Population = population; @@ -62,5 +63,9 @@ public override int Square } } } + public override string ToString() + { + return $"Name of City:{Name},Population of City:{Population}, Square of City:{Square}"; + } } } diff --git a/CourseApp/Settlement.cs b/CourseApp/Settlement.cs index 25ae719..f96bb60 100644 --- a/CourseApp/Settlement.cs +++ b/CourseApp/Settlement.cs @@ -20,11 +20,16 @@ public Settlement(string name) } 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 diff --git a/CourseApp/Village.cs b/CourseApp/Village.cs index 9626a4a..3473604 100644 --- a/CourseApp/Village.cs +++ b/CourseApp/Village.cs @@ -22,6 +22,7 @@ public Village(string name, int population) } public Village(string name, int population, int square) + :base(name, population, square) { Name = name; Population = population; @@ -62,5 +63,10 @@ public override int 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 From d42c06296c8f4c619844c82fe3411c4a51e951c1 Mon Sep 17 00:00:00 2001 From: mahaikova Date: Sun, 22 Dec 2019 18:10:29 +0300 Subject: [PATCH 3/5] FixCop --- CourseApp/City.cs | 3 ++- CourseApp/Settlement.cs | 3 ++- CourseApp/Village.cs | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CourseApp/City.cs b/CourseApp/City.cs index ffd7c8a..a42151b 100644 --- a/CourseApp/City.cs +++ b/CourseApp/City.cs @@ -22,7 +22,7 @@ public City(string name, int population) } public City(string name, int population, int square) - :base(name, population, square) + : base(name, population, square) { Name = name; Population = population; @@ -63,6 +63,7 @@ public override int Square } } } + public override string ToString() { return $"Name of City:{Name},Population of City:{Population}, Square of City:{Square}"; diff --git a/CourseApp/Settlement.cs b/CourseApp/Settlement.cs index f96bb60..b494442 100644 --- a/CourseApp/Settlement.cs +++ b/CourseApp/Settlement.cs @@ -20,7 +20,7 @@ public Settlement(string name) } public Settlement(string name, int population) - :this(name, population, 0) + : this(name, population, 0) { } @@ -30,6 +30,7 @@ public Settlement(string name, int population, int square) Population = population; Square = square; } + public string Name { get; set; } public virtual int Population diff --git a/CourseApp/Village.cs b/CourseApp/Village.cs index 3473604..2e1b40d 100644 --- a/CourseApp/Village.cs +++ b/CourseApp/Village.cs @@ -22,7 +22,7 @@ public Village(string name, int population) } public Village(string name, int population, int square) - :base(name, population, square) + : base(name, population, square) { Name = name; Population = population; @@ -63,7 +63,7 @@ public override int Square } } } - + public override string ToString() { return $"Name of Village:{Name},Population of Village:{Population}, Square of Village:{Square}"; From 90a342e44d45c99bcc7021f964b2a7b8da4db25d Mon Sep 17 00:00:00 2001 From: mahaikova Date: Sun, 29 Dec 2019 15:05:08 +0300 Subject: [PATCH 4/5] add IsCapital --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp/City.cs | 11 +++++++++++ CourseApp/CourseApp.csproj | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 58dffa3..2ddfe27 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0 + netcoreapp2.0,netcoreapp2.1 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp/City.cs b/CourseApp/City.cs index a42151b..a005ec4 100644 --- a/CourseApp/City.cs +++ b/CourseApp/City.cs @@ -22,13 +22,24 @@ public City(string name, int population) } 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 diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index dffae8d..aca43e7 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0 + netcoreapp2.0,netcoreapp2.1 True 1573,1591,1701;1702;1705; From 3de7f24055f8b0eef4099644b48fb7f07a299caa Mon Sep 17 00:00:00 2001 From: mahaikova Date: Sun, 29 Dec 2019 15:19:11 +0300 Subject: [PATCH 5/5] netcore version fix --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp/CourseApp.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 2ddfe27..668406b 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.0,netcoreapp2.1 + netcoreapp2.1 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index aca43e7..b244e47 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.0,netcoreapp2.1 + netcoreapp2.1 True 1573,1591,1701;1702;1705;