diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8dc39cc2..01821dd1 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,29 +1,29 @@ - - - - netcoreapp2.1 - True - false - - - - - - - - - - - - - - - ../_stylecop/stylecop.ruleset - true - - - - - - - + + + + netcoreapp2.1 + True + false + + + + + + + + + + + + + + + ../_stylecop/stylecop.ruleset + true + + + + + + + diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs deleted file mode 100644 index cf7cbb14..00000000 --- a/CourseApp.Tests/DemoTest.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp.Tests -{ - using Xunit; - - public class DemoTest - { - [Fact] - public void Test1() - { - Assert.True(true); - } - } -} diff --git a/CourseApp.Tests/TestEmployee.cs b/CourseApp.Tests/TestEmployee.cs new file mode 100644 index 00000000..1e0266b0 --- /dev/null +++ b/CourseApp.Tests/TestEmployee.cs @@ -0,0 +1,69 @@ +using System; +using Xunit; +using EmployeeClass; +using System.Threading; + +namespace TestEmployee +{ + public class TestEmployee + { + [Fact] + public void timeSpentFromGettingAJob_return2Seconds() + { + Employee emp = new Employee(); + + Thread.Sleep(2000); + + TimeSpan totalSeconds = emp.timeSpentFromGettingJob(); + + double res = Math.Round(totalSeconds.TotalSeconds); + + int seconds = 2; + + Assert.Equal(seconds, res); + } + + [Fact] + public void getJob_returns_Lvl1_2_3() + { + Employee emp = new Employee(); + + string res = emp.getJob(); + + if(res == "Lvl 1") + { + Assert.Equal(res, "Lvl 1"); + } + else if(res == "Lvl 2") + { + Assert.Equal(res, "Lvl 2"); + } + else + { + Assert.Equal(res, "Lvl 3"); + } + } + + [Fact] + public void getSalery_returns_1000_2000_3000() + { + Employee emp = new Employee(); + + int res = emp.getSalary(); + + if(emp.job == "Lvl 1") + { + Assert.Equal(1000, res); + } + else if(emp.job == "Lvl 2") + { + Assert.Equal(2000, res); + } + else + { + Assert.Equal(3000, res); + } + + } + } +} diff --git a/CourseApp.Tests/TestFormula.cs b/CourseApp.Tests/TestFormula.cs new file mode 100644 index 00000000..50da1909 --- /dev/null +++ b/CourseApp.Tests/TestFormula.cs @@ -0,0 +1,42 @@ +using System; +using Xunit; +using Formula; + +namespace TestFormula +{ + public class TestFormula + { + [Theory] + [InlineData(1.2,5.2,0.8,4.1,2.7)] + public void TestFormulaA(double xb, double xe, double dx, double a, double b) + { + Formula13 f = new Formula13(); + + double[] f_res = new double[5] { -5.988041709469331, 1, 20.10917011949253, 13.56786626062469, 11.505040323579745 }; + + double[] res = f.countFormulaA(xb, xe, dx, a, b); + + for (int i = 0; i < res.Length; i++) + { + Assert.Equal(res[i], f_res[i]); + } + } + + [Theory] + [InlineData(4.1,2.7)] + public void TestFormulaB(double a, double b) + { + Formula13 f = new Formula13(); + + double[] x_nums = new double[5] { 1.9, 2.15, 2.34, 2.73, 3.16 }; + double[] f_res = new double[5] { -99.97670497061331, 77.88791023801342, 38.122692372591594, 21.380274597107814, 16.020495497448806 }; + + double[] res = f.countFormulaB(x_nums, a, b); + + for (int i = 0; i < res.Length; i++) + { + Assert.Equal(res[i], f_res[i]); + } + } + } +} diff --git a/CourseApp/.vscode/launch.json b/CourseApp/.vscode/launch.json index 208ea3ac..cb90cf95 100644 --- a/CourseApp/.vscode/launch.json +++ b/CourseApp/.vscode/launch.json @@ -1,25 +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}" - } - ] +{ + // 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 index f8c71cd5..4a61e46b 100644 --- a/CourseApp/.vscode/tasks.json +++ b/CourseApp/.vscode/tasks.json @@ -1,42 +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" - } - ] +{ + "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 260260d3..6b8e84e1 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -1,22 +1,22 @@ - - - - Exe - netcoreapp2.1 - True - - - - - - - - ../_stylecop/stylecop.ruleset - true - - - - - - - + + + + Exe + netcoreapp2.1 + True + + + + + + + + ../_stylecop/stylecop.ruleset + true + + + + + + + diff --git a/CourseApp/CourseApp.sln b/CourseApp/CourseApp.sln index 9eae834c..4830b83b 100644 --- a/CourseApp/CourseApp.sln +++ b/CourseApp/CourseApp.sln @@ -1,31 +1,43 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2027 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp", "CourseApp.csproj", "{9B953FDD-1645-4B1A-B148-5849E7C2D3A7}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp.Tests", "..\CourseApp.Tests\CourseApp.Tests.csproj", "{C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9B953FDD-1645-4B1A-B148-5849E7C2D3A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9B953FDD-1645-4B1A-B148-5849E7C2D3A7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9B953FDD-1645-4B1A-B148-5849E7C2D3A7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9B953FDD-1645-4B1A-B148-5849E7C2D3A7}.Release|Any CPU.Build.0 = Release|Any CPU - {C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {064E603C-674E-4DB9-A061-4B08C0ACD98C} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31624.102 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp", "CourseApp.csproj", "{9B953FDD-1645-4B1A-B148-5849E7C2D3A7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp.Tests", "..\CourseApp.Tests\CourseApp.Tests.csproj", "{C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InterfaceTesting", "..\ConsoleApp1\InterfaceTesting.csproj", "{7BF29BEB-1805-45D9-8929-D67E38FE73F9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Player1", "..\Player\Player1.csproj", "{1FA106C9-0A52-4084-AFEF-188A9C24BE64}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9B953FDD-1645-4B1A-B148-5849E7C2D3A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9B953FDD-1645-4B1A-B148-5849E7C2D3A7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9B953FDD-1645-4B1A-B148-5849E7C2D3A7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9B953FDD-1645-4B1A-B148-5849E7C2D3A7}.Release|Any CPU.Build.0 = Release|Any CPU + {C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C348D2ED-C90F-4CE7-A1D8-9E57CBB33BDE}.Release|Any CPU.Build.0 = Release|Any CPU + {7BF29BEB-1805-45D9-8929-D67E38FE73F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7BF29BEB-1805-45D9-8929-D67E38FE73F9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7BF29BEB-1805-45D9-8929-D67E38FE73F9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7BF29BEB-1805-45D9-8929-D67E38FE73F9}.Release|Any CPU.Build.0 = Release|Any CPU + {1FA106C9-0A52-4084-AFEF-188A9C24BE64}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1FA106C9-0A52-4084-AFEF-188A9C24BE64}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1FA106C9-0A52-4084-AFEF-188A9C24BE64}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1FA106C9-0A52-4084-AFEF-188A9C24BE64}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {064E603C-674E-4DB9-A061-4B08C0ACD98C} + EndGlobalSection +EndGlobal diff --git a/CourseApp/Employee.cs b/CourseApp/Employee.cs new file mode 100644 index 00000000..e2534c69 --- /dev/null +++ b/CourseApp/Employee.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeeClass +{ + public class Employee + { + string name; + int age; + DateTime date; + public string job; + public Employee(string name, int age) + { + this.name = name; + this.age = age; + this.date = DateTime.Now; + this.job = getJob(); + } + + public Employee() + { + this.name = null; + this.age = 0; + this.date = DateTime.Now; + this.job = getJob(); + } + + public TimeSpan timeSpentFromGettingJob() + { + DateTime now = DateTime.Now; + return now - this.date; + } + + public string getJob() + { + Random rand = new Random(); + int res = rand.Next(1, 4); + + if(res == 1) + { + return "Lvl 1"; + } + else if(res == 2) + { + return "Lvl 2"; + } + else + { + return "Lvl 3"; + } + } + + public int getSalary() + { + int standardSalary = 1000; + + if(this.job == "Lvl 1") + { + return standardSalary; + } + else if(this.job == "Lvl 2") + { + return standardSalary * 2; + } + else + { + return standardSalary * 3; + } + } + } +} diff --git a/CourseApp/Formula13.cs b/CourseApp/Formula13.cs new file mode 100644 index 00000000..c34799cf --- /dev/null +++ b/CourseApp/Formula13.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Formula +{ + public class Formula13 + { + public double countFormula(double a, double x, double b) + { + double numerator = a * Math.Sqrt(x) - b * Math.Log(x, 5); + double denumerator = Math.Log10(Math.Abs(x - 1)); + if (double.IsInfinity(numerator/denumerator)) + { + return 1; + } + return numerator / denumerator; + } + + public double[] countFormulaA(double xb, double xe, double dx, double a, double b) + { + int len = (int)((xe - xb) / dx); + double[] res = new double[len]; + int i = 0; + while (xb < xe) + { + res[i] = countFormula(a, xb, b); + i++; + xb = Math.Round(xb+dx, 2); + } + + return res; + } + + public double[] countFormulaB(double[] x, double a, double b) + { + double[] res = new double[x.Length]; + + for (int i = 0; i < res.Length; i++) + { + res[i] = countFormula(a, x[i], b); + } + + return res; + } + } +} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs deleted file mode 100644 index 51d2a96d..00000000 --- a/CourseApp/Program.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace CourseApp -{ - using System; - - public class Program - { - public static void Main(string[] args) - { - Console.WriteLine($"Hello world"); - Console.ReadLine(); - } - } -} diff --git a/Player/Player1.csproj b/Player/Player1.csproj new file mode 100644 index 00000000..1d2d39a9 --- /dev/null +++ b/Player/Player1.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + diff --git a/Player/Program.cs b/Player/Program.cs new file mode 100644 index 00000000..f48f8ff7 --- /dev/null +++ b/Player/Program.cs @@ -0,0 +1,94 @@ +using System; + +namespace Player1 +{ + interface IHasInfo + { + void ShowInfo(); + } + interface IWeapon : IHasInfo + { + void Fire(); + int Damage { get; } + } + + + abstract class Weapon : IHasInfo, IWeapon + { + public abstract int Damage { get; } + public abstract void Fire(); + + public void ShowInfo() + { + Console.WriteLine($"{GetType().Name} Damage: {Damage}"); + } + + } + + class Gun : Weapon + { + public override int Damage { get { return 10; } } + + public override void Fire() + { + Console.WriteLine("Puff"); + } + } + + class LaserGun : Weapon + { + public override int Damage { get { return 20; } } + + public override void Fire() + { + Console.WriteLine("Phhh"); + } + } + + class Bow : Weapon + { + public override int Damage { get { return 7; } } + + public override void Fire() + { + Console.WriteLine("Pow"); + } + } + + + + + class Player + { + public void Fire(IWeapon weapon) + { + weapon.Fire(); + + } + + public void CheckInfo(IHasInfo hasInfo) + { + hasInfo.ShowInfo(); + } + } + + class Program + { + static void Main(string[] args) + { + Player player = new Player(); + IWeapon[] inventory = { new Gun(), new LaserGun(), new Bow() }; + + foreach (var item in inventory) + { + player.CheckInfo(item); + player.Fire(item); + Console.WriteLine(); + } + + + + } + + } +}