From aeb27bc23b08cdf09d3f75540aef1d1c06e6c7f9 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 10 Oct 2019 09:39:40 +0300 Subject: [PATCH 01/18] Sample of 1st lab --- CourseApp/Program.cs | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 248bbe4..11e476f 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -4,9 +4,61 @@ namespace CourseApp { public class Program { + public static double MyFunction(double a, double b, double x) + { + var c = (b * x) + a; + return c; + } + + 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) + { + y[i] = MyFunction(a, b, x); + i++; + } + + return y; + } + + public static double[] TaskB ( + double a, + double b, + double[] x) + { + var y = new double[x.Length]; + for (int i = 0; i < x.Length; i++) + { + y[i] = MyFunction(a, b, x[i]); + } + + return y; + } + public static void Main(string[] args) { Console.WriteLine("Hello World!"); + var taskA = TaskA(2, 3, 0, 5, 1); + for (var i = 0; i < taskA.Length; i++) + { + Console.WriteLine($"y={taskA[i]}"); + } + + var xB = new double[] { 0, 1, 2, 3 }; + var taskB = TaskB(2, 3, xB); + for (var i = 0; i < xB.Length; i++) + { + Console.WriteLine($"x={xB[i]} y={taskB[i]}"); + } + Console.ReadLine(); } } From 02472201c8e437f910a9fcd8e11ad50403aae5fa Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 17 Oct 2019 09:32:31 +0300 Subject: [PATCH 02/18] Tests samples --- CourseApp.Tests/DemoTest.cs | 25 +++++++++++++++++++++++-- CourseApp/CourseApp.sln | 31 +++++++++++++++++++++++++++++++ CourseApp/Program.cs | 4 +++- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 CourseApp/CourseApp.sln diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index fdc46f5..bd31c5c 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -5,10 +5,31 @@ 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() + { + } + + [Fact] + public void TestNormalB() + { + } + [Fact] - public void Test1() + public void TestZeroLengthB() { - Assert.True(true); + var res = Program.TaskB(1, 1, new double[0]); + Assert.Empty(res); } } } diff --git a/CourseApp/CourseApp.sln b/CourseApp/CourseApp.sln new file mode 100644 index 0000000..3dac3f4 --- /dev/null +++ b/CourseApp/CourseApp.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.852 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp", "CourseApp.csproj", "{17CB0273-34D3-4D23-965F-FC4AD0A83D0F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp.Tests", "..\CourseApp.Tests\CourseApp.Tests.csproj", "{E0133767-62A2-4B4A-87A2-BD09BC775E0A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {17CB0273-34D3-4D23-965F-FC4AD0A83D0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17CB0273-34D3-4D23-965F-FC4AD0A83D0F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17CB0273-34D3-4D23-965F-FC4AD0A83D0F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17CB0273-34D3-4D23-965F-FC4AD0A83D0F}.Release|Any CPU.Build.0 = Release|Any CPU + {E0133767-62A2-4B4A-87A2-BD09BC775E0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0133767-62A2-4B4A-87A2-BD09BC775E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0133767-62A2-4B4A-87A2-BD09BC775E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0133767-62A2-4B4A-87A2-BD09BC775E0A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1849B280-B447-4D18-9764-F412B7768C4F} + EndGlobalSection +EndGlobal diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 11e476f..e887881 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -6,7 +6,7 @@ public class Program { public static double MyFunction(double a, double b, double x) { - var c = (b * x) + a; + var c = (b * x) + (a / x); return c; } @@ -47,6 +47,8 @@ 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++) { Console.WriteLine($"y={taskA[i]}"); From d514055c9f7c9797067e4a2a8d7c641baa08abe6 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 08:32:42 +0300 Subject: [PATCH 03/18] Added actions file --- .github/workflows/dotnetcore.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/dotnetcore.yml diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml new file mode 100644 index 0000000..9c411d0 --- /dev/null +++ b/.github/workflows/dotnetcore.yml @@ -0,0 +1,23 @@ +name: .NET Core + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 2.1.802 + - name: Build with dotnet + run: + cd CourseApp + dotnet build --configuration Release + - name: Run tests + run: + cd CourseApp.Tests + dotnet test From b29aa6068fc4563d806b34b69b12709aa396960b Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 08:37:06 +0300 Subject: [PATCH 04/18] Fixed run steps (#28) --- .github/workflows/dotnetcore.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index 9c411d0..a09addb 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -14,10 +14,10 @@ jobs: with: dotnet-version: 2.1.802 - name: Build with dotnet - run: + run: | cd CourseApp dotnet build --configuration Release - name: Run tests - run: + run: | cd CourseApp.Tests dotnet test From dbae387a93373aae5ee85254037203dd830c012b Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 09:25:23 +0300 Subject: [PATCH 05/18] Test actions on PR (#30) --- .github/workflows/dotnetcore.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml index a09addb..22cc4eb 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -1,6 +1,6 @@ name: .NET Core -on: [push] +on: [push, pull_request] jobs: build: From 953427ebb4df2222f1edbd3967812883ed4ecb0a Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 09:28:33 +0300 Subject: [PATCH 06/18] Added tests and sample A|B tasks --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 556d11d..b422454 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# Tprogramming_147_2019 \ No newline at end of file +# Tprogramming_147_2019 +Konstantinov Eugeny \ No newline at end of file From 62b5d9ec96a03500857576f39c0a2aabe5aa348f Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 7 Nov 2019 09:14:46 +0300 Subject: [PATCH 07/18] 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 35d4ccd..24cb440 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 0000000..77c4d8f --- /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 0000000..208ea3a --- /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 0000000..f8c71cd --- /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 0000000..eb3d463 --- /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 e887881..a43396c 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 dc366c9042207c2eaa8eb7bae8f571737d93fb73 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 18 Nov 2019 09:11:20 +0300 Subject: [PATCH 08/18] Function v1.0 --- CourseApp/{Program.cs => Function.cs} | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) rename CourseApp/{Program.cs => Function.cs} (72%) diff --git a/CourseApp/Program.cs b/CourseApp/Function.cs similarity index 72% rename from CourseApp/Program.cs rename to CourseApp/Function.cs index a43396c..d88386c 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Function.cs @@ -4,15 +4,13 @@ namespace CourseApp { public class Program { - public static double MyFunction(double a, double b, double x) + public static double MyFunction(double x) { - var c = (b * x) + (a / x); + var c = (Math.Pow(Math.Sin(x), 3) + Math.Pow(Math.Cos(x), 3)) * Math.Log10(x); return c; } public static double[] TaskA ( - double a, - double b, double xn, double xk, double dx) @@ -22,7 +20,7 @@ public static double[] TaskA ( var i = 0; for (var x = xn; x < xk; x += dx) { - y[i] = MyFunction(a, b, x); + y[i] = MyFunction(x); i++; } @@ -30,14 +28,12 @@ public static double[] TaskA ( } public static double[] TaskB ( - double a, - double b, double[] x) { var y = new double[x.Length]; for (int i = 0; i < x.Length; i++) { - y[i] = MyFunction(a, b, x[i]); + y[i] = MyFunction(x[i]); } return y; @@ -46,7 +42,7 @@ public static double[] TaskB ( public static void Main(string[] args) { Console.WriteLine("Hello World!"); - var taskA = TaskA(2, 3, 0, 5, 1); + var taskA = TaskA(0.11, 0.36, 0.05); Console.WriteLine(taskA); for (var i = 0; i < taskA.Length; i++) @@ -54,8 +50,8 @@ public static void Main(string[] args) Console.WriteLine($"y={taskA[i]}"); } - var xB = new double[] { 0, 1, 2, 3 }; - var taskB = TaskB(2, 3, xB); + var xB = new double[] { 0.2, 0.3, 0.38, 0.43, 0.57 }; + var taskB = TaskB(xB); for (var i = 0; i < xB.Length; i++) { Console.WriteLine($"x={xB[i]} y={taskB[i]}"); From 09e9cc00899e7e2a78158a34cee2134768251d8b Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 18 Nov 2019 09:13:04 +0300 Subject: [PATCH 09/18] Function v1.1 --- CourseApp/Function.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp/Function.cs b/CourseApp/Function.cs index d88386c..a2dd935 100644 --- a/CourseApp/Function.cs +++ b/CourseApp/Function.cs @@ -2,7 +2,7 @@ namespace CourseApp { - public class Program + public class Function { public static double MyFunction(double x) { From 370715c28eb55c076d3d657f541701cd7964cee4 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 18 Nov 2019 09:18:07 +0300 Subject: [PATCH 10/18] Update --- CourseApp.Tests/FunctionTest.cs | 0 README.md | 4 ---- 2 files changed, 4 deletions(-) create mode 100644 CourseApp.Tests/FunctionTest.cs diff --git a/CourseApp.Tests/FunctionTest.cs b/CourseApp.Tests/FunctionTest.cs new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md index 4446bda..502c081 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,2 @@ # Tprogramming_147_2019 -<<<<<<< HEAD Evgeniy Satyev -======= -Konstantinov Eugeny ->>>>>>> master From 7b7eeced5ceb7d4d3a28ec088e0f75379ba1fa32 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 18 Nov 2019 09:24:17 +0300 Subject: [PATCH 11/18] FunctionTest v1.0 --- CourseApp.Tests/FunctionTest.cs | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/CourseApp.Tests/FunctionTest.cs b/CourseApp.Tests/FunctionTest.cs index e69de29..9daf652 100644 --- a/CourseApp.Tests/FunctionTest.cs +++ b/CourseApp.Tests/FunctionTest.cs @@ -0,0 +1,35 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class FunctionTest + { + [Theory] + [InlineData( 0, 0, double.NaN)] + [InlineData( 1, 2, 2.5)] + [InlineData( -1, 1, 0)] + public void TestCalc(double x, double exp) + { + var res = Program.MyFunction(x); + Assert.Equal(exp, res, 1); + } + + [Fact] + public void TestNormalA() + { + } + + [Fact] + public void TestNormalB() + { + } + + [Fact] + public void TestZeroLengthB() + { + var res = Program.TaskB(new double[0]); + Assert.Empty(res); + } + } +} From dd98a0cc3899abfe4bc8e9ed31ab5783a0ec4637 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 2 Dec 2019 09:40:27 +0300 Subject: [PATCH 12/18] AddTests --- CourseApp.Tests/DemoTest.cs | 35 --------------------------------- CourseApp.Tests/FunctionTest.cs | 20 ++++++++++++++----- CourseApp/Function.cs | 2 ++ 3 files changed, 17 insertions(+), 40 deletions(-) delete mode 100644 CourseApp.Tests/DemoTest.cs diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs deleted file mode 100644 index bd31c5c..0000000 --- a/CourseApp.Tests/DemoTest.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using Xunit; - -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() - { - } - - [Fact] - public void TestNormalB() - { - } - - [Fact] - public void TestZeroLengthB() - { - var res = Program.TaskB(1, 1, new double[0]); - Assert.Empty(res); - } - } -} diff --git a/CourseApp.Tests/FunctionTest.cs b/CourseApp.Tests/FunctionTest.cs index 9daf652..92aa7ee 100644 --- a/CourseApp.Tests/FunctionTest.cs +++ b/CourseApp.Tests/FunctionTest.cs @@ -6,29 +6,39 @@ namespace CourseApp.Tests public class FunctionTest { [Theory] - [InlineData( 0, 0, double.NaN)] - [InlineData( 1, 2, 2.5)] - [InlineData( -1, 1, 0)] + [InlineData(0, double.NegativeInfinity)] + [InlineData(2, 0.2)] + [InlineData(1, 0)] public void TestCalc(double x, double exp) { - var res = Program.MyFunction(x); + var res = Function.MyFunction(x); Assert.Equal(exp, res, 1); } [Fact] public void TestNormalA() { + var action = Function.TaskA(0.11, 0.36, 0.05); + var s = new double[] { -0.942599174573112, -0.768989662415832, -0.640224062047432, -0.537938691770828, -0.453755045309719 }; + Assert.Equal(action[0], s[0], 3); } [Fact] public void TestNormalB() { + var x = new double[] { 0.2, 0.3, 0.38, 0.43, 0.57 }; + var actial = Function.TaskB(x); + var exp = new double[] { -0.663479953941618, -0.469395196867133, -0.357994574230452, -0.301819984896032, -0.184040925422074 }; + for (var i = 0; i < 5; i++) + { + Assert.Equal(exp[i], actial[i], 3); + } } [Fact] public void TestZeroLengthB() { - var res = Program.TaskB(new double[0]); + var res = Function.TaskB(new double[0]); Assert.Empty(res); } } diff --git a/CourseApp/Function.cs b/CourseApp/Function.cs index a2dd935..61f8797 100644 --- a/CourseApp/Function.cs +++ b/CourseApp/Function.cs @@ -7,6 +7,7 @@ public class Function public static double MyFunction(double x) { var c = (Math.Pow(Math.Sin(x), 3) + Math.Pow(Math.Cos(x), 3)) * Math.Log10(x); + Console.WriteLine(c); return c; } @@ -41,6 +42,7 @@ public static double[] TaskB ( public static void Main(string[] args) { + MyFunction(0); Console.WriteLine("Hello World!"); var taskA = TaskA(0.11, 0.36, 0.05); Console.WriteLine(taskA); From c88f2833bac658df7e01fb3d2df84c6bf196209e Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 2 Dec 2019 12:33:12 +0300 Subject: [PATCH 13/18] AddClass --- CourseApp/Function.cs | 3 -- CourseApp/Pistol.cs | 72 +++++++++++++++++++++++++++++++++++++++++++ CourseApp/Platypus.cs | 60 ------------------------------------ 3 files changed, 72 insertions(+), 63 deletions(-) create mode 100644 CourseApp/Pistol.cs delete mode 100644 CourseApp/Platypus.cs diff --git a/CourseApp/Function.cs b/CourseApp/Function.cs index 61f8797..7a09791 100644 --- a/CourseApp/Function.cs +++ b/CourseApp/Function.cs @@ -59,9 +59,6 @@ public static void Main(string[] args) Console.WriteLine($"x={xB[i]} y={taskB[i]}"); } - var item = new Platypus(); - Console.WriteLine(item.View()); - Console.ReadLine(); } } diff --git a/CourseApp/Pistol.cs b/CourseApp/Pistol.cs new file mode 100644 index 0000000..e64a932 --- /dev/null +++ b/CourseApp/Pistol.cs @@ -0,0 +1,72 @@ +using System; + +namespace CourseApp +{ + public class Pistol + { + private double kalibr; + + public Pistol() + : this("No model", 0, true) + { + } + + public Pistol(string model, double kalibr, bool fire) + { + Model = model; + Kalibr = kalibr; + Fire = fire; + } + + public string Model { get; set; } + + public double Kalibr + { + get + { + return this.kalibr; + } + + set + { + if (value >= 0 && value < 20) + { + this.kalibr = value; + } + else + { + Console.WriteLine("Enter correct kalibr"); + } + } + } + + public bool Fire { get; set; } + + public bool CanShoot + { + get { return this.Fire; } + } + + public string Shoot(bool canShoot) + { + if (canShoot == true) + { + return $"Pistol {Model} and {Kalibr} made the shot!"; + } + else + { + return $"Pistol {Model} and {Kalibr} not made the shot!"; + } + } + + public override string ToString() + { + return $"Pistil-{Model}, {Kalibr}, {Fire}"; + } + + public string NumShoot(int shot) + { + return $"{Model} made of {shot} shots"; + } + } +} \ No newline at end of file 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 From 9531f0de6ebd847d31fb3df0af3de5c75ca39775 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 2 Dec 2019 12:55:08 +0300 Subject: [PATCH 14/18] AddTestClass --- CourseApp.Tests/PistolTest.cs | 58 +++++++++++++++++++++++++++++++++ CourseApp.Tests/PlatypusTest.cs | 55 ------------------------------- CourseApp/Pistol.cs | 2 +- 3 files changed, 59 insertions(+), 56 deletions(-) create mode 100644 CourseApp.Tests/PistolTest.cs delete mode 100644 CourseApp.Tests/PlatypusTest.cs diff --git a/CourseApp.Tests/PistolTest.cs b/CourseApp.Tests/PistolTest.cs new file mode 100644 index 0000000..9fa455a --- /dev/null +++ b/CourseApp.Tests/PistolTest.cs @@ -0,0 +1,58 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class PistolTest + { + [Fact] + public void TestEmptyConstructor() + { + var item = new Pistol(); + Assert.Equal(0, item.Kalibr); + Assert.Equal("No model", item.Model); + Assert.True(item.Fire); + } + + [Fact] + public void TestSetAge() + { + var item = new Pistol(); + item.Kalibr = 5; + Assert.Equal(5, item.Kalibr); + } + + [Fact] + public void TestIncorrectSetAge() + { + var item = new Pistol(); + item.Kalibr = -5; + Assert.Equal(0, item.Kalibr); + } + + [Fact] + public void TestCorrectIncorrectSetAge() + { + var item = new Pistol(); + item.Kalibr = 10; + item.Kalibr = -5; + Assert.Equal(10, item.Kalibr); + } + + [Fact] + public void TestShoot() + { + var item = new Pistol("Glock", 10, true); + var act = item.Shoot(true); + Assert.Equal($"Pistol Glock and 10 made the shot!", act); + } + + [Fact] + public void TestNumShoot() + { + var item = new Pistol("Glock", 10, true); + var act = item.NumShoot(15); + Assert.Equal($"Glock made of 15 shots", act); + } + } +} diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs deleted file mode 100644 index 77c4d8f..0000000 --- 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/Pistol.cs b/CourseApp/Pistol.cs index e64a932..e3f4df0 100644 --- a/CourseApp/Pistol.cs +++ b/CourseApp/Pistol.cs @@ -61,7 +61,7 @@ public string Shoot(bool canShoot) public override string ToString() { - return $"Pistil-{Model}, {Kalibr}, {Fire}"; + return $"Pistol-{Model}, {Kalibr}, {Fire}"; } public string NumShoot(int shot) From c71172be7791f1bcefa3fbbc49d0466efa3e2f74 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 16 Dec 2019 08:53:17 +0300 Subject: [PATCH 15/18] Add function collection --- CourseApp/Function.cs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/CourseApp/Function.cs b/CourseApp/Function.cs index 7a09791..bf95e7d 100644 --- a/CourseApp/Function.cs +++ b/CourseApp/Function.cs @@ -1,4 +1,6 @@ using System; +using System.Collections; +using System.Collections.Generic; namespace CourseApp { @@ -11,30 +13,27 @@ public static double MyFunction(double x) return c; } - public static double[] TaskA ( + public static List TaskA( double xn, double xk, double dx) { - var steps = (int)Math.Floor((xk - xn) / dx); - var y = new double[steps]; - var i = 0; + List y = new List(); for (var x = xn; x < xk; x += dx) { - y[i] = MyFunction(x); - i++; + y.Add(MyFunction(x)); } return y; } - public static double[] TaskB ( - double[] x) + public static List TaskB ( + List x) { - var y = new double[x.Length]; - for (int i = 0; i < x.Length; i++) + List y = new List(5); + foreach (double i in x) { - y[i] = MyFunction(x[i]); + y.Add(MyFunction(i)); } return y; @@ -44,21 +43,26 @@ public static void Main(string[] args) { MyFunction(0); Console.WriteLine("Hello World!"); - var taskA = TaskA(0.11, 0.36, 0.05); + List taskA = TaskA(0.11, 0.36, 0.05); Console.WriteLine(taskA); - for (var i = 0; i < taskA.Length; i++) + foreach (var item in taskA) { - Console.WriteLine($"y={taskA[i]}"); + Console.WriteLine($"y={item}"); } - var xB = new double[] { 0.2, 0.3, 0.38, 0.43, 0.57 }; - var taskB = TaskB(xB); - for (var i = 0; i < xB.Length; i++) + List xB = new List() { 0.2, 0.3, 0.38, 0.43, 0.57 }; + List taskB = TaskB(xB); + for (int i = 0; i < 5; i++) { - Console.WriteLine($"x={xB[i]} y={taskB[i]}"); + Console.WriteLine($"x={xB[i]}"); } + foreach (var item in taskB) + { + Console.WriteLine($"y={item}"); + } + Console.ReadLine(); } } From 5c988278df12ae8e7680cdbaad20dba4f33693a3 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 16 Dec 2019 08:54:09 +0300 Subject: [PATCH 16/18] Add Test + collection --- CourseApp.Tests/FunctionTest.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/CourseApp.Tests/FunctionTest.cs b/CourseApp.Tests/FunctionTest.cs index 92aa7ee..fbf82fe 100644 --- a/CourseApp.Tests/FunctionTest.cs +++ b/CourseApp.Tests/FunctionTest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Xunit; namespace CourseApp.Tests @@ -18,17 +19,20 @@ public void TestCalc(double x, double exp) [Fact] public void TestNormalA() { - var action = Function.TaskA(0.11, 0.36, 0.05); - var s = new double[] { -0.942599174573112, -0.768989662415832, -0.640224062047432, -0.537938691770828, -0.453755045309719 }; - Assert.Equal(action[0], s[0], 3); + List action = Function.TaskA(0.11, 0.36, 0.05); + List s = new List() { -0.942599174573112, -0.768989662415832, -0.640224062047432, -0.537938691770828, -0.453755045309719 }; + for (var i = 0; i < 5; i++) + { + Assert.Equal(action[i], s[i], 3); + } } [Fact] public void TestNormalB() { - var x = new double[] { 0.2, 0.3, 0.38, 0.43, 0.57 }; + List x = new List { 0.2, 0.3, 0.38, 0.43, 0.57 }; var actial = Function.TaskB(x); - var exp = new double[] { -0.663479953941618, -0.469395196867133, -0.357994574230452, -0.301819984896032, -0.184040925422074 }; + List exp = new List { -0.663479953941618, -0.469395196867133, -0.357994574230452, -0.301819984896032, -0.184040925422074 }; for (var i = 0; i < 5; i++) { Assert.Equal(exp[i], actial[i], 3); @@ -38,7 +42,7 @@ public void TestNormalB() [Fact] public void TestZeroLengthB() { - var res = Function.TaskB(new double[0]); + var res = Function.TaskB(new List()); Assert.Empty(res); } } From 455f611ffcb1752797189f2909c4f9c08ae54ac6 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 16 Dec 2019 21:44:50 +0300 Subject: [PATCH 17/18] add class+exception --- CourseApp/Pistol.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CourseApp/Pistol.cs b/CourseApp/Pistol.cs index e3f4df0..665165b 100644 --- a/CourseApp/Pistol.cs +++ b/CourseApp/Pistol.cs @@ -35,7 +35,7 @@ public double Kalibr } else { - Console.WriteLine("Enter correct kalibr"); + throw new Exception("Enter correct kalibr"); } } } @@ -61,7 +61,7 @@ public string Shoot(bool canShoot) public override string ToString() { - return $"Pistol-{Model}, {Kalibr}, {Fire}"; + return $"Pistil-{Model}, {Kalibr}, {Fire}"; } public string NumShoot(int shot) From 15b0626524d735e599920260509c79937fd848e6 Mon Sep 17 00:00:00 2001 From: Evgenij_Satyev Date: Mon, 16 Dec 2019 22:27:34 +0300 Subject: [PATCH 18/18] add test+exception --- CourseApp.Tests/PistolTest.cs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/CourseApp.Tests/PistolTest.cs b/CourseApp.Tests/PistolTest.cs index 9fa455a..84cb45d 100644 --- a/CourseApp.Tests/PistolTest.cs +++ b/CourseApp.Tests/PistolTest.cs @@ -22,23 +22,6 @@ public void TestSetAge() Assert.Equal(5, item.Kalibr); } - [Fact] - public void TestIncorrectSetAge() - { - var item = new Pistol(); - item.Kalibr = -5; - Assert.Equal(0, item.Kalibr); - } - - [Fact] - public void TestCorrectIncorrectSetAge() - { - var item = new Pistol(); - item.Kalibr = 10; - item.Kalibr = -5; - Assert.Equal(10, item.Kalibr); - } - [Fact] public void TestShoot() { @@ -54,5 +37,20 @@ public void TestNumShoot() var act = item.NumShoot(15); Assert.Equal($"Glock made of 15 shots", act); } + + [Fact] + public void TestCorrectIncorrectSetKalibr() + { + var item = new Pistol(); + try + { + item.Kalibr = -5; + Assert.Equal(-5, item.Kalibr); + } + catch (System.Exception) + { + Assert.True(true); + } + } } }