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/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a..53cfe73 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -27,4 +27,4 @@ - + \ No newline at end of file diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index fdc46f5..11a7808 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,14 +1,58 @@ using System; +using System.Collections.Generic; using Xunit; namespace CourseApp.Tests { public class DemoTest { + [Theory] + [InlineData(2, 4, 0.01682)] + [InlineData(10, -5, 0.0195424)] + public void TestMyFunction(double a, double x, double exp) + { + Assert.Equal(Program.Function(a, x), exp, 3); + } + + [Fact] + + public void TestTaskA() + { + double a = 2.0; + double xn = 1.2; + double xk = 4.2; + double dx = 0.6; + List res = Program.TaskA(a, xn, xk, dx); + List expy = new List { 0.024919580136386867, 0.02327901792977313, 0.02138591667754329, 0.019542362678459768, 0.01785029731362981 }; + for (int i = 0; i < 5; i++) + { + Assert.Equal(expy[i], res[i], 3); + } + } + [Fact] public void Test1() { Assert.True(true); } + + [Fact] + public void TestZeroFunction() + { + var res = Program.Function(0.0, 0.0); + Assert.Equal(double.PositiveInfinity, res); + } + + [Fact] + public void TestTaskB() + { + List x = new List { 1.16, 1.32, 1.47, 1.65, 1.93 }; + List res = Program.TaskB(2.0, x); + List expy = new List { 0.025004724857363752, 0.024639361870982292, 0.024247019851321865, 0.023732277381772752, 0.022875026963062515 }; + for (int i = 0; i < 5; i++) + { + Assert.Equal(expy[i], res[i], 3); + } + } } } diff --git a/CourseApp.Tests/DogTest.cs b/CourseApp.Tests/DogTest.cs new file mode 100644 index 0000000..2a7e724 --- /dev/null +++ b/CourseApp.Tests/DogTest.cs @@ -0,0 +1,64 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class DogTest + { + [Fact] + public void TestConstructor() + { + var item = new Dog(); + Assert.Equal(1, item.Age); + Assert.Equal("Test", item.Name); + Assert.Equal("male", item.Sex); + } + + [Fact] + public void TestSetAge() + { + var item = new Dog(); + item.Age = 3; + Assert.Equal(3, item.Age); + } + + [Fact] + public void TestWrongAge() + { + var item = new Dog(); + try + { + item.Age = 0; + } + catch (System.Exception) + { + Console.WriteLine("ERROR! Rewrite Age!"); + Assert.True(true); + } + } + + [Fact] + public void TestWrongSex() + { + var item = new Dog(); + try + { + item.Sex = "lemonade"; + } + catch (System.Exception) + { + Console.WriteLine("ERROR! Rewrite Sex!"); + Assert.True(true); + } + } + + [Fact] + public void FullTest() + { + var item = new Dog("Doberman", 3, "male"); + Assert.Equal("Doberman", item.Name); + Assert.Equal("male", item.Sex); + Assert.Equal(3, item.Age); + } + } +} \ No newline at end of file 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.csproj b/CourseApp/CourseApp.csproj index b244e47..a702dd8 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -20,4 +20,4 @@ - + \ No newline at end of file diff --git a/CourseApp/Dog.cs b/CourseApp/Dog.cs new file mode 100644 index 0000000..210a713 --- /dev/null +++ b/CourseApp/Dog.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; + +namespace CourseApp +{ + public class Dog + { + private int age; + private string sex; + + public Dog() + : this("Test") + { + } + + public Dog(string name, int age, string sex) + { + Name = name; + Age = age; + Sex = sex; + } + + public Dog(string name) + : this(name, 1, "male") + { + } + + public string Name { get; set; } + + public string Sex + { + get + { + return this.sex; + } + + set + { + if (value == "male") + { + this.sex = value; + } + else + { + throw new System.Exception(); + } + } + } + + public int Age + { + get + { + return this.age; + } + + set + { + if (value >= 1 && value < 10) + { + this.age = value; + } + else + { + throw new System.Exception(); + } + } + } + + public override string ToString() + { + return $"Имя:{Name},Возраст:{Age},Пол:{Sex}"; + } + + public void AgeUp() + { + this.Age++; + } + } +} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 248bbe4..796cc4d 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,13 +1,67 @@ using System; +using System.Collections.Generic; namespace CourseApp { public class Program { + public static double Function(double a, double x) + { + 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) + { + int k = 0; + List y = new List(5); + for (var i = xn; i < xk; i += dx) + { + y.Add(Function(a, i)); + k++; + } + + return y; + } + + public static List TaskB(double a, List x) + { + List y = new List(5); + for (var i = 0; i < x.Count; i++) + { + y.Add(Function(a, x[i])); + } + + return y; + } + public static void Main(string[] args) { - Console.WriteLine("Hello World!"); - Console.ReadLine(); + double a = 2.0; + double xn = 1.2; + double xk = 4.2; + double dx = 0.6; + var resA = TaskA(a, xn, xk, dx); + Console.WriteLine("=========="); + Console.WriteLine("Задание А:"); + Console.WriteLine("=========="); + foreach (var item in resA) + { + Console.WriteLine($"y = {item}"); + } + + Console.WriteLine("=========="); + List x = new List { 1.16, 1.32, 1.47, 1.65, 1.93 }; + var taskBRes = TaskB(a, x); + Console.WriteLine("Задание В:"); + Console.WriteLine("=========="); + foreach (var item in taskBRes) + { + Console.WriteLine($"y1 = {item}"); + } + + Console.WriteLine("=========="); } } } diff --git a/README.md b/README.md index 5259032..660a566 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -Vladislav_Savchenko \ No newline at end of file +Vladislav_Savchenko +# Tprogramming_147_2019 \ No newline at end of file