diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml new file mode 100644 index 0000000..22cc4eb --- /dev/null +++ b/.github/workflows/dotnetcore.yml @@ -0,0 +1,23 @@ +name: .NET Core + +on: [push, pull_request] + +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 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/DemoTest.cs b/CourseApp.Tests/DemoTest.cs deleted file mode 100644 index fdc46f5..0000000 --- a/CourseApp.Tests/DemoTest.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using Xunit; - -namespace CourseApp.Tests -{ - public class DemoTest - { - [Fact] - public void Test1() - { - Assert.True(true); - } - } -} diff --git a/CourseApp.Tests/FunctionTest.cs b/CourseApp.Tests/FunctionTest.cs new file mode 100644 index 0000000..fbf82fe --- /dev/null +++ b/CourseApp.Tests/FunctionTest.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using Xunit; + +namespace CourseApp.Tests +{ + public class FunctionTest + { + [Theory] + [InlineData(0, double.NegativeInfinity)] + [InlineData(2, 0.2)] + [InlineData(1, 0)] + public void TestCalc(double x, double exp) + { + var res = Function.MyFunction(x); + Assert.Equal(exp, res, 1); + } + + [Fact] + public void TestNormalA() + { + 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() + { + List x = new List { 0.2, 0.3, 0.38, 0.43, 0.57 }; + var actial = Function.TaskB(x); + 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); + } + } + + [Fact] + public void TestZeroLengthB() + { + var res = Function.TaskB(new List()); + Assert.Empty(res); + } + } +} diff --git a/CourseApp.Tests/PistolTest.cs b/CourseApp.Tests/PistolTest.cs new file mode 100644 index 0000000..84cb45d --- /dev/null +++ b/CourseApp.Tests/PistolTest.cs @@ -0,0 +1,56 @@ +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 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); + } + + [Fact] + public void TestCorrectIncorrectSetKalibr() + { + var item = new Pistol(); + try + { + item.Kalibr = -5; + Assert.Equal(-5, item.Kalibr); + } + catch (System.Exception) + { + Assert.True(true); + } + } + } +} 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/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/Function.cs b/CourseApp/Function.cs new file mode 100644 index 0000000..bf95e7d --- /dev/null +++ b/CourseApp/Function.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +namespace CourseApp +{ + 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; + } + + public static List TaskA( + double xn, + double xk, + double dx) + { + List y = new List(); + for (var x = xn; x < xk; x += dx) + { + y.Add(MyFunction(x)); + } + + return y; + } + + public static List TaskB ( + List x) + { + List y = new List(5); + foreach (double i in x) + { + y.Add(MyFunction(i)); + } + + return y; + } + + public static void Main(string[] args) + { + MyFunction(0); + Console.WriteLine("Hello World!"); + List taskA = TaskA(0.11, 0.36, 0.05); + Console.WriteLine(taskA); + + foreach (var item in taskA) + { + Console.WriteLine($"y={item}"); + } + + 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]}"); + } + + foreach (var item in taskB) + { + Console.WriteLine($"y={item}"); + } + + Console.ReadLine(); + } + } +} diff --git a/CourseApp/Pistol.cs b/CourseApp/Pistol.cs new file mode 100644 index 0000000..665165b --- /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 + { + throw new Exception("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/Program.cs b/CourseApp/Program.cs deleted file mode 100644 index 248bbe4..0000000 --- a/CourseApp/Program.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace CourseApp -{ - public class Program - { - public static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - Console.ReadLine(); - } - } -} diff --git a/README.md b/README.md index 3d4e211..502c081 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # Tprogramming_147_2019 -Evgeniy Satyev \ No newline at end of file +Evgeniy Satyev