-
Notifications
You must be signed in to change notification settings - Fork 17
Superclass #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mahaikova
wants to merge
5
commits into
ISUCT:Marija_Mahajkova
Choose a base branch
from
mahaikova:Marija_Mahajkova
base: Marija_Mahajkova
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Superclass #71
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}"; | ||
mahaikova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
mahaikova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.