From 62b5d9ec96a03500857576f39c0a2aabe5aa348f Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 7 Nov 2019 09:14:46 +0300 Subject: [PATCH 01/11] Added class task example, added vscode conf --- .gitignore | 1 - CourseApp.Tests/PlatypusTest.cs | 55 ++++++++++++++++++++++++++++++ CourseApp/.vscode/launch.json | 25 ++++++++++++++ CourseApp/.vscode/tasks.json | 42 +++++++++++++++++++++++ CourseApp/Platypus.cs | 60 +++++++++++++++++++++++++++++++++ CourseApp/Program.cs | 3 ++ 6 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 CourseApp.Tests/PlatypusTest.cs create mode 100644 CourseApp/.vscode/launch.json create mode 100644 CourseApp/.vscode/tasks.json create mode 100644 CourseApp/Platypus.cs diff --git a/.gitignore b/.gitignore index 35d4ccd6..24cb4403 100644 --- a/.gitignore +++ b/.gitignore @@ -198,7 +198,6 @@ $RECYCLE.BIN/ **/node_modules/* # Added by Jskonst -.vscode/ Properties/ ##### diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs new file mode 100644 index 00000000..77c4d8fa --- /dev/null +++ b/CourseApp.Tests/PlatypusTest.cs @@ -0,0 +1,55 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class PlatypusTest + { + [Fact] + public void TestEmptyConstructor() + { + var item = new Platypus(); + Assert.Equal(0, item.Age); + Assert.Equal("Untitled", item.Name); + Assert.True(item.IsMale); + } + + [Fact] + public void TestView() + { + var item = new Platypus(); + var view = @" + _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, + ______,' -o :. _ . ; ,'`, `. +( -\.._,.;;'._ ,( } _`_-_,, `, `, + ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' + "; + Assert.Equal(view, item.View()); + } + + [Fact] + public void TestSetAge() + { + var item = new Platypus(); + item.Age = 5; + Assert.Equal(5, item.Age); + } + + [Fact] + public void TestIncorrectSetAge() + { + var item = new Platypus(); + item.Age = -5; + Assert.Equal(0, item.Age); + } + + [Fact] + public void TestCorrectIncorrectSetAge() + { + var item = new Platypus(); + item.Age = 10; + item.Age = -5; + Assert.Equal(10, item.Age); + } + } +} diff --git a/CourseApp/.vscode/launch.json b/CourseApp/.vscode/launch.json new file mode 100644 index 00000000..208ea3ac --- /dev/null +++ b/CourseApp/.vscode/launch.json @@ -0,0 +1,25 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/CourseApp.dll", + "args": [], + "cwd": "${workspaceFolder}", + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/CourseApp/.vscode/tasks.json b/CourseApp/.vscode/tasks.json new file mode 100644 index 00000000..f8c71cd5 --- /dev/null +++ b/CourseApp/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/CourseApp.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/CourseApp.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/CourseApp.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/CourseApp/Platypus.cs b/CourseApp/Platypus.cs new file mode 100644 index 00000000..eb3d4634 --- /dev/null +++ b/CourseApp/Platypus.cs @@ -0,0 +1,60 @@ +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 e8878818..a43396c0 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -61,6 +61,9 @@ public static void Main(string[] args) Console.WriteLine($"x={xB[i]} y={taskB[i]}"); } + var item = new Platypus(); + Console.WriteLine(item.View()); + Console.ReadLine(); } } From f09247fe8984eec8efc16e62fc3584ee523d1300 Mon Sep 17 00:00:00 2001 From: Marija_Popova Date: Fri, 29 Nov 2019 12:19:05 +0300 Subject: [PATCH 02/11] first version tasks --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/DemoTest.cs | 43 ++++++++++------- CourseApp/CourseApp.csproj | 2 +- CourseApp/Program.cs | 64 ++++++++++---------------- 4 files changed, 54 insertions(+), 57 deletions(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a6..b5e64b9a 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp3.0 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index bd31c5ca..d4241f2b 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -5,31 +5,42 @@ namespace CourseApp.Tests { public class DemoTest { - [Theory] - [InlineData(0, 0, 0, double.NaN)] - [InlineData(1, 1, 2, 2.5)] - [InlineData(-1, 1, 1, 0)] - public void TestCalc(double a, double b, double x, double exp) - { - var res = Program.MyFunction(a, b, x); - Assert.Equal(exp, res, 3); - } - [Fact] - public void TestNormalA() + public void TestTaskBNullMass() { + double[] e = new double[0]; + var res = Program.TaskB(2.0, e); + Assert.Equal(res, new double[0]); } [Fact] - public void TestNormalB() + public void TaskBWork() { + var arr = new double[] { 1.02, 1.21, 1.5, 2.3, 2.71 }; + var resB = Program.TaskB(2.0, arr); + var exp = new double[] { 0.02526278072091896, 0.02489759880547166, 0.024164084643521107, 0.021702665452373534, 0.020418098612637083 }; + for (int i = 0; i < 5; i++) + { + Assert.Equal(resB[i], exp[i]); + } } - [Fact] - public void TestZeroLengthB() + [Theory] + [InlineData(2.0, 1.2, 4.2, 0.6)] + public void TaskAWork(double a, double xn, double xk, double dx) { - var res = Program.TaskB(1, 1, new double[0]); - Assert.Empty(res); + var resA = Program.TaskA(a, xn, xk, dx); + var result = new double[resA.Length]; + int j = 0; + + foreach (var item in resA) + { + result[j] = Math.Round(resA[j], 3); + j++; + } + + var exp = new double[] { 0.025, 0.023, 0.021, 0.02, 0.018 }; + Assert.Equal(result, exp); } } } diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index b244e479..1e655b8c 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp3.0 True 1573,1591,1701;1702;1705; diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index a43396c0..b3b9d829 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -4,40 +4,27 @@ namespace CourseApp { public class Program { - public static double MyFunction(double a, double b, double x) + public static double[] TaskA(double a, double xn, double xk, double dx) { - var c = (b * x) + (a / x); - return c; - } + int j = 0; + var y = new double[5]; - public static double[] TaskA ( - double a, - double b, - double xn, - double xk, - double dx) - { - var steps = (int)Math.Floor((xk - xn) / dx); - var y = new double[steps]; - var i = 0; - for (var x = xn; x < xk; x += dx) + for (var i = xn; i < xk; i += dx) { - y[i] = MyFunction(a, b, x); - i++; + y[j] = Math.Pow(Math.Log10(a + i), 2) / Math.Pow(a + i, 2); + j++; } return y; } - public static double[] TaskB ( - double a, - double b, - double[] x) + public static double[] TaskB(double a, double[] x) { var y = new double[x.Length]; - for (int i = 0; i < x.Length; i++) + + for (var i = 0; i < y.Length; i++) { - y[i] = MyFunction(a, b, x[i]); + y[i] = Math.Pow(Math.Log10(a + x[i]), 2) / Math.Pow(a + x[i], 2); } return y; @@ -45,26 +32,25 @@ public static double[] TaskB ( public static void Main(string[] args) { - Console.WriteLine("Hello World!"); - var taskA = TaskA(2, 3, 0, 5, 1); - Console.WriteLine(taskA); - - for (var i = 0; i < taskA.Length; i++) + const double a = 2.0; + const double xn = 1.2; + const double xk = 4.2; + const double dx = 0.6; + + var resultTaskA = TaskA(a, xn, xk, dx); + Console.WriteLine("Task A:"); + foreach (var item in resultTaskA) { - Console.WriteLine($"y={taskA[i]}"); + Console.WriteLine($"y = {item}"); } - var xB = new double[] { 0, 1, 2, 3 }; - var taskB = TaskB(2, 3, xB); - for (var i = 0; i < xB.Length; i++) + var x = new double[] { 1.16, 1.32, 1.47, 1.65, 1.93 }; + var resultTaskB = TaskB(a, x); + Console.WriteLine("Task B:"); + foreach (var item in resultTaskB) { - Console.WriteLine($"x={xB[i]} y={taskB[i]}"); + Console.WriteLine($"y = {item}"); } - - var item = new Platypus(); - Console.WriteLine(item.View()); - - Console.ReadLine(); } } -} +} \ No newline at end of file From fbf5a3a21b7595f6ff3ac0f3f5ca8b18dc7e00b7 Mon Sep 17 00:00:00 2001 From: Marija_Popova Date: Fri, 29 Nov 2019 12:24:30 +0300 Subject: [PATCH 03/11] fix netcore version --- 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 b5e64b9a..8fb7e4a6 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.0 + netcoreapp2.1 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 1e655b8c..b244e479 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.0 + netcoreapp2.1 True 1573,1591,1701;1702;1705; From 75ed82e28c2afa8e32a5fa460d5a3543d025cd08 Mon Sep 17 00:00:00 2001 From: Marija_Popova Date: Thu, 5 Dec 2019 16:10:11 +0300 Subject: [PATCH 04/11] Full 1 lab (with using collections) --- .github/workflows/dotnetcore.yml | 2 +- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/DemoTest.cs | 45 ++++++++++++++------------ CourseApp/CourseApp.csproj | 2 +- CourseApp/Program.cs | 35 +++++++++++--------- 5 files changed, 46 insertions(+), 40 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 22cc4ebc..502e5ced 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -12,7 +12,7 @@ jobs: - name: Setup .NET Core uses: actions/setup-dotnet@v1 with: - dotnet-version: 2.1.802 + dotnet-version: 3.0.100 - name: Build with dotnet run: | cd CourseApp diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a6..b5e64b9a 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp3.0 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index d4241f2b..b1edefa0 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Xunit; namespace CourseApp.Tests @@ -6,41 +7,43 @@ namespace CourseApp.Tests public class DemoTest { [Fact] - public void TestTaskBNullMass() + public void Test1() { - double[] e = new double[0]; - var res = Program.TaskB(2.0, e); - Assert.Equal(res, new double[0]); + Assert.True(true); + } + + [Fact] + public void TestNullMass() + { + var res = Program.MyFunction(0.0, 0.0); + Assert.Equal(double.PositiveInfinity, res); } [Fact] public void TaskBWork() { - var arr = new double[] { 1.02, 1.21, 1.5, 2.3, 2.71 }; - var resB = Program.TaskB(2.0, arr); - var exp = new double[] { 0.02526278072091896, 0.02489759880547166, 0.024164084643521107, 0.021702665452373534, 0.020418098612637083 }; + List arr = new List { 1.02, 1.21, 1.5, 2.3, 2.71 }; + List resB = Program.TaskB(2.0, arr); + List exp = new List { 0.02526278072091896, 0.02489759880547166, 0.024164084643521107, 0.021702665452373534, 0.020418098612637083 }; for (int i = 0; i < 5; i++) { - Assert.Equal(resB[i], exp[i]); + Assert.Equal(exp[i], resB[i], 3); } } - [Theory] - [InlineData(2.0, 1.2, 4.2, 0.6)] - public void TaskAWork(double a, double xn, double xk, double dx) + [Fact] + public void TaskAWork() { - var resA = Program.TaskA(a, xn, xk, dx); - var result = new double[resA.Length]; - int j = 0; - - foreach (var item in resA) + double a = 2.0; + double xn = 1.2; + double xk = 4.2; + double dx = 0.6; + List resA = Program.TaskA(a, xn, xk, dx); + List exp = new List { 0.025, 0.023, 0.021, 0.02, 0.018 }; + for (int i = 0; i < resA.Count; i++) { - result[j] = Math.Round(resA[j], 3); - j++; + Assert.Equal(exp[i], resA[i], 3); } - - var exp = new double[] { 0.025, 0.023, 0.021, 0.02, 0.018 }; - Assert.Equal(result, exp); } } } diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index b244e479..1e655b8c 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp3.0 True 1573,1591,1701;1702;1705; diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index b3b9d829..355a4e60 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,30 +1,34 @@ using System; +using System.Collections.Generic; namespace CourseApp { public class Program { - public static double[] TaskA(double a, double xn, double xk, double dx) + public static double MyFunction(double a, double x) { - int j = 0; - var y = new double[5]; + var y = Math.Pow(Math.Log10(a + x), 2) / Math.Pow(a + x, 2); + return y; + } - for (var i = xn; i < xk; i += dx) + public static List TaskA(double a, double xn, double xk, double dx) + { + List y = new List((int)((xk - xn) / dx)); + for (var x = xn; x < xk; x += dx) { - y[j] = Math.Pow(Math.Log10(a + i), 2) / Math.Pow(a + i, 2); - j++; + y.Add(MyFunction(a, x)); } return y; } - public static double[] TaskB(double a, double[] x) + public static List TaskB(double a, List x) { - var y = new double[x.Length]; + List y = new List(); - for (var i = 0; i < y.Length; i++) + for (var i = 0; i < x.Count; i++) { - y[i] = Math.Pow(Math.Log10(a + x[i]), 2) / Math.Pow(a + x[i], 2); + y.Add(MyFunction(a, x[i])); } return y; @@ -36,21 +40,20 @@ public static void Main(string[] args) const double xn = 1.2; const double xk = 4.2; const double dx = 0.6; - - var resultTaskA = TaskA(a, xn, xk, dx); Console.WriteLine("Task A:"); - foreach (var item in resultTaskA) + foreach (var item in TaskA(a, xn, xk, dx)) { Console.WriteLine($"y = {item}"); } - var x = new double[] { 1.16, 1.32, 1.47, 1.65, 1.93 }; - var resultTaskB = TaskB(a, x); + List x = new List { 1.16, 1.32, 1.47, 1.65, 1.93 }; Console.WriteLine("Task B:"); - foreach (var item in resultTaskB) + foreach (var item in TaskB(a, x)) { Console.WriteLine($"y = {item}"); } + + Console.ReadLine(); } } } \ No newline at end of file From 73032d99f1f617ab2b656f625010d7ed1e970570 Mon Sep 17 00:00:00 2001 From: Marija_Popova Date: Sun, 8 Dec 2019 18:15:44 +0300 Subject: [PATCH 05/11] added class --- CourseApp.Tests/MouseTest.cs | 51 ++++++++++++++++++++++++++ CourseApp.Tests/PlatypusTest.cs | 55 ----------------------------- CourseApp/{Platypus.cs => Mouse.cs} | 41 ++++++++++----------- CourseApp/Program.cs | 8 +++++ 4 files changed, 80 insertions(+), 75 deletions(-) create mode 100644 CourseApp.Tests/MouseTest.cs delete mode 100644 CourseApp.Tests/PlatypusTest.cs rename CourseApp/{Platypus.cs => Mouse.cs} (56%) diff --git a/CourseApp.Tests/MouseTest.cs b/CourseApp.Tests/MouseTest.cs new file mode 100644 index 00000000..9a21b333 --- /dev/null +++ b/CourseApp.Tests/MouseTest.cs @@ -0,0 +1,51 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class MouseTest + { + [Fact] + public void TestEmptyConstructor() + { + var item = new Mouse(); + Assert.Equal(0, item.Age); + Assert.Equal("Untitled", item.Name); + Assert.True(item.IsMale); + } + + [Fact] + public void TestConstructor() + { + var item = new Mouse("Rat", 2, false); + Assert.Equal(2, item.Age); + Assert.Equal("Rat", item.Name); + Assert.False(item.IsMale); + } + + [Fact] + public void TestSetAge() + { + var item = new Mouse(); + item.Age = 2; + Assert.Equal(2, item.Age); + } + + [Fact] + public void TestIncorrectSetAge() + { + var item = new Mouse(); + item.Age = -5; + Assert.Equal(0, item.Age); + } + + [Fact] + public void TestCorrectIncorrectSetAge() + { + var item = new Mouse(); + item.Age = 2; + item.Age = -5; + Assert.Equal(2, item.Age); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs deleted file mode 100644 index 77c4d8fa..00000000 --- a/CourseApp.Tests/PlatypusTest.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using Xunit; - -namespace CourseApp.Tests -{ - public class PlatypusTest - { - [Fact] - public void TestEmptyConstructor() - { - var item = new Platypus(); - Assert.Equal(0, item.Age); - Assert.Equal("Untitled", item.Name); - Assert.True(item.IsMale); - } - - [Fact] - public void TestView() - { - var item = new Platypus(); - var view = @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; - Assert.Equal(view, item.View()); - } - - [Fact] - public void TestSetAge() - { - var item = new Platypus(); - item.Age = 5; - Assert.Equal(5, item.Age); - } - - [Fact] - public void TestIncorrectSetAge() - { - var item = new Platypus(); - item.Age = -5; - Assert.Equal(0, item.Age); - } - - [Fact] - public void TestCorrectIncorrectSetAge() - { - var item = new Platypus(); - item.Age = 10; - item.Age = -5; - Assert.Equal(10, item.Age); - } - } -} diff --git a/CourseApp/Platypus.cs b/CourseApp/Mouse.cs similarity index 56% rename from CourseApp/Platypus.cs rename to CourseApp/Mouse.cs index eb3d4634..e78a3b6c 100644 --- a/CourseApp/Platypus.cs +++ b/CourseApp/Mouse.cs @@ -2,16 +2,26 @@ namespace CourseApp { - public class Platypus + public class Mouse { private int age; - public Platypus() - : this(0, "Untitled", true) + public Mouse() + : this("Untitled") { } - public Platypus(int age, string name, bool isMale) + public Mouse(string name) + : this(name, 0) + { + } + + public Mouse(string name, int age) + : this(name, age, true) + { + } + + public Mouse(string name, int age, bool isMale) { Name = name; Age = age; @@ -20,6 +30,8 @@ public Platypus(int age, string name, bool isMale) public string Name { get; set; } + public bool IsMale { get; set; } + public int Age { get @@ -29,32 +41,21 @@ public int Age set { - if (value >= 0 && value < 20) + if (value >= 0 && value < 3) { this.age = value; } else { - Console.WriteLine("Age should be > 0 and < than 20"); + Console.WriteLine("Age should be > 0 and < than 3"); } } } - public bool IsMale { get; set; } - - public bool IsPoisoned - { - get { return this.IsMale; } - } - - public string View() + public override string ToString() { - return @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; + string s = $"Piep piep. I am {Name}. I am {(IsMale ? "male" : "female")} {Age} years old."; + return s; } } } \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 355a4e60..6d4c9fe6 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -53,6 +53,14 @@ public static void Main(string[] args) Console.WriteLine($"y = {item}"); } + Mouse[] animal = new Mouse[2]; + animal[0] = new Mouse("Larisa", 1, false); + animal[1] = new Mouse("Karl", 2, true); + foreach (var item in animal) + { + Console.WriteLine(item); + } + Console.ReadLine(); } } From 7e9c06b18ae60c58caa97acd515ee781a646ca24 Mon Sep 17 00:00:00 2001 From: Marija_Popova Date: Sun, 15 Dec 2019 17:50:51 +0300 Subject: [PATCH 06/11] fixed --- CourseApp.Tests/DemoTest.cs | 7 +++++++ CourseApp.Tests/MouseTest.cs | 16 +++++++++++----- CourseApp/Mouse.cs | 2 +- CourseApp/Program.cs | 17 ++++++++++++----- CourseApp/README.md | 2 -- 5 files changed, 31 insertions(+), 13 deletions(-) delete mode 100644 CourseApp/README.md diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index b1edefa0..8dbd86d4 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -45,5 +45,12 @@ public void TaskAWork() Assert.Equal(exp[i], resA[i], 3); } } + + [Fact] + public void XnMoreThanXkAndUncorrectDx() + { + List res = Program.TaskA(2.0, 4.2, 1.2, 0.7); + Assert.Equal(res, new List()); + } } } diff --git a/CourseApp.Tests/MouseTest.cs b/CourseApp.Tests/MouseTest.cs index 9a21b333..04410e6c 100644 --- a/CourseApp.Tests/MouseTest.cs +++ b/CourseApp.Tests/MouseTest.cs @@ -34,18 +34,24 @@ public void TestSetAge() [Fact] public void TestIncorrectSetAge() { + try + { var item = new Mouse(); item.Age = -5; - Assert.Equal(0, item.Age); + } + catch (System.Exception) + { + Console.WriteLine("Age should be > 0 and < than 3"); + Assert.True(true); + } } [Fact] - public void TestCorrectIncorrectSetAge() + public void TestIncorrectSetString() { var item = new Mouse(); - item.Age = 2; - item.Age = -5; - Assert.Equal(2, item.Age); + item.Name = string.Empty; + Assert.Equal(string.Empty, item.Name); } } } \ No newline at end of file diff --git a/CourseApp/Mouse.cs b/CourseApp/Mouse.cs index e78a3b6c..cd5f43f5 100644 --- a/CourseApp/Mouse.cs +++ b/CourseApp/Mouse.cs @@ -47,7 +47,7 @@ public int Age } else { - Console.WriteLine("Age should be > 0 and < than 3"); + throw new System.Exception("Age should be > 0 and < than 3"); } } } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 6d4c9fe6..7537b290 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -13,13 +13,20 @@ public static double MyFunction(double a, double x) public static List TaskA(double a, double xn, double xk, double dx) { - List y = new List((int)((xk - xn) / dx)); - for (var x = xn; x < xk; x += dx) + if (xk < xn) { - y.Add(MyFunction(a, x)); + return new List(); } + else + { + List y = new List((int)((xk - xn) / dx)); + for (var x = xn; x < xk; x += dx) + { + y.Add(MyFunction(a, x)); + } - return y; + return y; + } } public static List TaskB(double a, List x) @@ -55,7 +62,7 @@ public static void Main(string[] args) Mouse[] animal = new Mouse[2]; animal[0] = new Mouse("Larisa", 1, false); - animal[1] = new Mouse("Karl", 2, true); + animal[1] = new Mouse("Konstantin", 2, true); foreach (var item in animal) { Console.WriteLine(item); diff --git a/CourseApp/README.md b/CourseApp/README.md deleted file mode 100644 index 2f4c1b50..00000000 --- a/CourseApp/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# Tprogramming_147_2019 -Попова Мария Вячеславовна From d9562b512957d5d1021044df9fbdd0fc53d1e9ba Mon Sep 17 00:00:00 2001 From: Marija_Popova Date: Tue, 17 Dec 2019 17:39:22 +0300 Subject: [PATCH 07/11] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=80=D1=84=D0=B8=D0=B7=D0=BC=20=D0=B8=20=D0=BD=D0=B0=D1=81?= =?UTF-8?q?=D0=BB=D0=B5=D0=B4=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp.Tests/AnimalsTest.cs | 77 ++++++++++++++++++++++++++++++++++ CourseApp.Tests/MouseTest.cs | 57 ------------------------- CourseApp/Animal.cs | 55 ++++++++++++++++++++++++ CourseApp/Cat.cs | 62 +++++++++++++++++++++++++++ CourseApp/Mouse.cs | 27 +++++++----- CourseApp/Program.cs | 14 ++++--- 6 files changed, 220 insertions(+), 72 deletions(-) create mode 100644 CourseApp.Tests/AnimalsTest.cs delete mode 100644 CourseApp.Tests/MouseTest.cs create mode 100644 CourseApp/Animal.cs create mode 100644 CourseApp/Cat.cs diff --git a/CourseApp.Tests/AnimalsTest.cs b/CourseApp.Tests/AnimalsTest.cs new file mode 100644 index 00000000..8a9c4a8d --- /dev/null +++ b/CourseApp.Tests/AnimalsTest.cs @@ -0,0 +1,77 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class AnimalsTest + { + [Fact] + public void TestConstructorMouse() + { + var item = new Mouse(); + Assert.Equal(1, item.Age); + Assert.Equal("Неизвестно", item.Name); + Assert.True(item.IsMale); + Assert.False(item.Aggression); + } + + [Fact] + public void TestConstructorCat() + { + var item = new Cat(); + Assert.Equal(1, item.Age); + Assert.Equal("Неизвестно", item.Name); + Assert.True(item.Brood); + Assert.False(item.IsMale); + } + + [Fact] + public void TestSetAgeCat() + { + var item = new Cat(); + item.Age = 9; + Assert.Equal(9, item.Age); + } + + [Fact] + public void TestSetAgeMouse() + { + var item = new Mouse(); + item.Age = 2; + Assert.Equal(2, item.Age); + } + + [Fact] + public void TestIncorrectSetAgeCat() + { + try + { + var item = new Mouse(); + item.Age = -1000; + } + catch (System.Exception) + { + Console.WriteLine("Age should be > 0 and < than 3"); + Assert.True(true); + } + } + + [Fact] + public void TestCorrectIncorrectSetAge() + { + var item = new Cat(); + item.Age = 7; + try + { + item.Age = -1; + } + catch + { + Assert.Equal(7, item.Age); + return; + } + + Assert.Equal(7, item.Age); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/MouseTest.cs b/CourseApp.Tests/MouseTest.cs deleted file mode 100644 index 04410e6c..00000000 --- a/CourseApp.Tests/MouseTest.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using Xunit; - -namespace CourseApp.Tests -{ - public class MouseTest - { - [Fact] - public void TestEmptyConstructor() - { - var item = new Mouse(); - Assert.Equal(0, item.Age); - Assert.Equal("Untitled", item.Name); - Assert.True(item.IsMale); - } - - [Fact] - public void TestConstructor() - { - var item = new Mouse("Rat", 2, false); - Assert.Equal(2, item.Age); - Assert.Equal("Rat", item.Name); - Assert.False(item.IsMale); - } - - [Fact] - public void TestSetAge() - { - var item = new Mouse(); - item.Age = 2; - Assert.Equal(2, item.Age); - } - - [Fact] - public void TestIncorrectSetAge() - { - try - { - var item = new Mouse(); - item.Age = -5; - } - catch (System.Exception) - { - Console.WriteLine("Age should be > 0 and < than 3"); - Assert.True(true); - } - } - - [Fact] - public void TestIncorrectSetString() - { - var item = new Mouse(); - item.Name = string.Empty; - Assert.Equal(string.Empty, item.Name); - } - } -} \ No newline at end of file diff --git a/CourseApp/Animal.cs b/CourseApp/Animal.cs new file mode 100644 index 00000000..f859af6f --- /dev/null +++ b/CourseApp/Animal.cs @@ -0,0 +1,55 @@ +using System; + +namespace CourseApp +{ + public abstract class Animal + { + private int age; + + public Animal() + : this("Неизвестно") + { + } + + public Animal(string name) + : this(name, 0) + { + } + + public Animal(string name, int age) + : this(name, age, true) + { + } + + public Animal(string name, int age, bool isMale) + { + Name = name; + Age = age; + IsMale = isMale; + } + + public virtual int Age + { + get + { + return this.age; + } + + set + { + this.age = value; + } + } + + public string Name { get; set; } + + public bool IsMale { get; set; } + + public override string ToString() + { + return $"Имя:{Name},Возраст:{Age}"; + } + + public abstract string Voice(); + } +} \ No newline at end of file diff --git a/CourseApp/Cat.cs b/CourseApp/Cat.cs new file mode 100644 index 00000000..6daf2a93 --- /dev/null +++ b/CourseApp/Cat.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CourseApp +{ + public class Cat : Animal + { + public Cat() + : this("Неизвестно") + { + } + + public Cat(string name) + : this(name, 1) + { + } + + public Cat(string name, int age) + : this(name, age, false) + { + } + + public Cat(string name, int age, bool isMale) + : this(name, age, isMale, true) + { + } + + public Cat(string name, int age, bool isMale, bool brood) + : base(name, age, isMale) + { + this.Brood = brood; + } + + public override int Age + { + set + { + if (value >= 0 && value < 16) + { + base.Age = value; + } + else + { + throw new System.Exception("Age should be more 0 and less than 16"); + } + } + } + + public bool Brood { get; set; } + + public override string ToString() + { + return $"I am {(Brood ? "thoroughbred" : "mongrel")} {Name}. I am {(IsMale ? "male" : "female")} {Age} years old."; + } + + public override string Voice() + { + return "Meow"; + } + } +} \ No newline at end of file diff --git a/CourseApp/Mouse.cs b/CourseApp/Mouse.cs index cd5f43f5..0bc56c05 100644 --- a/CourseApp/Mouse.cs +++ b/CourseApp/Mouse.cs @@ -2,17 +2,17 @@ namespace CourseApp { - public class Mouse + public class Mouse : Animal { private int age; public Mouse() - : this("Untitled") + : this("Неизвестно") { } public Mouse(string name) - : this(name, 0) + : this(name, 1) { } @@ -22,17 +22,19 @@ public Mouse(string name, int age) } public Mouse(string name, int age, bool isMale) + : this(name, age, isMale, false) { - Name = name; - Age = age; - IsMale = isMale; } - public string Name { get; set; } + public Mouse(string name, int age, bool isMale, bool aggression) + : base(name, age, isMale) + { + this.Aggression = aggression; + } - public bool IsMale { get; set; } + public bool Aggression { get; set; } - public int Age + public override int Age { get { @@ -54,8 +56,13 @@ public int Age public override string ToString() { - string s = $"Piep piep. I am {Name}. I am {(IsMale ? "male" : "female")} {Age} years old."; + string s = $"I am {(Aggression ? "aggression" : "friendly")} {Name}. I am {(IsMale ? "male" : "female")} {Age} years old."; return s; } + + public override string Voice() + { + return "Piep, piep"; + } } } \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 7537b290..afa38911 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -60,12 +60,16 @@ public static void Main(string[] args) Console.WriteLine($"y = {item}"); } - Mouse[] animal = new Mouse[2]; - animal[0] = new Mouse("Larisa", 1, false); - animal[1] = new Mouse("Konstantin", 2, true); - foreach (var item in animal) + Console.WriteLine(); + + Animal[] masss = new Animal[2]; + masss[0] = new Mouse("Larisa", 2, false, true); + masss[1] = new Cat("Kyza", 7, true, true); + foreach (var item in masss) { - Console.WriteLine(item); + Console.WriteLine(item.ToString()); + Console.WriteLine(item.Voice()); + Console.WriteLine(); } Console.ReadLine(); From 9e5317df2d86dc9b49544890498b8523e98a4633 Mon Sep 17 00:00:00 2001 From: Marija_Popova Date: Tue, 17 Dec 2019 17:55:06 +0300 Subject: [PATCH 08/11] fix tests --- CourseApp/Animal.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CourseApp/Animal.cs b/CourseApp/Animal.cs index f859af6f..863c07e6 100644 --- a/CourseApp/Animal.cs +++ b/CourseApp/Animal.cs @@ -23,9 +23,9 @@ public Animal(string name, int age) public Animal(string name, int age, bool isMale) { - Name = name; - Age = age; - IsMale = isMale; + this.Name = name; + this.Age = age; + this.IsMale = isMale; } public virtual int Age From 8300afde3fd3b5e7e30b714ae9d93dcd3db608a2 Mon Sep 17 00:00:00 2001 From: ivinoiz <55226166+ivinoiz@users.noreply.github.com> Date: Tue, 17 Dec 2019 18:00:57 +0300 Subject: [PATCH 09/11] Delete MouseTest.cs --- CourseApp.Tests/MouseTest.cs | 57 ------------------------------------ 1 file changed, 57 deletions(-) delete mode 100644 CourseApp.Tests/MouseTest.cs diff --git a/CourseApp.Tests/MouseTest.cs b/CourseApp.Tests/MouseTest.cs deleted file mode 100644 index 04410e6c..00000000 --- a/CourseApp.Tests/MouseTest.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using Xunit; - -namespace CourseApp.Tests -{ - public class MouseTest - { - [Fact] - public void TestEmptyConstructor() - { - var item = new Mouse(); - Assert.Equal(0, item.Age); - Assert.Equal("Untitled", item.Name); - Assert.True(item.IsMale); - } - - [Fact] - public void TestConstructor() - { - var item = new Mouse("Rat", 2, false); - Assert.Equal(2, item.Age); - Assert.Equal("Rat", item.Name); - Assert.False(item.IsMale); - } - - [Fact] - public void TestSetAge() - { - var item = new Mouse(); - item.Age = 2; - Assert.Equal(2, item.Age); - } - - [Fact] - public void TestIncorrectSetAge() - { - try - { - var item = new Mouse(); - item.Age = -5; - } - catch (System.Exception) - { - Console.WriteLine("Age should be > 0 and < than 3"); - Assert.True(true); - } - } - - [Fact] - public void TestIncorrectSetString() - { - var item = new Mouse(); - item.Name = string.Empty; - Assert.Equal(string.Empty, item.Name); - } - } -} \ No newline at end of file From d60fd9f0c09aae28298a342b274c640005d4db03 Mon Sep 17 00:00:00 2001 From: Marija_Popova Date: Wed, 17 Jun 2020 16:24:31 +0300 Subject: [PATCH 10/11] plus interfaces --- CourseApp.Tests/InterfaceTests.cs | 28 ++++++++++++++++++++++++++++ CourseApp/Animal.cs | 13 +++++++++---- CourseApp/Cat.cs | 4 +++- CourseApp/IFacts.cs | 7 +++++++ CourseApp/Program.cs | 22 +++++++++++++++++----- 5 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 CourseApp.Tests/InterfaceTests.cs create mode 100644 CourseApp/IFacts.cs diff --git a/CourseApp.Tests/InterfaceTests.cs b/CourseApp.Tests/InterfaceTests.cs new file mode 100644 index 00000000..3445f4f8 --- /dev/null +++ b/CourseApp.Tests/InterfaceTests.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using Xunit; + +namespace CourseApp.Tests +{ + public class InterfaceTests + { + [Fact] + public void Test1() + { + Assert.True(true); + } + + [Fact] + public void IComparable() + { + Animal[] mass = new Animal[3]; + mass[0] = new Cat("Name1", 6, true, true); + mass[1] = new Mouse("Name2", 1, false, true); + mass[2] = new Cat("Name3", 3, false, true); + Array.Sort(mass); + Assert.Equal("Name2", mass[0].Name); + Assert.Equal("Name3", mass[1].Name); + Assert.Equal("Name1", mass[2].Name); + } + } +} \ No newline at end of file diff --git a/CourseApp/Animal.cs b/CourseApp/Animal.cs index 863c07e6..617d313c 100644 --- a/CourseApp/Animal.cs +++ b/CourseApp/Animal.cs @@ -2,7 +2,7 @@ namespace CourseApp { - public abstract class Animal + public abstract class Animal : IComparable { private int age; @@ -23,9 +23,9 @@ public Animal(string name, int age) public Animal(string name, int age, bool isMale) { - this.Name = name; - this.Age = age; - this.IsMale = isMale; + Name = name; + Age = age; + IsMale = isMale; } public virtual int Age @@ -51,5 +51,10 @@ public override string ToString() } public abstract string Voice(); + + public int CompareTo(Animal an) + { + return this.Age.CompareTo(an.Age); + } } } \ No newline at end of file diff --git a/CourseApp/Cat.cs b/CourseApp/Cat.cs index 6daf2a93..6425eaec 100644 --- a/CourseApp/Cat.cs +++ b/CourseApp/Cat.cs @@ -4,7 +4,7 @@ namespace CourseApp { - public class Cat : Animal + public class Cat : Animal, IFacts { public Cat() : this("Неизвестно") @@ -58,5 +58,7 @@ public override string Voice() { return "Meow"; } + + void IFacts.Facts() => Console.WriteLine("Сердце кошки бьется около 140 ударов в минуту.\nМяуканьем кошки пытаются обратить внимание человека.\n Усы, необходимы кошке для перемещения в пространстве."); } } \ No newline at end of file diff --git a/CourseApp/IFacts.cs b/CourseApp/IFacts.cs new file mode 100644 index 00000000..3354caf9 --- /dev/null +++ b/CourseApp/IFacts.cs @@ -0,0 +1,7 @@ +namespace CourseApp +{ + public interface IFacts + { + void Facts(); + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index afa38911..130676af 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -7,8 +7,8 @@ public class Program { public static double MyFunction(double a, double x) { - var y = Math.Pow(Math.Log10(a + x), 2) / Math.Pow(a + x, 2); - return y; + var y = Math.Pow(Math.Log10(a + x), 2) / Math.Pow(a + x, 2); + return y; } public static List TaskA(double a, double xn, double xk, double dx) @@ -62,9 +62,10 @@ public static void Main(string[] args) Console.WriteLine(); - Animal[] masss = new Animal[2]; - masss[0] = new Mouse("Larisa", 2, false, true); - masss[1] = new Cat("Kyza", 7, true, true); + Animal[] masss = new Animal[3]; + masss[0] = new Cat("Kyza", 7, true, true); + masss[1] = new Mouse("Larisa", 2, false, true); + masss[2] = new Cat("Murzik", 4, true, false); foreach (var item in masss) { Console.WriteLine(item.ToString()); @@ -72,6 +73,17 @@ public static void Main(string[] args) Console.WriteLine(); } + Array.Sort(masss); + Console.WriteLine("Отсортированный по возрасту массив:"); + foreach (Animal an in masss) + { + Console.WriteLine($"{an.Name} - {an.Age}"); + } + + Console.WriteLine("================================"); + + IFacts barsik = new Cat("Barsik", 5, true, true); + barsik.Facts(); Console.ReadLine(); } } From d9a3d7715cd3e145fc85de0ab764eb59a35dc6e3 Mon Sep 17 00:00:00 2001 From: ivinoiz <55226166+ivinoiz@users.noreply.github.com> Date: Wed, 17 Jun 2020 16:34:08 +0300 Subject: [PATCH 11/11] Update Cat.cs --- CourseApp/Cat.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CourseApp/Cat.cs b/CourseApp/Cat.cs index fc71b2be..0c034d93 100644 --- a/CourseApp/Cat.cs +++ b/CourseApp/Cat.cs @@ -4,7 +4,6 @@ namespace CourseApp { - public class Cat : Animal, IFacts { public Cat() @@ -62,4 +61,4 @@ public override string Voice() void IFacts.Facts() => Console.WriteLine("Сердце кошки бьется около 140 ударов в минуту.\nМяуканьем кошки пытаются обратить внимание человека.\n Усы, необходимы кошке для перемещения в пространстве."); } -} \ No newline at end of file +}