From c20b78247a7db824a0105ac878aa5e1e76320873 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 6 Jan 2020 10:44:33 +0300 Subject: [PATCH 1/8] remove code style ref --- CourseApp.Tests/CourseApp.Tests.csproj | 3 --- CourseApp/CourseApp.csproj | 3 --- CourseApp/Program.cs | 2 +- _stylecop/stylecop.json | 12 ------------ _stylecop/stylecop.ruleset | 14 -------------- 5 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 _stylecop/stylecop.json delete mode 100644 _stylecop/stylecop.ruleset diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a..d53285f 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -11,7 +11,6 @@ - @@ -19,12 +18,10 @@ - ../_stylecop/stylecop.ruleset true - diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index b244e47..8703eae 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -8,16 +8,13 @@ - - ../_stylecop/stylecop.ruleset true - diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 637c621..e932330 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -66,7 +66,7 @@ public static void Main(string[] args) var item = new Platypus(); Console.WriteLine(item.View()); - Console.ReadLine(); + Console.ReadLine(); } } } \ No newline at end of file diff --git a/_stylecop/stylecop.json b/_stylecop/stylecop.json deleted file mode 100644 index 4a96e8f..0000000 --- a/_stylecop/stylecop.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", - "settings": { - "documentationRules": { - "documentExposedElements": false, - "documentInterfaces": false, - "companyName": "Test Company", - "copyrightText": "This source code is Copyright © {companyName} and MAY NOT be copied, reproduced,\npublished, distributed or transmitted to or stored in any manner without prior\nwritten consent from {companyName} (www.yourcompany.com).", - "xmlHeader":false - } - } -} \ No newline at end of file diff --git a/_stylecop/stylecop.ruleset b/_stylecop/stylecop.ruleset deleted file mode 100644 index 98806c8..0000000 --- a/_stylecop/stylecop.ruleset +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file From 3fd25f048af2940316eb8644ef2df64a4a76be17 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 6 Jan 2020 10:51:19 +0300 Subject: [PATCH 2/8] add table class and update tests --- CourseApp.Tests/PlatypusTest.cs | 85 ++++++++++++++++++++++----------- CourseApp/Platypus.cs | 60 ----------------------- CourseApp/Program.cs | 21 +++++++- CourseApp/Table.cs | 30 ++++++++++++ 4 files changed, 107 insertions(+), 89 deletions(-) delete mode 100644 CourseApp/Platypus.cs create mode 100644 CourseApp/Table.cs diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs index 77c4d8f..5d667ab 100644 --- a/CourseApp.Tests/PlatypusTest.cs +++ b/CourseApp.Tests/PlatypusTest.cs @@ -6,50 +6,81 @@ namespace CourseApp.Tests public class PlatypusTest { [Fact] - public void TestEmptyConstructor() + public void TestCreateTable() { - var item = new Platypus(); - Assert.Equal(0, item.Age); - Assert.Equal("Untitled", item.Name); - Assert.True(item.IsMale); + var item = new Table(12, 13, "white"); + Assert.Equal(12, item.Weigh); + Assert.Equal(13, item.Height); + Assert.Equal("white", item.Color); } [Fact] - public void TestView() + public void TestCreateTableWithoutColor() { - var item = new Platypus(); - var view = @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; - Assert.Equal(view, item.View()); + var item = new Table(12, 13); + Assert.Equal(12, item.Weigh); + Assert.Equal(13, item.Height); + Assert.Equal("black", item.Color); } [Fact] - public void TestSetAge() + public void TestGetToString() { - var item = new Platypus(); - item.Age = 5; - Assert.Equal(5, item.Age); + var ecString = "Weigh = 12, Height = 12, Color = red"; + var item = new Table(12, 12, "red"); + Assert.Equal(ecString, item.ToString()); } [Fact] - public void TestIncorrectSetAge() + public void TestCreateTableWithWrongWeigth() { - var item = new Platypus(); - item.Age = -5; - Assert.Equal(0, item.Age); + try + { + var item = new Table(0, 12, "red"); + } + catch (Exception exc) + { + Assert.Equal("Value does not fall within the expected range.", exc.Message); + } } [Fact] - public void TestCorrectIncorrectSetAge() + public void TestCreateTableWithWrongHeigth() { - var item = new Platypus(); - item.Age = 10; - item.Age = -5; - Assert.Equal(10, item.Age); + try + { + var item = new Table(12, 0, "red"); + } + catch (Exception exc) + { + Assert.Equal("Value does not fall within the expected range.", exc.Message); + } + } + + [Fact] + public void TestCreateTableWithWrongColorNull() + { + try + { + var item = new Table(12, 12, null); + } + catch (Exception exc) + { + Assert.Equal("Value does not fall within the expected range.", exc.Message); + } + } + + [Fact] + public void TestCreateTableWithWrongColorEmpty() + { + try + { + var item = new Table(12, 12, string.Empty); + } + catch (Exception exc) + { + Assert.Equal("Value does not fall within the expected range.", exc.Message); + } } } } diff --git a/CourseApp/Platypus.cs b/CourseApp/Platypus.cs deleted file mode 100644 index eb3d463..0000000 --- a/CourseApp/Platypus.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; - -namespace CourseApp -{ - public class Platypus - { - private int age; - - public Platypus() - : this(0, "Untitled", true) - { - } - - public Platypus(int age, string name, bool isMale) - { - Name = name; - Age = age; - IsMale = isMale; - } - - public string Name { get; set; } - - public int Age - { - get - { - return this.age; - } - - set - { - if (value >= 0 && value < 20) - { - this.age = value; - } - else - { - Console.WriteLine("Age should be > 0 and < than 20"); - } - } - } - - public bool IsMale { get; set; } - - public bool IsPoisoned - { - get { return this.IsMale; } - } - - public string View() - { - return @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; - } - } -} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index e932330..bd59de4 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -63,8 +63,25 @@ public static void Main(string[] args) Console.WriteLine($"x={xB[i]} y={taskB[i]}"); } - var item = new Platypus(); - Console.WriteLine(item.View()); + List tables = new List
() + { + new Table(12, 12), + new Table(12, 12, "red") + }; + + for (int i = 0; i < tables.Count; i++) + { + Console.WriteLine(tables[i].ToString()); + } + + try + { + tables.Add(new Table(0, 12, null)); + } + catch (Exception exc) + { + Console.WriteLine(exc.Message); + } Console.ReadLine(); } diff --git a/CourseApp/Table.cs b/CourseApp/Table.cs new file mode 100644 index 0000000..3d3aca1 --- /dev/null +++ b/CourseApp/Table.cs @@ -0,0 +1,30 @@ +using System; + +namespace CourseApp +{ + public class Table + { + public Table(double weight, double height, string color = "black") + { + if (weight == 0 || height == 0 || string.IsNullOrEmpty(color)) + { + throw new ArgumentException(); + } + + Weigh = weight; + Height = height; + Color = color; + } + + public double Weigh { get; private set; } + + public double Height { get; private set; } + + public string Color { get; private set; } + + public override string ToString() + { + return "Weigh = " + Weigh + ", Height = " + Height + ", Color = " + Color; + } + } +} \ No newline at end of file From 097ac0c9b9248c6c207dbb093184bfddbda1a7b4 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 6 Jan 2020 11:24:37 +0300 Subject: [PATCH 3/8] add abstract class and chair class --- CourseApp/Chair.cs | 23 +++++++++++++++++++++++ CourseApp/Furniture.cs | 26 ++++++++++++++++++++++++++ CourseApp/Program.cs | 20 ++++++++++++++------ CourseApp/Table.cs | 23 ++++++++--------------- 4 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 CourseApp/Chair.cs create mode 100644 CourseApp/Furniture.cs diff --git a/CourseApp/Chair.cs b/CourseApp/Chair.cs new file mode 100644 index 0000000..276b287 --- /dev/null +++ b/CourseApp/Chair.cs @@ -0,0 +1,23 @@ +using System; + +namespace CourseApp +{ + public class Chair : Furniture + { + public Chair(double weight, double height, string color = "white", int countLegs = 4): base(weight, height, color) + { + CountLegs = countLegs; + } + + public double CountLegs { get; private set; } + + public override void Build() { + Console.WriteLine("Build chair."); + } + + public override string ToString() + { + return "Chair: Weigh = " + Weight + ", Height = " + Height + ", Color = " + Color + ", Count legs = " + CountLegs; + } + } +} \ No newline at end of file diff --git a/CourseApp/Furniture.cs b/CourseApp/Furniture.cs new file mode 100644 index 0000000..3162433 --- /dev/null +++ b/CourseApp/Furniture.cs @@ -0,0 +1,26 @@ +using System; + +namespace CourseApp +{ + public abstract class Furniture + { + public Furniture(double weight, double height, string color) + { + if (weight == 0 || height == 0 || string.IsNullOrEmpty(color)) + { + throw new ArgumentException(); + } + Weight = weight; + Height = height; + Color = color; + } + + public double Weight { get; private set; } + + public double Height { get; private set; } + + public string Color { get; private set; } + + public abstract void Build(); + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index bd59de4..a9b90ac 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -63,20 +63,28 @@ public static void Main(string[] args) Console.WriteLine($"x={xB[i]} y={taskB[i]}"); } - List
tables = new List
() + Console.WriteLine("Table info:"); + + List furniture = new List() { - new Table(12, 12), - new Table(12, 12, "red") + new Table(500, 120), + new Table(400, 400, "red"), + new Chair(100, 100), + new Chair(120, 120, "yellow"), + new Chair(100, 100, "red", 4), + new Chair(120, 120, "yellow", 2), + new Table(400, 400, countLegs: 3), }; - for (int i = 0; i < tables.Count; i++) + for (int i = 0; i < furniture.Count; i++) { - Console.WriteLine(tables[i].ToString()); + furniture[i].Build(); + Console.WriteLine(furniture[i].ToString()); } try { - tables.Add(new Table(0, 12, null)); + furniture.Add(new Table(0, 12, null)); } catch (Exception exc) { diff --git a/CourseApp/Table.cs b/CourseApp/Table.cs index 3d3aca1..857b789 100644 --- a/CourseApp/Table.cs +++ b/CourseApp/Table.cs @@ -2,29 +2,22 @@ namespace CourseApp { - public class Table + public class Table : Furniture { - public Table(double weight, double height, string color = "black") + public Table(double weight, double height, string color = "black", int countLegs = 4): base(weight, height, color) { - if (weight == 0 || height == 0 || string.IsNullOrEmpty(color)) - { - throw new ArgumentException(); - } - - Weigh = weight; - Height = height; - Color = color; + CountLegs = countLegs; } - public double Weigh { get; private set; } - - public double Height { get; private set; } + public double CountLegs { get; private set; } - public string Color { get; private set; } + public override void Build() { + Console.WriteLine("Build table."); + } public override string ToString() { - return "Weigh = " + Weigh + ", Height = " + Height + ", Color = " + Color; + return "Table: Weigh = " + Weight + ", Height = " + Height + ", Color = " + Color + ", Count legs = " + CountLegs; } } } \ No newline at end of file From 1a99710b837a6ccc6df45232710379d91bc4e688 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 6 Jan 2020 15:21:04 +0300 Subject: [PATCH 4/8] updated tests --- CourseApp.Tests/PlatypusTest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs index 5d667ab..0d7be01 100644 --- a/CourseApp.Tests/PlatypusTest.cs +++ b/CourseApp.Tests/PlatypusTest.cs @@ -9,7 +9,7 @@ public class PlatypusTest public void TestCreateTable() { var item = new Table(12, 13, "white"); - Assert.Equal(12, item.Weigh); + Assert.Equal(12, item.Weight); Assert.Equal(13, item.Height); Assert.Equal("white", item.Color); } @@ -18,7 +18,7 @@ public void TestCreateTable() public void TestCreateTableWithoutColor() { var item = new Table(12, 13); - Assert.Equal(12, item.Weigh); + Assert.Equal(12, item.Weight); Assert.Equal(13, item.Height); Assert.Equal("black", item.Color); } @@ -26,7 +26,7 @@ public void TestCreateTableWithoutColor() [Fact] public void TestGetToString() { - var ecString = "Weigh = 12, Height = 12, Color = red"; + var ecString = "Weight = 12, Height = 12, Color = red"; var item = new Table(12, 12, "red"); Assert.Equal(ecString, item.ToString()); } From 5e7df773f7c0b4002793b03f6eec24a5217d52e2 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 6 Jan 2020 15:25:28 +0300 Subject: [PATCH 5/8] fixed line in test --- CourseApp.Tests/PlatypusTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs index 0d7be01..199b94c 100644 --- a/CourseApp.Tests/PlatypusTest.cs +++ b/CourseApp.Tests/PlatypusTest.cs @@ -26,7 +26,7 @@ public void TestCreateTableWithoutColor() [Fact] public void TestGetToString() { - var ecString = "Weight = 12, Height = 12, Color = red"; + var ecString = "Table: Weigh = 400, Height = 400, Color = red, Count legs = 4"; var item = new Table(12, 12, "red"); Assert.Equal(ecString, item.ToString()); } From 89df6b43691cd1f652211b7a31cd0434b0921fbf Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 6 Jan 2020 15:28:48 +0300 Subject: [PATCH 6/8] fixed params in test --- CourseApp.Tests/PlatypusTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs index 199b94c..7a14ea9 100644 --- a/CourseApp.Tests/PlatypusTest.cs +++ b/CourseApp.Tests/PlatypusTest.cs @@ -27,7 +27,7 @@ public void TestCreateTableWithoutColor() public void TestGetToString() { var ecString = "Table: Weigh = 400, Height = 400, Color = red, Count legs = 4"; - var item = new Table(12, 12, "red"); + var item = new Table(400, 400, "red"); Assert.Equal(ecString, item.ToString()); } From 4ab9c06e74e04587eca79952da1a19f2f872a150 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 6 Jan 2020 18:18:17 +0300 Subject: [PATCH 7/8] revert abstract class --- CourseApp.Tests/PlatypusTest.cs | 4 ++-- CourseApp/Chair.cs | 23 ----------------------- CourseApp/Furniture.cs | 26 -------------------------- CourseApp/Program.cs | 20 ++++++-------------- CourseApp/Table.cs | 23 +++++++++++++++-------- 5 files changed, 23 insertions(+), 73 deletions(-) delete mode 100644 CourseApp/Chair.cs delete mode 100644 CourseApp/Furniture.cs diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs index 7a14ea9..cd9d907 100644 --- a/CourseApp.Tests/PlatypusTest.cs +++ b/CourseApp.Tests/PlatypusTest.cs @@ -9,7 +9,7 @@ public class PlatypusTest public void TestCreateTable() { var item = new Table(12, 13, "white"); - Assert.Equal(12, item.Weight); + Assert.Equal(12, item.Weigh); Assert.Equal(13, item.Height); Assert.Equal("white", item.Color); } @@ -18,7 +18,7 @@ public void TestCreateTable() public void TestCreateTableWithoutColor() { var item = new Table(12, 13); - Assert.Equal(12, item.Weight); + Assert.Equal(12, item.Weigh); Assert.Equal(13, item.Height); Assert.Equal("black", item.Color); } diff --git a/CourseApp/Chair.cs b/CourseApp/Chair.cs deleted file mode 100644 index 276b287..0000000 --- a/CourseApp/Chair.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace CourseApp -{ - public class Chair : Furniture - { - public Chair(double weight, double height, string color = "white", int countLegs = 4): base(weight, height, color) - { - CountLegs = countLegs; - } - - public double CountLegs { get; private set; } - - public override void Build() { - Console.WriteLine("Build chair."); - } - - public override string ToString() - { - return "Chair: Weigh = " + Weight + ", Height = " + Height + ", Color = " + Color + ", Count legs = " + CountLegs; - } - } -} \ No newline at end of file diff --git a/CourseApp/Furniture.cs b/CourseApp/Furniture.cs deleted file mode 100644 index 3162433..0000000 --- a/CourseApp/Furniture.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; - -namespace CourseApp -{ - public abstract class Furniture - { - public Furniture(double weight, double height, string color) - { - if (weight == 0 || height == 0 || string.IsNullOrEmpty(color)) - { - throw new ArgumentException(); - } - Weight = weight; - Height = height; - Color = color; - } - - public double Weight { get; private set; } - - public double Height { get; private set; } - - public string Color { get; private set; } - - public abstract void Build(); - } -} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index a9b90ac..bd59de4 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -63,28 +63,20 @@ public static void Main(string[] args) Console.WriteLine($"x={xB[i]} y={taskB[i]}"); } - Console.WriteLine("Table info:"); - - List furniture = new List() + List
tables = new List
() { - new Table(500, 120), - new Table(400, 400, "red"), - new Chair(100, 100), - new Chair(120, 120, "yellow"), - new Chair(100, 100, "red", 4), - new Chair(120, 120, "yellow", 2), - new Table(400, 400, countLegs: 3), + new Table(12, 12), + new Table(12, 12, "red") }; - for (int i = 0; i < furniture.Count; i++) + for (int i = 0; i < tables.Count; i++) { - furniture[i].Build(); - Console.WriteLine(furniture[i].ToString()); + Console.WriteLine(tables[i].ToString()); } try { - furniture.Add(new Table(0, 12, null)); + tables.Add(new Table(0, 12, null)); } catch (Exception exc) { diff --git a/CourseApp/Table.cs b/CourseApp/Table.cs index 857b789..3d3aca1 100644 --- a/CourseApp/Table.cs +++ b/CourseApp/Table.cs @@ -2,22 +2,29 @@ namespace CourseApp { - public class Table : Furniture + public class Table { - public Table(double weight, double height, string color = "black", int countLegs = 4): base(weight, height, color) + public Table(double weight, double height, string color = "black") { - CountLegs = countLegs; + if (weight == 0 || height == 0 || string.IsNullOrEmpty(color)) + { + throw new ArgumentException(); + } + + Weigh = weight; + Height = height; + Color = color; } - public double CountLegs { get; private set; } + public double Weigh { get; private set; } - public override void Build() { - Console.WriteLine("Build table."); - } + public double Height { get; private set; } + + public string Color { get; private set; } public override string ToString() { - return "Table: Weigh = " + Weight + ", Height = " + Height + ", Color = " + Color + ", Count legs = " + CountLegs; + return "Weigh = " + Weigh + ", Height = " + Height + ", Color = " + Color; } } } \ No newline at end of file From 14f5496a927b3d2e6840ca7d38684d22d239b4b8 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 6 Jan 2020 18:23:43 +0300 Subject: [PATCH 8/8] updated tests --- CourseApp.Tests/PlatypusTest.cs | 8 ++++---- CourseApp/Table.cs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs index cd9d907..b3a28ab 100644 --- a/CourseApp.Tests/PlatypusTest.cs +++ b/CourseApp.Tests/PlatypusTest.cs @@ -9,7 +9,7 @@ public class PlatypusTest public void TestCreateTable() { var item = new Table(12, 13, "white"); - Assert.Equal(12, item.Weigh); + Assert.Equal(12, item.Weight); Assert.Equal(13, item.Height); Assert.Equal("white", item.Color); } @@ -18,7 +18,7 @@ public void TestCreateTable() public void TestCreateTableWithoutColor() { var item = new Table(12, 13); - Assert.Equal(12, item.Weigh); + Assert.Equal(12, item.Weight); Assert.Equal(13, item.Height); Assert.Equal("black", item.Color); } @@ -26,8 +26,8 @@ public void TestCreateTableWithoutColor() [Fact] public void TestGetToString() { - var ecString = "Table: Weigh = 400, Height = 400, Color = red, Count legs = 4"; - var item = new Table(400, 400, "red"); + var ecString = "Weight = 400, Height = 400, Color = black"; + var item = new Table(400, 400, "black"); Assert.Equal(ecString, item.ToString()); } diff --git a/CourseApp/Table.cs b/CourseApp/Table.cs index 3d3aca1..fd6ca19 100644 --- a/CourseApp/Table.cs +++ b/CourseApp/Table.cs @@ -11,12 +11,12 @@ public Table(double weight, double height, string color = "black") throw new ArgumentException(); } - Weigh = weight; + Weight = weight; Height = height; Color = color; } - public double Weigh { get; private set; } + public double Weight { get; private set; } public double Height { get; private set; } @@ -24,7 +24,7 @@ public Table(double weight, double height, string color = "black") public override string ToString() { - return "Weigh = " + Weigh + ", Height = " + Height + ", Color = " + Color; + return "Weight = " + Weight + ", Height = " + Height + ", Color = " + Color; } } } \ No newline at end of file