From 2db98edc4c6b683920154b9e7336df17cde7f8ea Mon Sep 17 00:00:00 2001 From: User of A315 Date: Thu, 12 Sep 2019 09:11:20 +0400 Subject: [PATCH 01/41] v1 --- README.md | 3 ++- dkjg | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 dkjg diff --git a/README.md b/README.md index 556d11d..98435b6 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# Tprogramming_147_2019 \ No newline at end of file +# Tprogramming_147_2019 +//hello there \ No newline at end of file diff --git a/dkjg b/dkjg new file mode 100644 index 0000000..231c547 --- /dev/null +++ b/dkjg @@ -0,0 +1,29 @@ +* Konstantin_Tjukalov + master + remotes/origin/Aleksandr_Enivatov + remotes/origin/Aleksandr_Ermakov + remotes/origin/Aleksandr_Gruzdev + remotes/origin/Aleksej_Merzljakov + remotes/origin/Alena_Krutikova + remotes/origin/Anastasija_Kasatkina + remotes/origin/Anatolij_Tkachev + remotes/origin/Anna_Kubova + remotes/origin/Anton_Lapshov + remotes/origin/Daniil_Tretjakov + remotes/origin/Denis_Oreshnikov + remotes/origin/Dmitrij_Nazarov + remotes/origin/Dmitrij_Ovsjanik + remotes/origin/Evgenij_Satyev + remotes/origin/Fedor_Tomash + remotes/origin/HEAD -> origin/master + remotes/origin/Ilja_Raskatov + remotes/origin/Konstantin_Tjukalov + remotes/origin/Ksenija_Kochina + remotes/origin/Marija_Popova + remotes/origin/Svetlana_Nesheva + remotes/origin/Valerija_Kiseleva + remotes/origin/Veniamin_Kolmogorov + remotes/origin/Viktor_Morohovtsev + remotes/origin/Vladislav_Savchenko + remotes/origin/jskonst + remotes/origin/master From 9acf321e0f1fe1707f0595717824b58b82dcaf36 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 3 Oct 2019 08:46:32 +0300 Subject: [PATCH 02/41] Initial app --- .gitignore | 206 +++++++++++++++++++++++++ CourseApp.Tests/CourseApp.Tests.csproj | 30 ++++ CourseApp.Tests/DemoTest.cs | 14 ++ CourseApp/CourseApp.csproj | 23 +++ CourseApp/Program.cs | 13 ++ _stylecop/stylecop.json | 12 ++ _stylecop/stylecop.ruleset | 14 ++ courseworkspace.code-workspace | 11 ++ 8 files changed, 323 insertions(+) create mode 100644 .gitignore create mode 100644 CourseApp.Tests/CourseApp.Tests.csproj create mode 100644 CourseApp.Tests/DemoTest.cs create mode 100644 CourseApp/CourseApp.csproj create mode 100644 CourseApp/Program.cs create mode 100644 _stylecop/stylecop.json create mode 100644 _stylecop/stylecop.ruleset create mode 100644 courseworkspace.code-workspace diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..35d4ccd --- /dev/null +++ b/.gitignore @@ -0,0 +1,206 @@ +# 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) +##### \ No newline at end of file diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj new file mode 100644 index 0000000..8fb7e4a --- /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 + + + + + + + diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs new file mode 100644 index 0000000..fdc46f5 --- /dev/null +++ b/CourseApp.Tests/DemoTest.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class DemoTest + { + [Fact] + public void Test1() + { + Assert.True(true); + } + } +} diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj new file mode 100644 index 0000000..b244e47 --- /dev/null +++ b/CourseApp/CourseApp.csproj @@ -0,0 +1,23 @@ + + + + Exe + netcoreapp2.1 + True + 1573,1591,1701;1702;1705; + + + + + + + + ../_stylecop/stylecop.ruleset + true + + + + + + + diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs new file mode 100644 index 0000000..248bbe4 --- /dev/null +++ b/CourseApp/Program.cs @@ -0,0 +1,13 @@ +using System; + +namespace CourseApp +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + Console.ReadLine(); + } + } +} 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 From aeb27bc23b08cdf09d3f75540aef1d1c06e6c7f9 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 10 Oct 2019 09:39:40 +0300 Subject: [PATCH 03/41] 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 a0c9c7eb57161e97dc047ec62b2b0d522f3788e2 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sun, 13 Oct 2019 22:41:13 +0300 Subject: [PATCH 04/41] Delete dkjg --- dkjg | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 dkjg diff --git a/dkjg b/dkjg deleted file mode 100644 index 231c547..0000000 --- a/dkjg +++ /dev/null @@ -1,29 +0,0 @@ -* Konstantin_Tjukalov - master - remotes/origin/Aleksandr_Enivatov - remotes/origin/Aleksandr_Ermakov - remotes/origin/Aleksandr_Gruzdev - remotes/origin/Aleksej_Merzljakov - remotes/origin/Alena_Krutikova - remotes/origin/Anastasija_Kasatkina - remotes/origin/Anatolij_Tkachev - remotes/origin/Anna_Kubova - remotes/origin/Anton_Lapshov - remotes/origin/Daniil_Tretjakov - remotes/origin/Denis_Oreshnikov - remotes/origin/Dmitrij_Nazarov - remotes/origin/Dmitrij_Ovsjanik - remotes/origin/Evgenij_Satyev - remotes/origin/Fedor_Tomash - remotes/origin/HEAD -> origin/master - remotes/origin/Ilja_Raskatov - remotes/origin/Konstantin_Tjukalov - remotes/origin/Ksenija_Kochina - remotes/origin/Marija_Popova - remotes/origin/Svetlana_Nesheva - remotes/origin/Valerija_Kiseleva - remotes/origin/Veniamin_Kolmogorov - remotes/origin/Viktor_Morohovtsev - remotes/origin/Vladislav_Savchenko - remotes/origin/jskonst - remotes/origin/master From 02472201c8e437f910a9fcd8e11ad50403aae5fa Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 17 Oct 2019 09:32:31 +0300 Subject: [PATCH 05/41] 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 beae4071f779f2138db5648b2ee2cfc1bfada065 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Wed, 23 Oct 2019 10:59:55 +0300 Subject: [PATCH 06/41] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 98435b6..5f9906d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ -# Tprogramming_147_2019 -//hello there \ No newline at end of file +Konstantin Tyukalov 2/147 From d514055c9f7c9797067e4a2a8d7c641baa08abe6 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Thu, 24 Oct 2019 08:32:42 +0300 Subject: [PATCH 07/41] 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 08/41] 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 09/41] 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 10/41] 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 11/41] 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 1005403680f6c8aab409ebc7db8c49b3088e12b4 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sun, 17 Nov 2019 22:32:09 +0300 Subject: [PATCH 12/41] Delete prog.cs --- prog.cs | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 prog.cs diff --git a/prog.cs b/prog.cs deleted file mode 100644 index e69de29..0000000 From 8ecbcc7e9b55159871c3632ec01e20f4b2d5d72f Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sun, 17 Nov 2019 22:42:40 +0300 Subject: [PATCH 13/41] added table function --- CourseApp.Tests/DemoTest.cs | 8 ++-- CourseApp/Program.cs | 96 ++++++++++++++++++------------------- prog.cs | 0 3 files changed, 51 insertions(+), 53 deletions(-) delete mode 100644 prog.cs diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index bd31c5c..0f39b43 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -6,12 +6,12 @@ namespace CourseApp.Tests public class DemoTest { [Theory] - [InlineData(0, 0, 0, double.NaN)] - [InlineData(1, 1, 2, 2.5)] + [InlineData(0, 0, double.NaN)] + [InlineData(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); + var res = Program.MyFunction(a, x); Assert.Equal(exp, res, 3); } @@ -28,7 +28,7 @@ public void TestNormalB() [Fact] public void TestZeroLengthB() { - var res = Program.TaskB(1, 1, new double[0]); + var res = Program.TaskB(1, new double[0]); Assert.Empty(res); } } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index a43396c..3dd064b 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,70 +1,68 @@ -using System; +// Вариант 22 +using System; namespace CourseApp { public class Program { - public static double MyFunction(double a, double b, double x) - { - var c = (b * x) + (a / x); + public static double MyFunction(double a, double x) + { + var lg = Math.Log10(Math.Pow(x, 2) - 1); + + var c = Math.Pow(a, Math.Pow(x, 2) - 1) - lg + Math.Pow(Math.Pow(x, 2) - 1, 1 / 3); 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) + public static double[] TaskA( + double a, + double xn, + double xk, + double dx) { - y[i] = MyFunction(a, b, x); - i++; - } + var steps = (int)Math.Floor((xk - xn) / dx) + 1; + var y = new double[steps]; + var i = 0; + for (var x = xn; x < xk; x += dx) + { + y[i] = MyFunction(a, x); + i++; + } - return y; - } + 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]); - } + var y = new double[x.Length]; + for (int i = 0; i < x.Length; i++) + { + y[i] = MyFunction(a, x[i]); + } - return y; - } - - 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]}"); + return y; } - var xB = new double[] { 0, 1, 2, 3 }; - var taskB = TaskB(2, 3, xB); - for (var i = 0; i < xB.Length; i++) + public static void Main(string[] args) { - Console.WriteLine($"x={xB[i]} y={taskB[i]}"); - } + Console.WriteLine("Hello World!"); + var taskA = TaskA(2.25, 1.2, 2.7, 0.3); + Console.WriteLine(taskA); + + for (var i = 0; i < taskA.Length; i++) + { + Console.WriteLine($"y={taskA[i]}"); + } - var item = new Platypus(); - Console.WriteLine(item.View()); + var xB = new double[] { 1.31, 1.39, 1.44, 1.56, 1.92 }; + var taskB = TaskB(2, xB); + for (var i = 0; i < xB.Length; i++) + { + Console.WriteLine($"x={xB[i]} y={taskB[i]}"); + } - Console.ReadLine(); - } + Console.ReadLine(); + } } -} +} \ No newline at end of file diff --git a/prog.cs b/prog.cs deleted file mode 100644 index e69de29..0000000 From baae003d0c14d8b7bf94c36f37118dd447c5e223 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Wed, 20 Nov 2019 17:05:45 +0300 Subject: [PATCH 14/41] Update README.md --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index b3309e9..1a6ad5d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,2 @@ <<<<<<< HEAD Konstantin Tyukalov 2/147 -======= -# Tprogramming_147_2019 -Konstantinov Eugeny ->>>>>>> master From 955f7e42cde0e148a9cece7fffe82a273aced1e1 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Wed, 20 Nov 2019 23:26:35 +0300 Subject: [PATCH 15/41] Still 1st lab --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/DemoTest.cs | 18 +++++++-- CourseApp.Tests/PlatypusTest.cs | 13 ------- CourseApp/Platypus.cs | 10 ----- CourseApp/Program.cs | 2 +- Film.cs | 54 ++++++++++++++++++++++++++ 6 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 Film.cs diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 8fb7e4a..bb3e234 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -4,7 +4,7 @@ netcoreapp2.1 True 1573,1591,1701;1702;1705 - false + True diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index 0f39b43..26ef825 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,20 +1,30 @@ using System; using Xunit; +// using CourseApp.Program; namespace CourseApp.Tests { public class DemoTest { [Theory] [InlineData(0, 0, double.NaN)] - [InlineData(1, 2, 2.5)] - [InlineData(-1, 1, 1, 0)] - public void TestCalc(double a, double b, double x, double exp) + + // [InlineData(-1, 0, 1)] + // [InlineData(2, 10, 6)] + public void TestCalc(double a, double x, double exp) { var res = Program.MyFunction(a, x); Assert.Equal(exp, res, 3); } + [Fact] + + public void TestZeroValues() + { + var a = Program.MyFunction(0, 0); + Assert.Equal(double.NaN, a); + } + [Fact] public void TestNormalA() { @@ -28,7 +38,7 @@ public void TestNormalB() [Fact] public void TestZeroLengthB() { - var res = Program.TaskB(1, new double[0]); + var res = Program.TaskB(0, new double[0]); Assert.Empty(res); } } diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs index 77c4d8f..8eb86ab 100644 --- a/CourseApp.Tests/PlatypusTest.cs +++ b/CourseApp.Tests/PlatypusTest.cs @@ -14,19 +14,6 @@ public void TestEmptyConstructor() Assert.True(item.IsMale); } - [Fact] - public void TestView() - { - var item = new Platypus(); - var view = @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; - Assert.Equal(view, item.View()); - } - [Fact] public void TestSetAge() { diff --git a/CourseApp/Platypus.cs b/CourseApp/Platypus.cs index eb3d463..2c5ca46 100644 --- a/CourseApp/Platypus.cs +++ b/CourseApp/Platypus.cs @@ -46,15 +46,5 @@ 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 3dd064b..abc0e27 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -48,8 +48,8 @@ public static void Main(string[] args) { Console.WriteLine("Hello World!"); var taskA = TaskA(2.25, 1.2, 2.7, 0.3); - Console.WriteLine(taskA); + // Console.WriteLine(taskA); for (var i = 0; i < taskA.Length; i++) { Console.WriteLine($"y={taskA[i]}"); diff --git a/Film.cs b/Film.cs new file mode 100644 index 0000000..fc615dc --- /dev/null +++ b/Film.cs @@ -0,0 +1,54 @@ +using System; + +namespace CourseApp +{ + public class Film + { + private int age; + string country; + + public Film() + : this(0, "Untitled","No country", true) + { + } + + public Film(int age, string name,string country) + { + Name = name; + Age = age; + } + + public string Name { get; set; } + public string Country; + + 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 string View() + { + return @" + _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, + ______,' -o :. _ . ; ,'`, `. +( -\.._,.;;'._ ,( } _`_-_,, `, `, + ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' + "; + } + } +} \ No newline at end of file From 671bff79ad6c3bc72f58b7f2a623b62b3926f64d Mon Sep 17 00:00:00 2001 From: User of A315 Date: Thu, 21 Nov 2019 09:33:18 +0400 Subject: [PATCH 16/41] v2.2 --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/DemoTest.cs | 12 +++++++----- CourseApp/CourseApp.csproj | 4 ++-- Film.cs => CourseApp/Film.cs | 21 ++++++++++----------- CourseApp/Program.cs | 4 +++- 5 files changed, 23 insertions(+), 20 deletions(-) rename Film.cs => CourseApp/Film.cs (62%) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index bb3e234..799a559 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -2,7 +2,7 @@ netcoreapp2.1 - True + False 1573,1591,1701;1702;1705 True diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index 26ef825..cfd8fd0 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -8,9 +8,9 @@ public class DemoTest { [Theory] [InlineData(0, 0, double.NaN)] + [InlineData(-1, 0, 1)] + [InlineData(2, 10, 6)] - // [InlineData(-1, 0, 1)] - // [InlineData(2, 10, 6)] public void TestCalc(double a, double x, double exp) { var res = Program.MyFunction(a, x); @@ -19,15 +19,17 @@ public void TestCalc(double a, double x, double exp) [Fact] - public void TestZeroValues() + public void TestNotANumber() { - var a = Program.MyFunction(0, 0); - Assert.Equal(double.NaN, a); + var a = Program.MyFunction(1, 1); + Assert.True(double.IsNaN(a)); } [Fact] public void TestNormalA() { + var a = Program.MyFunction(, 0); + } [Fact] diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index b244e47..127fa8f 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,8 +2,8 @@ Exe - netcoreapp2.1 - True + netcoreapp2.0 + False 1573,1591,1701;1702;1705; diff --git a/Film.cs b/CourseApp/Film.cs similarity index 62% rename from Film.cs rename to CourseApp/Film.cs index fc615dc..566e509 100644 --- a/Film.cs +++ b/CourseApp/Film.cs @@ -8,7 +8,7 @@ public class Film string country; public Film() - : this(0, "Untitled","No country", true) + : this(0, "Untitled","No country") { } @@ -30,25 +30,24 @@ public int Age set { - if (value >= 0 && value < 20) + if (value >= 1910 && value < 2020) { this.age = value; } else { - Console.WriteLine("Age should be > 0 and < than 20"); + Console.WriteLine("Age should be > 1910 and < than 2020"); } } - } - public string View() + } + public void WatchFilm() { - return @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; + Console.WriteLine("I watch film:"); + Age=1990; + + + } } } \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index abc0e27..9724ce5 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -19,7 +19,7 @@ public static double[] TaskA( double xk, double dx) { - var steps = (int)Math.Floor((xk - xn) / dx) + 1; + var steps = (int)Math.Round((xk - xn) / dx); var y = new double[steps]; var i = 0; for (var x = xn; x < xk; x += dx) @@ -62,6 +62,8 @@ public static void Main(string[] args) Console.WriteLine($"x={xB[i]} y={taskB[i]}"); } + //var tmp = new Film(); + Console.ReadLine(); } } From f6bd62e398e99818f827b2cf492419c047a0663a Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 21 Nov 2019 20:57:42 +0300 Subject: [PATCH 17/41] Deleted View mothog from Film --- Film.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Film.cs b/Film.cs index fc615dc..cf21c59 100644 --- a/Film.cs +++ b/Film.cs @@ -40,15 +40,5 @@ public int Age } } } - - public string View() - { - return @" - _.-^~~^^^`~-,_,,~''''''```~,''``~'``~, - ______,' -o :. _ . ; ,'`, `. -( -\.._,.;;'._ ,( } _`_-_,, `, `, - ``~~~~~~' ((/'((((____/~~~~~~'(,(,___> `~' - "; - } } } \ No newline at end of file From d67d45cb4a13155d4a54ead035d6ef1b77708c72 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 28 Nov 2019 00:01:15 +0300 Subject: [PATCH 18/41] Added methods for Class --- .../{PlatypusTest.cs => FilmTest.cs} | 0 CourseApp/Film.cs | 25 +++++++++++++++++++ 2 files changed, 25 insertions(+) rename CourseApp.Tests/{PlatypusTest.cs => FilmTest.cs} (100%) diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/FilmTest.cs similarity index 100% rename from CourseApp.Tests/PlatypusTest.cs rename to CourseApp.Tests/FilmTest.cs diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index 3349e6b..764348a 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -50,5 +50,30 @@ public void WatchFilm() { Console.WriteLine($"This is a film, named {Name}, Which came out in {Age} in {Country}, was awesome!"); } + public void MarkFilm(int mark) + { + switch (mark) + { + case 1: + Console.WriteLine($"{Name} is terrible film, dont watch it never!!!!!! "); + break; + + case 2: + Console.WriteLine($"Ok,{Name} not good not bad, for an amateur..."); + break; + + case 3: + Console.WriteLine($"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"); + break; + + default: + Console.WriteLine("HI-hi-hi im not watched this film"); + break; + } + } + public string SendFilm(string ToWho) + { + return $"Hi {ToWho}, can you check {Name}({Age}) to watch? I want to know your opinion about this film))"; + } } } From f25ec02f360fc15f92e93fe749f235abc0f1ccc9 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 28 Nov 2019 23:33:50 +0300 Subject: [PATCH 19/41] Fixed some cosmetic issues in Film and DemoTest --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/DemoTest.cs | 4 -- .../{FilmTest.cs => PlatypusTest.cs} | 0 CourseApp/Film.cs | 64 ++++++++++--------- 4 files changed, 34 insertions(+), 36 deletions(-) rename CourseApp.Tests/{FilmTest.cs => PlatypusTest.cs} (100%) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 799a559..bb3e234 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -2,7 +2,7 @@ netcoreapp2.1 - False + True 1573,1591,1701;1702;1705 True diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index b98383c..24383ec 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -18,7 +18,6 @@ public void TestCalc(double a, double x, double exp) } [Fact] - public void TestNotaNumber() { var a = Program.MyFunction(1.1, 1.3); @@ -32,12 +31,9 @@ public void TestNormalA(double a, double xn, double xk, double dx) { var c = Program.TaskA(a, xn, xk, dx); Assert.NotNull(c); - - // Assert.Equal(exp, c); } [Theory] - [InlineData(3, 5)] public void TestNormalB(int t, double a) { diff --git a/CourseApp.Tests/FilmTest.cs b/CourseApp.Tests/PlatypusTest.cs similarity index 100% rename from CourseApp.Tests/FilmTest.cs rename to CourseApp.Tests/PlatypusTest.cs diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index 764348a..50d1aac 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -4,19 +4,17 @@ namespace CourseApp { public class Film { - private int age; - /*private string country; - private string name;*/ + private int year; public Film() : this(0, "Untitled", "No country") { } - public Film(int age, string name, string country) + public Film(int year, string name, string country) { Name = name; - Age = age; + ProdYear = year; Country = country; } @@ -24,56 +22,60 @@ public Film(int age, string name, string country) public string Country { get; set; } - public int Age + public int ProdYear { get { - return this.age; + return this.year; } set { - if (value >= 1888 && value < 2020) + if (value >= 1888 && value <= DateTime.Now.Year) { - this.age = value; + this.year = value; } else { - Console.WriteLine("Age should be > 1888 and < than 2020"); - - // throw new Exception[]; + Console.WriteLine($"Production year should be > 1888 and < than {DateTime.Now.Year}"); } } } - public void WatchFilm() + public string WatchFilm() { - Console.WriteLine($"This is a film, named {Name}, Which came out in {Age} in {Country}, was awesome!"); + return $"This is a film, named {Name}, Which came out in {ProdYear} in {Country}, was awesome!"; } + public void MarkFilm(int mark) { switch (mark) { - case 1: - Console.WriteLine($"{Name} is terrible film, dont watch it never!!!!!! "); - break; - - case 2: - Console.WriteLine($"Ok,{Name} not good not bad, for an amateur..."); - break; - - case 3: - Console.WriteLine($"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"); - break; - - default: - Console.WriteLine("HI-hi-hi im not watched this film"); - break; + case 1: + + Console.WriteLine($"{Name} is terrible film, dont watch it never!!!!!! "); + break; + + case 2: + + Console.WriteLine($"Ok,{Name} not good not bad, for an amateur..."); + break; + + case 3: + + Console.WriteLine($"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"); + break; + + default: + + Console.WriteLine("HI-hi-hi im not watched this film"); + break; } } - public string SendFilm(string ToWho) + + public string SendFilm(string toWho) { - return $"Hi {ToWho}, can you check {Name}({Age}) to watch? I want to know your opinion about this film))"; + return $"Hi {toWho}, can you check {Name}({ProdYear}) to watch? I want to know your opinion about this film))"; } } } From 4dd0bcfdd34898e14df8b5b1662c8110d4e74ffb Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sat, 30 Nov 2019 14:30:14 +0300 Subject: [PATCH 20/41] Changed tests --- CourseApp.Tests/DemoTest.cs | 30 ++++++++++++++++++------------ CourseApp/Program.cs | 1 - 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index 24383ec..a698e7c 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -24,22 +24,28 @@ public void TestNotaNumber() Assert.False(double.IsNaN(a)); } - [Theory] - [InlineData(1, 2, 3, 4)] - [InlineData(4, 3, 2, 1)] - public void TestNormalA(double a, double xn, double xk, double dx) + [Fact] + public void TestNormalA() { - var c = Program.TaskA(a, xn, xk, dx); - Assert.NotNull(c); + var exp = Program.TaskA(2.25, 1.2, 2.7, 0.3); + var act = new double[] { 2.7853106952595, 3.65876594762302, 6.79994634014975, 16.350605890362, 47.7890653567819, 164.346493221504 }; + + for (int i = 0; i < 5; i++) + { + Assert.Equal(exp[i], act[i], 3); + } } - [Theory] - [InlineData(3, 5)] - public void TestNormalB(int t, double a) + [Fact] + public void TestNormalB() { - double[] x = new double[t]; - var c = Program.TaskB(a, x); - Assert.NotNull(c); + var x = new double[] { 1.31, 1.39, 1.44, 1.56, 1.92 }; + var act = Program.TaskB(2, x); + var exp = new double[] { 2.78776158956314, 2.93858884457848, 3.07383618485121, 3.54477114149419, 7.00788077097357 }; + for (int i = 0; i < 5; i++) + { + Assert.Equal(exp[i], act[i], 3); + } } [Fact] diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index abc0e27..0af1e6a 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -49,7 +49,6 @@ public static void Main(string[] args) Console.WriteLine("Hello World!"); var taskA = TaskA(2.25, 1.2, 2.7, 0.3); - // Console.WriteLine(taskA); for (var i = 0; i < taskA.Length; i++) { Console.WriteLine($"y={taskA[i]}"); From 90ff6fd449bf18b0aa81a548b08b77c97f48ee85 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sat, 30 Nov 2019 14:31:46 +0300 Subject: [PATCH 21/41] added ArgumentException(not tested) --- CourseApp/Film.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index 50d1aac..9adc152 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -37,7 +37,7 @@ public int ProdYear } else { - Console.WriteLine($"Production year should be > 1888 and < than {DateTime.Now.Year}"); + throw new System.ArgumentException($"Production year should be > 1888 and < than {DateTime.Now.Year}"); } } } From b605ab6d8431d8b2694c20beaec1ec16e304e7fc Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sat, 30 Nov 2019 22:27:33 +0300 Subject: [PATCH 22/41] Added override ToString --- CourseApp/Film.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index 9adc152..e2d9801 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -75,7 +75,12 @@ public void MarkFilm(int mark) public string SendFilm(string toWho) { - return $"Hi {toWho}, can you check {Name}({ProdYear}) to watch? I want to know your opinion about this film))"; + return $"Hi {toWho}, can you check {Name}({ProdYear}) to watch? I want to know your opinion about this film))"; } + + public override string ToString() + { + return "Name: " + Name.ToString() + ", Production year: " + ProdYear.ToString() + ", Country: " + Country.ToString(); + } } } From 58ece7c3e432828c8150a268bace77980d78180e Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sat, 30 Nov 2019 23:21:43 +0300 Subject: [PATCH 23/41] Added tests for Film, minor changes in Film.cs --- CourseApp.Tests/FilmTest.cs | 58 +++++++++++++++++++++++++++++++++++++ CourseApp/Film.cs | 17 ++++++----- 2 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 CourseApp.Tests/FilmTest.cs diff --git a/CourseApp.Tests/FilmTest.cs b/CourseApp.Tests/FilmTest.cs new file mode 100644 index 0000000..530fcf7 --- /dev/null +++ b/CourseApp.Tests/FilmTest.cs @@ -0,0 +1,58 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class FilmTest + { + [Fact] + public void TestEmptyConstructor() + { + var item = new Film(); + Assert.Equal(1888, item.ProdYear); + Assert.Equal("Untitled", item.Name); + Assert.Equal("No country", item.Country); + } + + [Fact] + public void TestSetProductionYear() + { + var item = new Film(); + item.ProdYear = 2005; + Assert.Equal(2005, item.ProdYear); + } + + [Fact] + public void TestIncorrectSetProductionYear() + { + var item = new Film(); + item.ProdYear = 120; + Assert.Equal(1888, item.ProdYear); + } + + [Fact] + public void TestCorrectIncorrectSetProductionYear() + { + var item = new Film(); + item.ProdYear = 2008; + item.ProdYear = 235; + Assert.Equal(2008, item.ProdYear); + } + + [Fact] + public void TestCorrectName() + { + var item = new Film(); + item.Country = "Russia"; + Assert.Equal("Russia", item.Country); + } + + [Fact] + public void TestSendFilm() + { + var item = new Film(1984, "GhostBusters", "America"); + var act = item.SendFilm("Kostya"); + Assert.Equal($"Hi Kostya, can you check GhostBusters(1984) to watch? I want to know your opinion about this film))", act); + } + } +} diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index e2d9801..d48b279 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -7,7 +7,7 @@ public class Film private int year; public Film() - : this(0, "Untitled", "No country") + : this(1888, "Untitled", "No country") { } @@ -37,14 +37,15 @@ public int ProdYear } else { - throw new System.ArgumentException($"Production year should be > 1888 and < than {DateTime.Now.Year}"); + // throw new System.ArgumentException($"Production year should be > 1888 and < than {DateTime.Now.Year}"); + Console.WriteLine($"Production year should be > 1888 and < than {DateTime.Now.Year}"); } } } public string WatchFilm() { - return $"This is a film, named {Name}, Which came out in {ProdYear} in {Country}, was awesome!"; + return $"Now i am watching a film, named {Name}, which came out in {ProdYear} from {Country}"; } public void MarkFilm(int mark) @@ -78,9 +79,9 @@ public string SendFilm(string toWho) return $"Hi {toWho}, can you check {Name}({ProdYear}) to watch? I want to know your opinion about this film))"; } - public override string ToString() - { - return "Name: " + Name.ToString() + ", Production year: " + ProdYear.ToString() + ", Country: " + Country.ToString(); - } + public override string ToString() + { + return "Name: " + Name.ToString() + ", Production year: " + ProdYear.ToString() + ", Country: " + Country.ToString(); + } } -} +} \ No newline at end of file From d3976f3e2839c9e9a5ded876d8aa6e65a0fa102b Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sat, 30 Nov 2019 23:25:16 +0300 Subject: [PATCH 24/41] kicked the platypus out of my swamp --- CourseApp.Tests/PlatypusTest.cs | 42 --------------------------- CourseApp/Platypus.cs | 50 --------------------------------- 2 files changed, 92 deletions(-) delete mode 100644 CourseApp.Tests/PlatypusTest.cs delete mode 100644 CourseApp/Platypus.cs diff --git a/CourseApp.Tests/PlatypusTest.cs b/CourseApp.Tests/PlatypusTest.cs deleted file mode 100644 index 8eb86ab..0000000 --- a/CourseApp.Tests/PlatypusTest.cs +++ /dev/null @@ -1,42 +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 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/Platypus.cs b/CourseApp/Platypus.cs deleted file mode 100644 index 2c5ca46..0000000 --- a/CourseApp/Platypus.cs +++ /dev/null @@ -1,50 +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; } - } - } -} \ No newline at end of file From 160b6c68cf0f586cf9796a8b0c3d3c80dedd4c8d Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sat, 30 Nov 2019 23:57:03 +0300 Subject: [PATCH 25/41] Renamed DemoTest to ProgTest, added test for Film --- CourseApp.Tests/FilmTest.cs | 8 ++++++++ CourseApp.Tests/{DemoTest.cs => ProgTest.cs} | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) rename CourseApp.Tests/{DemoTest.cs => ProgTest.cs} (98%) diff --git a/CourseApp.Tests/FilmTest.cs b/CourseApp.Tests/FilmTest.cs index 530fcf7..30184b3 100644 --- a/CourseApp.Tests/FilmTest.cs +++ b/CourseApp.Tests/FilmTest.cs @@ -54,5 +54,13 @@ public void TestSendFilm() var act = item.SendFilm("Kostya"); Assert.Equal($"Hi Kostya, can you check GhostBusters(1984) to watch? I want to know your opinion about this film))", act); } + + [Fact] + public void TestWatchFilm() + { + var item = new Film(1984, "GhostBusters", "America"); + var act = item.WatchFilm(); + Assert.Equal($"Now i am watching a film, named GhostBusters, which came out in 1984 from America", act); + } } } diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/ProgTest.cs similarity index 98% rename from CourseApp.Tests/DemoTest.cs rename to CourseApp.Tests/ProgTest.cs index a698e7c..d1dd982 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/ProgTest.cs @@ -3,7 +3,7 @@ namespace CourseApp.Tests { - public class DemoTest + public class ProgTest { [Theory] [InlineData(0, 0, double.NaN)] From b5665097daa65b7d0b780db1e4ef76b9af6cb923 Mon Sep 17 00:00:00 2001 From: "1@1" <1@1.ru> Date: Mon, 2 Dec 2019 09:45:50 +0300 Subject: [PATCH 26/41] Case changed for return --- CourseApp/Film.cs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index d48b279..3944542 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -48,29 +48,26 @@ public string WatchFilm() return $"Now i am watching a film, named {Name}, which came out in {ProdYear} from {Country}"; } - public void MarkFilm(int mark) + public string MarkFilm(int mark) { switch (mark) { case 1: - Console.WriteLine($"{Name} is terrible film, dont watch it never!!!!!! "); - break; - - case 2: + //Console.WriteLine($"{Name} is terrible film, dont watch it never!!!!!! "); + return $"{Name} is terrible film, dont watch it never!!!!!! "; - Console.WriteLine($"Ok,{Name} not good not bad, for an amateur..."); + // Console.WriteLine($"Ok,{Name} not good not bad, for an amateur..."); + return $"Ok,{Name} not good not bad, for an amateur..."; break; - case 3: - - Console.WriteLine($"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"); - break; + // Console.WriteLine($"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"); + return $"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"; default: - Console.WriteLine("HI-hi-hi im not watched this film"); - break; + // Console.WriteLine("HI-hi-hi im not watched this film"); + return "HI-hi-hi im not watched this film"; } } @@ -81,7 +78,7 @@ public string SendFilm(string toWho) public override string ToString() { - return "Name: " + Name.ToString() + ", Production year: " + ProdYear.ToString() + ", Country: " + Country.ToString(); + return $"Name:{Name}, Production year:{ProdYear}, Country:{Country}"; } } } \ No newline at end of file From 7406eeef06275cb307b9ff4ede519847528492b3 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Tue, 3 Dec 2019 23:19:49 +0300 Subject: [PATCH 27/41] Added Exception, minor fixes --- CourseApp.Tests/FilmTest.cs | 26 +++++++++++++++++++++----- CourseApp.Tests/ProgTest.cs | 2 +- CourseApp/Film.cs | 12 +++--------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/CourseApp.Tests/FilmTest.cs b/CourseApp.Tests/FilmTest.cs index 30184b3..c044c7a 100644 --- a/CourseApp.Tests/FilmTest.cs +++ b/CourseApp.Tests/FilmTest.cs @@ -26,17 +26,33 @@ public void TestSetProductionYear() public void TestIncorrectSetProductionYear() { var item = new Film(); - item.ProdYear = 120; - Assert.Equal(1888, item.ProdYear); + try + { + item.ProdYear = 120; + Assert.Equal(1888, item.ProdYear); + } + catch (System.Exception) + { + Console.WriteLine($"Production year should be > 1888 and < than {DateTime.Now.Year}"); + Assert.True(true); + } } [Fact] public void TestCorrectIncorrectSetProductionYear() { var item = new Film(); - item.ProdYear = 2008; - item.ProdYear = 235; - Assert.Equal(2008, item.ProdYear); + try + { + item.ProdYear = 2008; + item.ProdYear = 235; + Assert.Equal(2008, item.ProdYear); + } + catch (System.Exception) + { + Console.WriteLine($"Production year should be > 1888 and < than {DateTime.Now.Year}"); + Assert.True(true); + } } [Fact] diff --git a/CourseApp.Tests/ProgTest.cs b/CourseApp.Tests/ProgTest.cs index d1dd982..6f17ad2 100644 --- a/CourseApp.Tests/ProgTest.cs +++ b/CourseApp.Tests/ProgTest.cs @@ -20,7 +20,7 @@ public void TestCalc(double a, double x, double exp) [Fact] public void TestNotaNumber() { - var a = Program.MyFunction(1.1, 1.3); + var a = Program.MyFunction(0, 1); Assert.False(double.IsNaN(a)); } diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index 3944542..d8486ed 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -37,8 +37,7 @@ public int ProdYear } else { - // throw new System.ArgumentException($"Production year should be > 1888 and < than {DateTime.Now.Year}"); - Console.WriteLine($"Production year should be > 1888 and < than {DateTime.Now.Year}"); + throw new System.Exception($"Production year should be > 1888 and < than {DateTime.Now.Year}"); } } } @@ -53,20 +52,15 @@ public string MarkFilm(int mark) switch (mark) { case 1: - - //Console.WriteLine($"{Name} is terrible film, dont watch it never!!!!!! "); return $"{Name} is terrible film, dont watch it never!!!!!! "; - // Console.WriteLine($"Ok,{Name} not good not bad, for an amateur..."); + case 2: return $"Ok,{Name} not good not bad, for an amateur..."; - break; - // Console.WriteLine($"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"); + case 3: return $"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"; default: - - // Console.WriteLine("HI-hi-hi im not watched this film"); return "HI-hi-hi im not watched this film"; } } From 7ff3a64cac39b86a09178416eaef4c40acddb0fe Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 5 Dec 2019 01:09:29 +0300 Subject: [PATCH 28/41] added lists (not final), commented 2 tests --- CourseApp.Tests/ProgTest.cs | 8 +++---- CourseApp/Program.cs | 43 +++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/CourseApp.Tests/ProgTest.cs b/CourseApp.Tests/ProgTest.cs index 6f17ad2..7a35a8d 100644 --- a/CourseApp.Tests/ProgTest.cs +++ b/CourseApp.Tests/ProgTest.cs @@ -36,7 +36,7 @@ public void TestNormalA() } } - [Fact] + /*[Fact] public void TestNormalB() { var x = new double[] { 1.31, 1.39, 1.44, 1.56, 1.92 }; @@ -46,13 +46,13 @@ public void TestNormalB() { Assert.Equal(exp[i], act[i], 3); } - } + } */ - [Fact] + /* [Fact] public void TestZeroLengthB() { var res = Program.TaskB(0, new double[0]); Assert.Empty(res); - } + } */ } } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 0af1e6a..2fddb7d 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,5 +1,7 @@ // Вариант 22 using System; +using System.Collections; +using System.Collections.Generic; namespace CourseApp { @@ -13,32 +15,30 @@ public static double MyFunction(double a, double x) return c; } - public static double[] TaskA( + public static List TaskA( double a, double xn, double xk, double dx) { - var steps = (int)Math.Floor((xk - xn) / dx) + 1; - var y = new double[steps]; - var i = 0; + // var steps = (int)Math.Floor((xk - xn) / dx) + 1; + List y = new List(); for (var x = xn; x < xk; x += dx) { - y[i] = MyFunction(a, x); - i++; + y.Add(MyFunction(a, x)); } return y; } - public static double[] TaskB ( + public static List TaskB ( double a, - double[] x) + 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(a, x[i]); + y.Add(MyFunction(a, i)); } return y; @@ -46,19 +46,24 @@ public static double[] TaskB ( public static void Main(string[] args) { - Console.WriteLine("Hello World!"); - var taskA = TaskA(2.25, 1.2, 2.7, 0.3); + Console.WriteLine("hELLO"); + List taskA = TaskA(2.25, 1.2, 2.7, 0.3); - 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[] { 1.31, 1.39, 1.44, 1.56, 1.92 }; - var taskB = TaskB(2, xB); - for (var i = 0; i < xB.Length; i++) + List xB = new List() { 1.31, 1.39, 1.44, 1.56, 1.92 }; + List taskB = TaskB(2, 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 3e3ee23c9c056eed758ac05452c922ec94ec32dd Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 5 Dec 2019 16:51:23 +0300 Subject: [PATCH 29/41] Tests was changed for collections --- CourseApp.Tests/ProgTest.cs | 15 ++++++++------- CourseApp/Program.cs | 1 - 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CourseApp.Tests/ProgTest.cs b/CourseApp.Tests/ProgTest.cs index 7a35a8d..f64925a 100644 --- a/CourseApp.Tests/ProgTest.cs +++ b/CourseApp.Tests/ProgTest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Xunit; namespace CourseApp.Tests @@ -36,23 +37,23 @@ public void TestNormalA() } } - /*[Fact] + [Fact] public void TestNormalB() { - var x = new double[] { 1.31, 1.39, 1.44, 1.56, 1.92 }; + List x = new List() { 1.31, 1.39, 1.44, 1.56, 1.92 }; var act = Program.TaskB(2, x); - var exp = new double[] { 2.78776158956314, 2.93858884457848, 3.07383618485121, 3.54477114149419, 7.00788077097357 }; + List exp = new List() { 2.78776158956314, 2.93858884457848, 3.07383618485121, 3.54477114149419, 7.00788077097357 }; for (int i = 0; i < 5; i++) { Assert.Equal(exp[i], act[i], 3); } - } */ + } - /* [Fact] + [Fact] public void TestZeroLengthB() { - var res = Program.TaskB(0, new double[0]); + var res = Program.TaskB(0, new List()); Assert.Empty(res); - } */ + } } } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 2fddb7d..ca04d54 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -21,7 +21,6 @@ public static List TaskA( double xk, double dx) { - // var steps = (int)Math.Floor((xk - xn) / dx) + 1; List y = new List(); for (var x = xn; x < xk; x += dx) { From 78d791405e4ef0b7609dfbcd40a1d9f1ee5f6481 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Tue, 10 Dec 2019 21:07:00 +0300 Subject: [PATCH 30/41] Added SuperClass --- CourseApp.Tests/FilmTest.cs | 4 ++-- CourseApp/Film.cs | 14 +++++++------- CourseApp/PieceOfArt.cs | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 CourseApp/PieceOfArt.cs diff --git a/CourseApp.Tests/FilmTest.cs b/CourseApp.Tests/FilmTest.cs index c044c7a..af491f2 100644 --- a/CourseApp.Tests/FilmTest.cs +++ b/CourseApp.Tests/FilmTest.cs @@ -67,7 +67,7 @@ public void TestCorrectName() public void TestSendFilm() { var item = new Film(1984, "GhostBusters", "America"); - var act = item.SendFilm("Kostya"); + var act = item.Send("Kostya"); Assert.Equal($"Hi Kostya, can you check GhostBusters(1984) to watch? I want to know your opinion about this film))", act); } @@ -75,7 +75,7 @@ public void TestSendFilm() public void TestWatchFilm() { var item = new Film(1984, "GhostBusters", "America"); - var act = item.WatchFilm(); + var act = item.Watch(); Assert.Equal($"Now i am watching a film, named GhostBusters, which came out in 1984 from America", act); } } diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index d8486ed..d808512 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -2,7 +2,7 @@ namespace CourseApp { - public class Film + public class Film : PieceOfArt { private int year; @@ -18,11 +18,11 @@ public Film(int year, string name, string country) Country = country; } - public string Name { get; set; } + public override string Name { get; set; } - public string Country { get; set; } + public override string Country { get; set; } - public int ProdYear + public override int ProdYear { get { @@ -42,12 +42,12 @@ public int ProdYear } } - public string WatchFilm() + public override string Watch() { return $"Now i am watching a film, named {Name}, which came out in {ProdYear} from {Country}"; } - public string MarkFilm(int mark) + public override string Mark(int mark) { switch (mark) { @@ -65,7 +65,7 @@ public string MarkFilm(int mark) } } - public string SendFilm(string toWho) + public override string Send(string toWho) { return $"Hi {toWho}, can you check {Name}({ProdYear}) to watch? I want to know your opinion about this film))"; } diff --git a/CourseApp/PieceOfArt.cs b/CourseApp/PieceOfArt.cs new file mode 100644 index 0000000..aa6ae60 --- /dev/null +++ b/CourseApp/PieceOfArt.cs @@ -0,0 +1,19 @@ +using System; + +namespace CourseApp +{ + public abstract class PieceOfArt + { + public abstract string Name { get; set; } + + public abstract string Country { get; set; } + + public abstract int ProdYear { get; set; } + + public abstract string Watch(); + + public abstract string Mark(int mark); + + public abstract string Send(string toWho); + } +} From 7eea7db3d936a910f2ca24c759ba9d1e1129bc4c Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Tue, 10 Dec 2019 21:30:40 +0300 Subject: [PATCH 31/41] Added constructor for SuperClass --- CourseApp/Film.cs | 13 +++++++------ CourseApp/Picture.cs | 8 ++++++++ CourseApp/PieceOfArt.cs | 13 +++++++++++-- 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 CourseApp/Picture.cs diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index d808512..fcbb35f 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -11,16 +11,17 @@ public Film() { } - public Film(int year, string name, string country) + public Film(int prodYear, string name, string country) + : base(prodYear, name, country) { - Name = name; - ProdYear = year; - Country = country; + /*Name = name; + //ProdYear = prodYear; + Country = country;*/ } - public override string Name { get; set; } + /* public override string Name { get; set; } - public override string Country { get; set; } + public override string Country { get; set; }*/ public override int ProdYear { diff --git a/CourseApp/Picture.cs b/CourseApp/Picture.cs new file mode 100644 index 0000000..09184c6 --- /dev/null +++ b/CourseApp/Picture.cs @@ -0,0 +1,8 @@ +using System; + +namespace CourseApp +{ + public class Picture + { + } +} \ No newline at end of file diff --git a/CourseApp/PieceOfArt.cs b/CourseApp/PieceOfArt.cs index aa6ae60..178c24d 100644 --- a/CourseApp/PieceOfArt.cs +++ b/CourseApp/PieceOfArt.cs @@ -4,9 +4,16 @@ namespace CourseApp { public abstract class PieceOfArt { - public abstract string Name { get; set; } + public PieceOfArt(int prodYear, string name, string country) + { + Name = name; + ProdYear = prodYear; + Country = country; + } - public abstract string Country { get; set; } + public string Name { get; set; } + + public string Country { get; set; } public abstract int ProdYear { get; set; } @@ -15,5 +22,7 @@ public abstract class PieceOfArt public abstract string Mark(int mark); public abstract string Send(string toWho); + + public new abstract string ToString(); } } From 92f6b754e6a2199efd4b897b5ae88bcbadb21aec Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 12 Dec 2019 21:22:58 +0300 Subject: [PATCH 32/41] Added class Picture, fixed issues --- CourseApp.Tests/FilmTest.cs | 2 +- CourseApp/Film.cs | 31 ++++++--------- CourseApp/Picture.cs | 66 ++++++++++++++++++++++++++++++- CourseApp/PieceOfArt.cs | 30 +++++++------- CourseApp/Program.cs | 78 ++++++++++++++++++------------------- 5 files changed, 132 insertions(+), 75 deletions(-) diff --git a/CourseApp.Tests/FilmTest.cs b/CourseApp.Tests/FilmTest.cs index af491f2..02323ca 100644 --- a/CourseApp.Tests/FilmTest.cs +++ b/CourseApp.Tests/FilmTest.cs @@ -3,7 +3,7 @@ namespace CourseApp.Tests { - public class FilmTest + public class FilmTest { [Fact] public void TestEmptyConstructor() diff --git a/CourseApp/Film.cs b/CourseApp/Film.cs index fcbb35f..4a62a97 100644 --- a/CourseApp/Film.cs +++ b/CourseApp/Film.cs @@ -14,15 +14,8 @@ public Film() public Film(int prodYear, string name, string country) : base(prodYear, name, country) { - /*Name = name; - //ProdYear = prodYear; - Country = country;*/ } - /* public override string Name { get; set; } - - public override string Country { get; set; }*/ - public override int ProdYear { get @@ -45,25 +38,25 @@ public override int ProdYear public override string Watch() { - return $"Now i am watching a film, named {Name}, which came out in {ProdYear} from {Country}"; + return $"Now i am watching a film, named {Name}, which came out in {ProdYear} from {Country}"; } public override string Mark(int mark) { - switch (mark) - { - case 1: - return $"{Name} is terrible film, dont watch it never!!!!!! "; + switch (mark) + { + case 1: + return $"{Name} is terrible film, dont watch it never!!!!!! "; - case 2: - return $"Ok,{Name} not good not bad, for an amateur..."; + case 2: + return $"Ok,{Name} not good not bad, for an amateur..."; - case 3: - return $"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"; + case 3: + return $"{Name} is a masterpeace!!! I want to {Country} to take a look at those places!!!"; - default: - return "HI-hi-hi im not watched this film"; - } + default: + return "HI-hi-hi im not watched this film"; + } } public override string Send(string toWho) diff --git a/CourseApp/Picture.cs b/CourseApp/Picture.cs index 09184c6..648c037 100644 --- a/CourseApp/Picture.cs +++ b/CourseApp/Picture.cs @@ -2,7 +2,71 @@ namespace CourseApp { - public class Picture + public class Picture : PieceOfArt { + private int year; + + public Picture() + : this(0, "Untitled", "No country") + { + } + + public Picture(int prodYear, string name, string country) + : base(prodYear, name, country) + { + } + + public override int ProdYear + { + get + { + return this.year; + } + + set + { + if (value >= 0 && value <= DateTime.Now.Year) + { + this.year = value; + } + else + { + throw new System.Exception($"Production year should be > 0 and < than {DateTime.Now.Year}"); + } + } + } + + public override string Watch() + { + return $"Now i am watching a picture, named {Name}, which was painted in {ProdYear} in {Country}"; + } + + public override string Mark(int mark) + { + switch (mark) + { + case 1: + return $"{Name} is terrible, artist need to be locked in a madhouse "; + + case 2: + return $"Ok,{Name} looks like fan art from internet ..."; + + case 3: + return $"{Name} is a masterpeace!!! I want to go to the {Country} and shake hands with the artist!"; + + default: + return "Wuh? What picture? Where?"; + } + } + + public override string Send(string toWho) + { + return $"Hi {toWho}, can you check {Name}? I want to know your opinion about this picture"; + } + + public override string ToString() + { + return $"Name:{Name}, Production year:{ProdYear}, Country:{Country}"; + } } } \ No newline at end of file diff --git a/CourseApp/PieceOfArt.cs b/CourseApp/PieceOfArt.cs index 178c24d..c72c895 100644 --- a/CourseApp/PieceOfArt.cs +++ b/CourseApp/PieceOfArt.cs @@ -2,27 +2,27 @@ namespace CourseApp { - public abstract class PieceOfArt - { - public PieceOfArt(int prodYear, string name, string country) + public abstract class PieceOfArt { - Name = name; - ProdYear = prodYear; - Country = country; - } + public PieceOfArt(int prodYear, string name, string country) + { + Name = name; + ProdYear = prodYear; + Country = country; + } - public string Name { get; set; } + public string Name { get; set; } - public string Country { get; set; } + public string Country { get; set; } - public abstract int ProdYear { get; set; } + public virtual int ProdYear { get; set; } - public abstract string Watch(); + public abstract string Watch(); - public abstract string Mark(int mark); + public abstract string Mark(int mark); - public abstract string Send(string toWho); + public abstract string Send(string toWho); - public new abstract string ToString(); - } + public new abstract string ToString(); + } } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index ca04d54..e581379 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -7,65 +7,65 @@ namespace CourseApp { public class Program { - public static double MyFunction(double a, double x) - { - var lg = Math.Log10(Math.Pow(x, 2) - 1); + public static double MyFunction(double a, double x) + { + var lg = Math.Log10(Math.Pow(x, 2) - 1); - var c = Math.Pow(a, Math.Pow(x, 2) - 1) - lg + Math.Pow(Math.Pow(x, 2) - 1, 1 / 3); + var c = Math.Pow(a, Math.Pow(x, 2) - 1) - lg + Math.Pow(Math.Pow(x, 2) - 1, 1 / 3); return c; - } + } public static List TaskA( double a, double xn, double xk, double dx) + { + List y = new List(); + for (var x = xn; x < xk; x += dx) { - List y = new List(); - for (var x = xn; x < xk; x += dx) - { - y.Add(MyFunction(a, x)); - } - - return y; + y.Add(MyFunction(a, x)); } - public static List TaskB ( + return y; + } + + public static List TaskB( double a, List x) + { + List y = new List(5); + foreach (double i in x) { - List y = new List(5); - foreach (double i in x) - { - y.Add(MyFunction(a, i)); - } - - return y; + y.Add(MyFunction(a, i)); } - public static void Main(string[] args) - { - Console.WriteLine("hELLO"); - List taskA = TaskA(2.25, 1.2, 2.7, 0.3); + return y; + } - foreach (var item in taskA) - { - Console.WriteLine($"y={item}"); - } + public static void Main(string[] args) + { + Console.WriteLine("hELLO"); + List taskA = TaskA(2.25, 1.2, 2.7, 0.3); - List xB = new List() { 1.31, 1.39, 1.44, 1.56, 1.92 }; - List taskB = TaskB(2, xB); - for (int i = 0; i < 5; i++) - { - Console.WriteLine($"x={xB[i]}"); - } + foreach (var item in taskA) + { + Console.WriteLine($"y={item}"); + } - foreach (var item in taskB) - { - Console.WriteLine($"y={item}"); - } + List xB = new List() { 1.31, 1.39, 1.44, 1.56, 1.92 }; + List taskB = TaskB(2, xB); + for (int i = 0; i < 5; i++) + { + Console.WriteLine($"x={xB[i]}"); + } - Console.ReadLine(); + foreach (var item in taskB) + { + Console.WriteLine($"y={item}"); } + + Console.ReadLine(); + } } } \ No newline at end of file From 20a2e355528692aa826110b2904e0fe6c4bc6ed5 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Fri, 13 Dec 2019 23:58:13 +0300 Subject: [PATCH 33/41] Added massive of objects --- CourseApp/Program.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index e581379..cb9854c 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -45,6 +45,13 @@ public static List TaskB( public static void Main(string[] args) { + var pieces = new PieceOfArt[] { new Film(), new Picture() }; + + for (int i = 0; i < 2; i++) + { + Console.WriteLine(pieces[i].Send("Tommy")); + } + Console.WriteLine("hELLO"); List taskA = TaskA(2.25, 1.2, 2.7, 0.3); From 990b4905f7c34785c3d76cbe7b31b16df7196d0b Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Sun, 15 Dec 2019 14:14:52 +0300 Subject: [PATCH 34/41] Added 2 tests for polimorhp --- CourseApp.Tests/PieceOfArtTest.cs | 24 ++++++++++++++++++++++++ CourseApp/PieceOfArt.cs | 5 +++++ 2 files changed, 29 insertions(+) create mode 100644 CourseApp.Tests/PieceOfArtTest.cs diff --git a/CourseApp.Tests/PieceOfArtTest.cs b/CourseApp.Tests/PieceOfArtTest.cs new file mode 100644 index 0000000..ecd0e71 --- /dev/null +++ b/CourseApp.Tests/PieceOfArtTest.cs @@ -0,0 +1,24 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class PieceOfArtTest + { + [Fact] + public void TestEmptyConstructorForPicture() + { + var item = new Picture(); + Assert.Equal(0, item.ProdYear); + Assert.Equal("Untitled", item.Name); + Assert.Equal("No country", item.Country); + } + + [Fact] + public void TestForVirtualMethod() + { + var item = new Film(); + Assert.Equal("Virtual Method", item.VirtualView()); + } + } +} \ No newline at end of file diff --git a/CourseApp/PieceOfArt.cs b/CourseApp/PieceOfArt.cs index c72c895..0cfb5f9 100644 --- a/CourseApp/PieceOfArt.cs +++ b/CourseApp/PieceOfArt.cs @@ -24,5 +24,10 @@ public PieceOfArt(int prodYear, string name, string country) public abstract string Send(string toWho); public new abstract string ToString(); + + public virtual string VirtualView() + { + return "Virtual Method"; + } } } From 73257647b3137a2a9d09caaffc9bcbcab9bc09c0 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Mon, 16 Dec 2019 20:22:13 +0300 Subject: [PATCH 35/41] age calculation --- CourseApp/CalcAge.cs | 17 +++++++++++++++++ CourseApp/Program.cs | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 CourseApp/CalcAge.cs diff --git a/CourseApp/CalcAge.cs b/CourseApp/CalcAge.cs new file mode 100644 index 0000000..9865755 --- /dev/null +++ b/CourseApp/CalcAge.cs @@ -0,0 +1,17 @@ +using System; + +namespace CourseApp +{ + public class CalcAge + { + private DateTime now = DateTime.Today; + + public string CalculateAge(int day, int month, int year) + { + var birthday = new DateTime(year, month, day); + var today = DateTime.Today; + var age = new DateTime(today.Ticks - birthday.Ticks); + return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней"; + } + } +} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index cb9854c..b116804 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -72,6 +72,9 @@ public static void Main(string[] args) Console.WriteLine($"y={item}"); } + var ageKostya = new CalcAge(); + Console.WriteLine(ageKostya.CalculateAge(28, 6, 2000)); + Console.ReadLine(); } } From db2f14c12625547ff31816c8c2bdfa6228e5d844 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Mon, 16 Dec 2019 22:00:09 +0300 Subject: [PATCH 36/41] Tests for age calculation --- CourseApp.Tests/CalcAgeTest.cs | 46 ++++++++++++++++++++++++++++++++++ CourseApp/CalcAge.cs | 11 ++++++++ 2 files changed, 57 insertions(+) create mode 100644 CourseApp.Tests/CalcAgeTest.cs diff --git a/CourseApp.Tests/CalcAgeTest.cs b/CourseApp.Tests/CalcAgeTest.cs new file mode 100644 index 0000000..713df01 --- /dev/null +++ b/CourseApp.Tests/CalcAgeTest.cs @@ -0,0 +1,46 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class CalcAgeTest + { + [Fact] + public void CorrectAgeInputTest() + { + var yeah = new CalcAge(); + Assert.Equal(yeah.CalculateAge(2, 3, 2000), $"Возраст:19 лет, 9 месяцев, 15 дней"); + } + + [Fact] + public void FutureDateInputTest() + { + var time = new CalcAge(); + try + { + Assert.Equal(time.CalculateAge(16, 12, 2020), $"Возраст:19 лет, 5 месяцев, 19 дней"); + } + catch + { + Assert.True(true); + } + } + + [Fact] + public void CurrentDayIsBirthdayTest() + { + var time = new CalcAge(); + var day = DateTime.Today.Day; + var month = DateTime.Today.Month; + var year = DateTime.Today.Year; + try + { + Assert.Equal(time.CalculateAge(day, month, year), $"Возраст:0 лет, 0 месяцев, 0 дней"); + } + catch + { + Assert.True(true); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/CalcAge.cs b/CourseApp/CalcAge.cs index 9865755..d4d773a 100644 --- a/CourseApp/CalcAge.cs +++ b/CourseApp/CalcAge.cs @@ -10,8 +10,19 @@ public string CalculateAge(int day, int month, int year) { var birthday = new DateTime(year, month, day); var today = DateTime.Today; + if (birthday.Ticks > now.Ticks) + { + throw new Exception("you cannot enter a date that did not occur"); + } + else if (birthday.Ticks == now.Ticks) + { + throw new Exception("he/she/you was born today"); + } + else + { var age = new DateTime(today.Ticks - birthday.Ticks); return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней"; + } } } } From b2ce0a5cd3c282f1d44a09d8b03753050b99ef93 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Tue, 17 Dec 2019 16:00:22 +0300 Subject: [PATCH 37/41] +1(2) test for CalcAge --- CourseApp.Tests/CalcAgeTest.cs | 15 ++++++++++++--- CourseApp/CalcAge.cs | 13 ++++++++++--- CourseApp/Program.cs | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/CourseApp.Tests/CalcAgeTest.cs b/CourseApp.Tests/CalcAgeTest.cs index 713df01..16e9f69 100644 --- a/CourseApp.Tests/CalcAgeTest.cs +++ b/CourseApp.Tests/CalcAgeTest.cs @@ -9,7 +9,7 @@ public class CalcAgeTest public void CorrectAgeInputTest() { var yeah = new CalcAge(); - Assert.Equal(yeah.CalculateAge(2, 3, 2000), $"Возраст:19 лет, 9 месяцев, 15 дней"); + Assert.Equal(yeah.CalculateAge(2, 3, 2000, true), $"Возраст:19 лет, 9 месяцев, 16 дней"); } [Fact] @@ -18,7 +18,7 @@ public void FutureDateInputTest() var time = new CalcAge(); try { - Assert.Equal(time.CalculateAge(16, 12, 2020), $"Возраст:19 лет, 5 месяцев, 19 дней"); + Assert.Equal(time.CalculateAge(16, 12, 2020, true), $"Возраст:19 лет, 5 месяцев, 19 дней"); } catch { @@ -35,12 +35,21 @@ public void CurrentDayIsBirthdayTest() var year = DateTime.Today.Year; try { - Assert.Equal(time.CalculateAge(day, month, year), $"Возраст:0 лет, 0 месяцев, 0 дней"); + Assert.Equal(time.CalculateAge(day, month, year, true), $"Возраст:0 лет, 0 месяцев, 0 дней"); } catch { Assert.True(true); } } + + [Theory] + [InlineData(30, 12, 2000, 18)] + [InlineData(16, 12, 2000, 19)] + public void CurrectYearCountTest(int d, int m, int y, int exp) + { + var time = new CalcAge(); + Assert.Equal($"Возраст:{exp} лет", time.CalculateAge(d, m, y, false)); + } } } \ No newline at end of file diff --git a/CourseApp/CalcAge.cs b/CourseApp/CalcAge.cs index d4d773a..e2e1cde 100644 --- a/CourseApp/CalcAge.cs +++ b/CourseApp/CalcAge.cs @@ -6,7 +6,7 @@ public class CalcAge { private DateTime now = DateTime.Today; - public string CalculateAge(int day, int month, int year) + public string CalculateAge(int day, int month, int year, bool fullAge) { var birthday = new DateTime(year, month, day); var today = DateTime.Today; @@ -20,8 +20,15 @@ public string CalculateAge(int day, int month, int year) } else { - var age = new DateTime(today.Ticks - birthday.Ticks); - return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней"; + var age = new DateTime(today.Ticks - birthday.Ticks); + if (fullAge == true) + { + return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней"; + } + else + { + return $"Возраст:{age.Year - 1} лет"; + } } } } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index b116804..7791933 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -73,7 +73,7 @@ public static void Main(string[] args) } var ageKostya = new CalcAge(); - Console.WriteLine(ageKostya.CalculateAge(28, 6, 2000)); + Console.WriteLine(ageKostya.CalculateAge(28, 6, 2000, true)); Console.ReadLine(); } From b52e192f58141b1b12c9042ed932a0d8e3c4a3c1 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Fri, 20 Dec 2019 00:06:39 +0300 Subject: [PATCH 38/41] rewrite age method and tests --- CourseApp.Tests/CalcAgeTest.cs | 8 ++++---- CourseApp/CalcAge.cs | 8 +++++++- CourseApp/Program.cs | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CourseApp.Tests/CalcAgeTest.cs b/CourseApp.Tests/CalcAgeTest.cs index 16e9f69..0ee0165 100644 --- a/CourseApp.Tests/CalcAgeTest.cs +++ b/CourseApp.Tests/CalcAgeTest.cs @@ -9,7 +9,7 @@ public class CalcAgeTest public void CorrectAgeInputTest() { var yeah = new CalcAge(); - Assert.Equal(yeah.CalculateAge(2, 3, 2000, true), $"Возраст:19 лет, 9 месяцев, 16 дней"); + Assert.Equal(yeah.CalculateAge(DateTime.Now.Day - 15, DateTime.Now.Month - 9, DateTime.Now.Year - 19, true, true), $"Возраст:19 лет, 9 месяцев, 16 дней"); } [Fact] @@ -18,7 +18,7 @@ public void FutureDateInputTest() var time = new CalcAge(); try { - Assert.Equal(time.CalculateAge(16, 12, 2020, true), $"Возраст:19 лет, 5 месяцев, 19 дней"); + Assert.Equal(time.CalculateAge(16, 12, DateTime.Now.Year + 3, true, false), $"Возраст:19 лет, 5 месяцев, 19 дней"); } catch { @@ -35,7 +35,7 @@ public void CurrentDayIsBirthdayTest() var year = DateTime.Today.Year; try { - Assert.Equal(time.CalculateAge(day, month, year, true), $"Возраст:0 лет, 0 месяцев, 0 дней"); + Assert.Equal(time.CalculateAge(day, month, year, true, false), $"Возраст:0 лет, 0 месяцев, 0 дней"); } catch { @@ -49,7 +49,7 @@ public void CurrentDayIsBirthdayTest() public void CurrectYearCountTest(int d, int m, int y, int exp) { var time = new CalcAge(); - Assert.Equal($"Возраст:{exp} лет", time.CalculateAge(d, m, y, false)); + Assert.Equal($"Возраст:{exp} лет", time.CalculateAge(d, m, y, false, false)); } } } \ No newline at end of file diff --git a/CourseApp/CalcAge.cs b/CourseApp/CalcAge.cs index e2e1cde..8179de3 100644 --- a/CourseApp/CalcAge.cs +++ b/CourseApp/CalcAge.cs @@ -6,10 +6,16 @@ public class CalcAge { private DateTime now = DateTime.Today; - public string CalculateAge(int day, int month, int year, bool fullAge) + public string CalculateAge(int day, int month, int year, bool fullAge, bool currentTime) { var birthday = new DateTime(year, month, day); var today = DateTime.Today; + + if (currentTime == false) + { + today = new DateTime(2019, 12, 19); + } + if (birthday.Ticks > now.Ticks) { throw new Exception("you cannot enter a date that did not occur"); diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 7791933..4061dc5 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -73,7 +73,7 @@ public static void Main(string[] args) } var ageKostya = new CalcAge(); - Console.WriteLine(ageKostya.CalculateAge(28, 6, 2000, true)); + Console.WriteLine(ageKostya.CalculateAge(28, 6, 2000, true, true)); Console.ReadLine(); } From daf7caa2544bec27eb13896e8cb020c8d9a0aaf1 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 26 Dec 2019 18:55:56 +0300 Subject: [PATCH 39/41] Rewrited AgeCalc for overload --- CourseApp.Tests/CalcAgeTest.cs | 8 ++++---- CourseApp/CalcAge.cs | 28 +++++++++++++++++++++++++--- CourseApp/Program.cs | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CourseApp.Tests/CalcAgeTest.cs b/CourseApp.Tests/CalcAgeTest.cs index 0ee0165..2698f60 100644 --- a/CourseApp.Tests/CalcAgeTest.cs +++ b/CourseApp.Tests/CalcAgeTest.cs @@ -9,7 +9,7 @@ public class CalcAgeTest public void CorrectAgeInputTest() { var yeah = new CalcAge(); - Assert.Equal(yeah.CalculateAge(DateTime.Now.Day - 15, DateTime.Now.Month - 9, DateTime.Now.Year - 19, true, true), $"Возраст:19 лет, 9 месяцев, 16 дней"); + Assert.Equal(yeah.CalculateAge(12, 3, 2000, 19, 12, 2019, true), $"Возраст:19 лет, 9 месяцев, 8 дней"); } [Fact] @@ -18,7 +18,7 @@ public void FutureDateInputTest() var time = new CalcAge(); try { - Assert.Equal(time.CalculateAge(16, 12, DateTime.Now.Year + 3, true, false), $"Возраст:19 лет, 5 месяцев, 19 дней"); + Assert.Equal(time.CalculateAge(16, 6, 2021, 19, 12, 2019, true), $"Возраст:19 лет, 5 месяцев, 19 дней"); } catch { @@ -35,7 +35,7 @@ public void CurrentDayIsBirthdayTest() var year = DateTime.Today.Year; try { - Assert.Equal(time.CalculateAge(day, month, year, true, false), $"Возраст:0 лет, 0 месяцев, 0 дней"); + Assert.Equal(time.CalculateAge(12, 12, 2019, 12, 12, 2019, true), $"Возраст:0 лет, 0 месяцев, 0 дней"); } catch { @@ -49,7 +49,7 @@ public void CurrentDayIsBirthdayTest() public void CurrectYearCountTest(int d, int m, int y, int exp) { var time = new CalcAge(); - Assert.Equal($"Возраст:{exp} лет", time.CalculateAge(d, m, y, false, false)); + Assert.Equal($"Возраст:{exp} лет", time.CalculateAge(d, m, y, 19, 12, 2019, false)); } } } \ No newline at end of file diff --git a/CourseApp/CalcAge.cs b/CourseApp/CalcAge.cs index 8179de3..8e59a22 100644 --- a/CourseApp/CalcAge.cs +++ b/CourseApp/CalcAge.cs @@ -6,15 +6,37 @@ public class CalcAge { private DateTime now = DateTime.Today; - public string CalculateAge(int day, int month, int year, bool fullAge, bool currentTime) + public string CalculateAge(int day, int month, int year, bool fullAge) { var birthday = new DateTime(year, month, day); var today = DateTime.Today; - if (currentTime == false) + if (birthday.Ticks > now.Ticks) + { + throw new Exception("you cannot enter a date that did not occur"); + } + else if (birthday.Ticks == now.Ticks) { - today = new DateTime(2019, 12, 19); + throw new Exception("he/she/you was born today"); + } + else + { + var age = new DateTime(today.Ticks - birthday.Ticks); + if (fullAge == true) + { + return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней"; + } + else + { + return $"Возраст:{age.Year - 1} лет"; + } } + } + + public string CalculateAge(int day, int month, int year, int currDay, int currMonth, int currYear, bool fullAge) + { + var birthday = new DateTime(year, month, day); + var today = new DateTime(currYear, currMonth, currDay); if (birthday.Ticks > now.Ticks) { diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 4061dc5..7791933 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -73,7 +73,7 @@ public static void Main(string[] args) } var ageKostya = new CalcAge(); - Console.WriteLine(ageKostya.CalculateAge(28, 6, 2000, true, true)); + Console.WriteLine(ageKostya.CalculateAge(28, 6, 2000, true)); Console.ReadLine(); } From 37a6e0e2c080e75ae174a2ee1019fcc552a43018 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 26 Dec 2019 19:05:58 +0300 Subject: [PATCH 40/41] Rewrited test --- CourseApp.Tests/CalcAgeTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp.Tests/CalcAgeTest.cs b/CourseApp.Tests/CalcAgeTest.cs index 2698f60..aaae1a3 100644 --- a/CourseApp.Tests/CalcAgeTest.cs +++ b/CourseApp.Tests/CalcAgeTest.cs @@ -9,7 +9,7 @@ public class CalcAgeTest public void CorrectAgeInputTest() { var yeah = new CalcAge(); - Assert.Equal(yeah.CalculateAge(12, 3, 2000, 19, 12, 2019, true), $"Возраст:19 лет, 9 месяцев, 8 дней"); + Assert.Equal(yeah.CalculateAge(18, 12, 2000, 19, 12, 2019, true), $"Возраст:19 лет, 0 месяцев, 1 дней"); } [Fact] From 5d88c97215af03664a7e3b1adf64b5786ecea3c3 Mon Sep 17 00:00:00 2001 From: QinamruG <52399739+QinamruG@users.noreply.github.com> Date: Thu, 9 Jan 2020 11:40:35 +0300 Subject: [PATCH 41/41] Fixes --- CourseApp.Tests/CalcAgeTest.cs | 12 ++++-------- CourseApp/CalcAge.cs | 35 ++++++---------------------------- CourseApp/Program.cs | 3 +-- 3 files changed, 11 insertions(+), 39 deletions(-) diff --git a/CourseApp.Tests/CalcAgeTest.cs b/CourseApp.Tests/CalcAgeTest.cs index aaae1a3..652304f 100644 --- a/CourseApp.Tests/CalcAgeTest.cs +++ b/CourseApp.Tests/CalcAgeTest.cs @@ -8,17 +8,15 @@ public class CalcAgeTest [Fact] public void CorrectAgeInputTest() { - var yeah = new CalcAge(); - Assert.Equal(yeah.CalculateAge(18, 12, 2000, 19, 12, 2019, true), $"Возраст:19 лет, 0 месяцев, 1 дней"); + Assert.Equal(CalcAge.CalculateAge(18, 12, 2000, 19, 12, 2019, true), $"Возраст:19 лет, 0 месяцев, 1 дней"); } [Fact] public void FutureDateInputTest() { - var time = new CalcAge(); try { - Assert.Equal(time.CalculateAge(16, 6, 2021, 19, 12, 2019, true), $"Возраст:19 лет, 5 месяцев, 19 дней"); + CalcAge.CalculateAge(16, 6, 2021, true); } catch { @@ -29,13 +27,12 @@ public void FutureDateInputTest() [Fact] public void CurrentDayIsBirthdayTest() { - var time = new CalcAge(); var day = DateTime.Today.Day; var month = DateTime.Today.Month; var year = DateTime.Today.Year; try { - Assert.Equal(time.CalculateAge(12, 12, 2019, 12, 12, 2019, true), $"Возраст:0 лет, 0 месяцев, 0 дней"); + Assert.Equal(CalcAge.CalculateAge(12, 12, 2019, 12, 12, 2019, true), $"Возраст:0 лет, 0 месяцев, 0 дней"); } catch { @@ -48,8 +45,7 @@ public void CurrentDayIsBirthdayTest() [InlineData(16, 12, 2000, 19)] public void CurrectYearCountTest(int d, int m, int y, int exp) { - var time = new CalcAge(); - Assert.Equal($"Возраст:{exp} лет", time.CalculateAge(d, m, y, 19, 12, 2019, false)); + Assert.Equal($"Возраст:{exp} лет", CalcAge.CalculateAge(d, m, y, 19, 12, 2019, false)); } } } \ No newline at end of file diff --git a/CourseApp/CalcAge.cs b/CourseApp/CalcAge.cs index 8e59a22..d36928f 100644 --- a/CourseApp/CalcAge.cs +++ b/CourseApp/CalcAge.cs @@ -2,47 +2,24 @@ namespace CourseApp { - public class CalcAge + public static class CalcAge { - private DateTime now = DateTime.Today; - - public string CalculateAge(int day, int month, int year, bool fullAge) + public static string CalculateAge(int day, int month, int year, bool fullAge) { - var birthday = new DateTime(year, month, day); var today = DateTime.Today; - - if (birthday.Ticks > now.Ticks) - { - throw new Exception("you cannot enter a date that did not occur"); - } - else if (birthday.Ticks == now.Ticks) - { - throw new Exception("he/she/you was born today"); - } - else - { - var age = new DateTime(today.Ticks - birthday.Ticks); - if (fullAge == true) - { - return $"Возраст:{age.Year - 1} лет, {age.Month - 1} месяцев, {age.Day - 1} дней"; - } - else - { - return $"Возраст:{age.Year - 1} лет"; - } - } + return CalcAge.CalculateAge(day, month, year, today.Day, today.Month, today.Year, fullAge); } - public string CalculateAge(int day, int month, int year, int currDay, int currMonth, int currYear, bool fullAge) + public static string CalculateAge(int day, int month, int year, int currDay, int currMonth, int currYear, bool fullAge) { var birthday = new DateTime(year, month, day); var today = new DateTime(currYear, currMonth, currDay); - if (birthday.Ticks > now.Ticks) + if (birthday.Ticks > today.Ticks) { throw new Exception("you cannot enter a date that did not occur"); } - else if (birthday.Ticks == now.Ticks) + else if (birthday.Ticks == today.Ticks) { throw new Exception("he/she/you was born today"); } diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 7791933..dec4146 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -72,8 +72,7 @@ public static void Main(string[] args) Console.WriteLine($"y={item}"); } - var ageKostya = new CalcAge(); - Console.WriteLine(ageKostya.CalculateAge(28, 6, 2000, true)); + Console.WriteLine(CalcAge.CalculateAge(28, 6, 2000, true)); Console.ReadLine(); }