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 new file mode 100644 index 0000000..bf8e2a6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,207 @@ +# Download this file using PowerShell v3 under Windows with the following comand: +# Invoke-WebRequest https://gist.githubusercontent.com/kmorcinek/2710267/raw/ -OutFile .gitignore +# or wget: +# wget --no-check-certificate http://gist.githubusercontent.com/kmorcinek/2710267/raw/.gitignore + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# OS generated files # +.DS_Store* +Icon? + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.Cache +ClientBin/ +# [Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings +modulesbin/ +tempbin/ + +# EPiServer Site file (VPP) +AppData/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# vim +*.txt~ +*.swp +*.swo + +# svn +.svn + +# Remainings from resolvings conflicts in Source Control +*.orig + +# SQL Server files +**/App_Data/*.mdf +**/App_Data/*.ldf +**/App_Data/*.sdf + + +#LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac desktop service store files +.DS_Store + +# SASS Compiler cache +.sass-cache + +# Visual Studio 2014 CTP +**/*.sln.ide + +# Visual Studio temp something +.vs/ + +# VS 2015+ +*.vc.vc.opendb +*.vc.db + +# Rider +.idea/ + +**/node_modules/* + +# Added by Jskonst +# .vscode/ +Properties/ + +##### +# End of core ignore list, below put you custom 'per project' settings (patterns or path) +##### +/CourseApp/.vscode diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj new file mode 100644 index 0000000..cb0486b --- /dev/null +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -0,0 +1,30 @@ + + + + netcoreapp2.1 + True + 1573,1591,1701;1702;1705 + false + + + + + + + + + + + + + + + ../_stylecop/stylecop.ruleset + true + + + + + + + \ No newline at end of file diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs new file mode 100644 index 0000000..cd05a99 --- /dev/null +++ b/CourseApp.Tests/DemoTest.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using Xunit; + +namespace CourseApp.Tests +{ + public class DemoTest + { + [Fact] + public void Test1() + { + Xunit.Assert.True(true); + } + + [Fact] + public void TestMyFunctionZeros() + { + var res = Program.MyFunction(0.0, 0.0); + Xunit.Assert.Equal(double.NaN, res); + } + + [Fact] + public void TestMyFunctionNonZeros() + { + double test = 1.52287874528034; + var res = Program.MyFunction(1, 2); + Xunit.Assert.Equal(test, res, 1); + + /* Хотел бы воспользоваться помощью! + Когда в этом тесте пишу вместо 1, 2 в функции + MyFuncion(5, 6), то ответ получается 2.91038304567337E+24 + И AssertEqual не работает ни с каким указанием точности, + указывая, что значения не одинаковы, даже если просто списать его + для проверки + В чём дело? Слишком большое число? Или те самые проблемы языков с плавающей точкой? + */ + } + + [Fact] + public void TestTaskBNullMass() + { + List mass = new List(); + var res = Program.TaskB(1, mass); + Xunit.Assert.Equal(mass, res); + } + + [Fact] + public void TestTaskB() + { + List x = new List { 1.28, 1.36, 2.47, 3.68, 4.56 }; + var res = Program.TaskB(1.6, x); + List expy = new List { 2.54483385166692, 2.5615887682505, 11.2873629585646, 363.108837198182, 10971.2863691829 }; + for (int i = 0; i < 5; i++) + { + Xunit.Assert.Equal(expy[i], res[i], 3); + } + } + + [Fact] + public void TestTaskA0() + { + double a = 1.6; + double xn = 1.2; + double xk = 3.7; + double dx = 0.5; + var res = Program.TaskA(a, xn, xk, dx); + List expy = new List { 2.58628588710697, 3.15454831838707, 6.49450906742811, 19.428489457705, 76.9595290357977 }; + for (int i = 0; i < 5; i++) + { + Xunit.Assert.Equal(expy[i], res[i], 3); + } + } + + [Fact] + public void TestTaskA1() + { + double a = 1.6; + double xn = 1.2; + double xk = 3.7; + double dx = 0.5; + var res = Program.TaskA(a, xn, xk, dx); + List expy = new List { 2.58628588710697, 3.15454831838707, 6.49450906742811, 19.428489457705, 76.9595290357977 }; + for (int i = 0; i < 5; i++) + { + Xunit.Assert.Equal(expy[i], res[i], 3); + } + } + + [Fact] + public void TestTaskA2() + { + double a = 1.6; + double xn = 1.2; + double xk = 3.7; + double dx = 0.5; + var res = Program.TaskA(a, xn, xk, dx); + List expy = new List { 2.58628588710697, 3.15454831838707, 6.49450906742811, 19.428489457705, 76.9595290357977 }; + for (int i = 0; i < 5; i++) + { + Xunit.Assert.Equal(expy[i], res[i], 3); + } + } + } +} diff --git a/CourseApp.Tests/PersonTest.cs b/CourseApp.Tests/PersonTest.cs new file mode 100644 index 0000000..d9007e6 --- /dev/null +++ b/CourseApp.Tests/PersonTest.cs @@ -0,0 +1,102 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class PersonTest + { + [Fact] + public void TestEmptyConstructor() + { + var item = new Person(); + Assert.Equal(0, item.Age); + Assert.Equal("Somename", item.Name); + Assert.Equal("Somesurname", item.Surname); + Assert.True(item.IsMale); + } + + [Fact] + public void TestView() + { + var item = new Person(); + var view = "hello"; + Assert.Equal(view, item.ToString()); + } + + [Fact] + public void TestSetAge() + { + var item = new Person(); + item.Age = 26; + Assert.Equal(26, item.Age); + } + + [Fact] + public void TestIncorrectSetAge() + { + var item = new Person(); + try + { + item.Age = -5; + } + catch + { + Assert.Equal(0, item.Age); + return; + } + + Assert.True(false); + } + + [Fact] + public void TestCorrectIncorrectSetAge() + { + var item = new Person(); + item.Age = 27; + try + { + item.Age = -1; + } + catch + { + Assert.Equal(27, item.Age); + return; + } + + Assert.Equal(27, item.Age); + } + + [Fact] + public void TestIncorrectSetString() + { + var item = new Person(); + try + { + item.Name = string.Empty; + } + catch (ArgumentNullException) + { + Assert.True(true); + } + + try + { + item.Surname = string.Empty; + } + catch (ArgumentNullException) + { + Assert.True(true); + } + } + + [Fact] + public void TestCorrectSetString() + { + var item = new Person(); + item.Name = "im so tired"; + item.Surname = "it is not a test it is a cry for help"; + Assert.Equal("im so tired", item.Name); + Assert.Equal("it is not a test it is a cry for help", item.Surname); + } + } +} 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/Alien.cs b/CourseApp/Alien.cs new file mode 100644 index 0000000..8f692f9 --- /dev/null +++ b/CourseApp/Alien.cs @@ -0,0 +1,34 @@ +using System; + +namespace CourseApp +{ + public class Alien : Humanoid + { + public Alien() + : this(0, "Somename", "Somesurname", true, "Mars") + { + } + + public Alien(int age, string name, string surname, bool isMale, string homeland) + : base(10, name, surname, true) + { + Homeland = homeland; + Name = name; + Surname = surname; + Age = age; + IsMale = isMale; + } + + public string Homeland { get; set; } + + public override void SayAnything() + { + Console.WriteLine($"{Name} {Surname}: -alien speech-"); + } + + public override string ToString() + { + return $"Name:{Name}, Surname:{Surname}, Age:{Age}, Homeland:{Homeland}"; + } + } +} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj new file mode 100644 index 0000000..a702dd8 --- /dev/null +++ b/CourseApp/CourseApp.csproj @@ -0,0 +1,23 @@ + + + + Exe + netcoreapp2.1 + True + 1573,1591,1701;1702;1705; + + + + + + + + ../_stylecop/stylecop.ruleset + true + + + + + + + \ No newline at end of file diff --git a/CourseApp/CourseApp.sln b/CourseApp/CourseApp.sln new file mode 100644 index 0000000..9eae834 --- /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.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 diff --git a/CourseApp/Humanoid.cs b/CourseApp/Humanoid.cs new file mode 100644 index 0000000..420a4c5 --- /dev/null +++ b/CourseApp/Humanoid.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; + +namespace CourseApp +{ + public abstract class Humanoid + { + private int age; + private string name; + private string surname; + + public Humanoid() + : this("Somename", "Somesurname") + { + } + + public Humanoid(string name, string surname) + : this(0, name, surname, true) + { + } + + public Humanoid(int age, string name, string surname, bool isMale) + { + Name = name; + Surname = surname; + Age = age; + IsMale = isMale; + } + + public string Name + { + get + { + return this.name; + } + + set + { + if (value == string.Empty) + { + throw new ArgumentNullException("This field can't be empty."); + } + else + { + this.name = value; + } + } + } + + public string Surname + { + get + { + return this.surname; + } + + set + { + if (value == string.Empty) + { + throw new ArgumentNullException("This field can't be empty."); + } + else + { + this.surname = value; + } + } + } + + public bool IsMale { get; set; } + + public int Age + { + get + { + return this.age; + } + + set + { + if (value >= 0 && value < 200) + { + this.age = value; + } + else + { + throw new Exception("Age should be > 0 and < than 20"); + } + } + } + + public override string ToString() + { + return $"Name:{Name}, Surname:{Surname}, Age:{Age}"; + } + + public void AgeDown() + { + this.Age--; + } + + public abstract void SayAnything(); + } +} \ No newline at end of file diff --git a/CourseApp/Person.cs b/CourseApp/Person.cs new file mode 100644 index 0000000..006d086 --- /dev/null +++ b/CourseApp/Person.cs @@ -0,0 +1,30 @@ +using System; + +namespace CourseApp +{ + public class Person : Humanoid + { + public Person() + : this(0, "Somename", "Somesurname", true) + { + } + + public Person(int age, string name, string surname, bool isMale) + { + Name = name; + Surname = surname; + Age = age; + IsMale = isMale; + } + + public override void SayAnything() + { + Console.WriteLine($"{Name} {Surname}: -human english speech-"); + } + + public override string ToString() + { + return "hello"; + } + } +} \ 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 new file mode 100644 index 0000000..72616cf --- /dev/null +++ b/CourseApp/Program.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; + +namespace CourseApp +{ + public class Program + { + public static double MyFunction(double a, double x) + { + var y = Math.Pow(a, Math.Pow(x, 2) - 1) - Math.Log10(Math.Pow(x, 2) - 1) + Math.Pow(Math.Sqrt(Math.Pow(x, 2) - 1), 1 / 3); + return y; + } + + public static List TaskA(double a, double xn, double xk, double dx) + { + var y = new List(); + for (double x = xn; x < xk; x += dx) + { + y.Add(MyFunction(a, x)); + } + + return y; + } + + public static List TaskB(double a, List x) + { + var y = new List(); + for (var i = 0; i < x.Count; i++) + { + y.Add(MyFunction(a, x[i])); + } + + return y; + } + + public static void Main(string[] args) + { + const double a = 1.6; + const double xn = 1.2; + const double xk = 3.7; + const double dx = 0.5; + Console.WriteLine("Task А:"); + foreach (var item in TaskA(a, xn, xk, dx)) + { + Console.WriteLine($"y = {item}"); + } + + Console.WriteLine("Task B:"); + List x = new List { 1.28, 1.36, 2.47, 3.68, 4.56 }; + foreach (var item in TaskB(a, x)) + { + Console.WriteLine($"y = {item}"); + } + + Console.WriteLine(MyFunction(5, 6)); + + Console.ReadLine(); + } + } +} \ No newline at end of file diff --git a/_stylecop/stylecop.json b/_stylecop/stylecop.json new file mode 100644 index 0000000..4a96e8f --- /dev/null +++ b/_stylecop/stylecop.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "documentExposedElements": false, + "documentInterfaces": false, + "companyName": "Test Company", + "copyrightText": "This source code is Copyright © {companyName} and MAY NOT be copied, reproduced,\npublished, distributed or transmitted to or stored in any manner without prior\nwritten consent from {companyName} (www.yourcompany.com).", + "xmlHeader":false + } + } +} \ No newline at end of file diff --git a/_stylecop/stylecop.ruleset b/_stylecop/stylecop.ruleset new file mode 100644 index 0000000..98806c8 --- /dev/null +++ b/_stylecop/stylecop.ruleset @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/courseworkspace.code-workspace b/courseworkspace.code-workspace new file mode 100644 index 0000000..4f9af01 --- /dev/null +++ b/courseworkspace.code-workspace @@ -0,0 +1,11 @@ +{ + "folders": [ + { + "path": "CourseApp" + }, + { + "path": "CourseApp.Tests" + } + ], + "settings": {} +} \ No newline at end of file