diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj new file mode 100644 index 0000000..419a3ae --- /dev/null +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -0,0 +1,29 @@ + + + netcoreapp2.0 + True + 1573,1591,1701;1702;1705 + false + + + + + + + + + + + + + + + ../stylecop/stylecop.ruleset + true + + + + + + + \ No newline at end of file diff --git a/CourseApp.Tests/UnitTest1.cs b/CourseApp.Tests/UnitTest1.cs new file mode 100644 index 0000000..cd95274 --- /dev/null +++ b/CourseApp.Tests/UnitTest1.cs @@ -0,0 +1,72 @@ +using System; +using Xunit; +using Matan; + +namespace CourseApp.Test +{ + public class UnitTest1 + { + [Fact] + public void Test1() + { + var res = Program.Y(0, 0, 0); + Assert.Equal(0, res); + } + + [Fact] + public void Test2() + { + var res = Program.Y(1, 0, 0); + Assert.Equal(double.NaN, res); + } + + [Fact] + public void Test3() + { + var res = Program.Y(1, 1, 0); + Assert.Equal(double.PositiveInfinity, res); + } + + [Fact] + public void Test4() + { + var res = Program.Y(5, 1, -8); + Assert.Equal(10.96, res, 2); + } + + [Fact] + public void Test5() + { + var res = Program.Y(2, 3, 0); + Assert.Equal(10.49, res, 2); + } + + [Fact] + public void Test6() + { + var res = Program.Y(0, 4, -9); + Assert.Equal(0, res); + } + + [Fact] + public void Test7() + { + var res = Program.Y(8, 2, 4); + Assert.Equal(6.38, res, 2); + } + + [Fact] + public void Test9() + { + var res = Program.Y(0, 3, 2); + Assert.Equal(0, res); + } + + [Fact] + public void Test10() + { + var res = Program.Y(0, 3, 3); + Assert.Equal(0, res); + } + } +} diff --git a/CourseApp.Tests/UnitTest2.cs b/CourseApp.Tests/UnitTest2.cs new file mode 100644 index 0000000..f65b05f --- /dev/null +++ b/CourseApp.Tests/UnitTest2.cs @@ -0,0 +1,63 @@ +using System; +using Xunit; +using Menu; + +namespace CourseApp.Tests +{ + public class UnitTest2 + { + [Fact] + public void Test1() + { + Dish salad = new Dish("Cesar", 500, "Salad", 250); + Assert.Equal("Cesar", salad.Name); + Assert.Equal(500, salad.Price); + Assert.Equal("Salad", salad.Type); + Assert.Equal(250, salad.Weight); + } + + [Fact] + public void Test2() + { + Dish soup = new Dish("chees", 250); + Assert.Equal("chees", soup.Name); + Assert.Equal(250, soup.Price); + } + + [Fact] + public void Test3() + { + Dish soup = new Dish("chees", -3); + Assert.Equal("chees", soup.Name); + Assert.Equal(0, soup.Price); + } + + [Fact] + public void Test4() + { + Dish soup = new Dish("Cesar", 20); + Assert.Equal("Cesar", soup.Name); + Assert.Equal(20, soup.Price); + } + + [Fact] + public void Test5() + { + Dish salad = new Dish("Paprica", 500, "Salad", -3); + Assert.Equal("Paprica", salad.Name); + Assert.Equal(500, salad.Price); + Assert.Equal("Salad", salad.Type); + Assert.Equal(0, salad.Weight); + } + + [Fact] + public void Test6() + { + Dish salad = new Dish("Cesar", -100, "rrrrrrrrr", 1000); + Assert.Equal("Cesar", salad.Name); + Assert.Equal(0, salad.Price); + Assert.Equal("NoType", salad.Type); + Assert.Equal(1000, salad.Weight); + } + } +} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 23df604..b26cc56 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,22 @@ Exe - netcoreapp2.1 + netcoreapp2.0 + True + 1573,1591,1701;1702;1705 + + + + + + ../stylecop/stylecop.ruleset + true + + + + + + diff --git a/CourseApp/CourseApp.sln b/CourseApp/CourseApp.sln new file mode 100644 index 0000000..f6325be --- /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.27428.2002 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp", "CourseApp.csproj", "{270747D2-1BE6-4FB6-AB36-C427275A74F3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CourseApp.Tests", "..\CourseApp.Tests\CourseApp.Tests.csproj", "{A8BE50E0-7D41-4C54-8B0E-1AA0AEE23645}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {270747D2-1BE6-4FB6-AB36-C427275A74F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {270747D2-1BE6-4FB6-AB36-C427275A74F3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {270747D2-1BE6-4FB6-AB36-C427275A74F3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {270747D2-1BE6-4FB6-AB36-C427275A74F3}.Release|Any CPU.Build.0 = Release|Any CPU + {A8BE50E0-7D41-4C54-8B0E-1AA0AEE23645}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8BE50E0-7D41-4C54-8B0E-1AA0AEE23645}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8BE50E0-7D41-4C54-8B0E-1AA0AEE23645}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8BE50E0-7D41-4C54-8B0E-1AA0AEE23645}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E01AD994-55CD-4736-AD2F-24B07F270089} + EndGlobalSection +EndGlobal diff --git a/CourseApp/Dish.cs b/CourseApp/Dish.cs new file mode 100644 index 0000000..cd0524e --- /dev/null +++ b/CourseApp/Dish.cs @@ -0,0 +1,55 @@ +using System; + +namespace Menu +{ + public class Dish + { + private int price; + private string type; + private int weight; + + public Dish(string name, int price, string type, int weight) + { + Name = name == string.Empty ? $"NoName" : name; + this.Price = price; + this.Type = type; + this.Weight = weight; + } + + public Dish(string name, int price) + : this(name, price, string.Empty, 0) + { + } + + public string Name { get; set; } + + public int Price + { + get => price; + set + { + price = value > 0 ? value : 0; + } + } + + public string Type + { + get => type; + set + { + type = value == $"Salad" ? value : $"NoType"; + } + } + + public int Weight + { + get => weight; + set + { + weight = value > 0 ? value : 0; + } + } + + public void GetInfo() => Console.WriteLine($": {Name} : {price} : {type} : {weight}"); + } +} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 3f81738..dffbd70 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,12 +1,45 @@ using System; +using Menu; -namespace CourseApp +namespace Matan { - class Program + public class Program { - static void Main(string[] args) + public static double Y(double x, double a, double b) { - Console.WriteLine("Hello World!"); + return Math.Sqrt(Math.Abs(a - (b * x)) / Math.Pow(Math.Log10(x), 3)); + } + + public static void Main(string[] args) + { + double a = 7.2; + double b = 4.2; + double xn = 1.81; + double xk = 5.31; + double dx = 0.7; + + double[] x = new double[5] { 2.4, 2.8, 3.9, 4.7, 3.16 }; + + Console.WriteLine("Задача A:"); + + for (double xl = xn; xl < xk; xl += dx) + { + Console.WriteLine($"Для x = {xl}\t y = {Y(xl, a, b):f3}"); + } + + Console.WriteLine("Задача B:"); + + foreach (double i in x) + { + Console.WriteLine($"Для x = {i}\t y = {Y(i, a, b):f3}"); + } + + Dish salad = new Dish("Cesar", 500, "Salad", 250); + Dish soup = new Dish("chees", 250); + salad.GetInfo(); + soup.GetInfo(); + + Console.ReadKey(); } } -} +} \ No newline at end of file diff --git a/README.md b/README.md index ee1aa8c..75a7100 100644 --- a/README.md +++ b/README.md @@ -1,3 +1 @@ -# Course of c# - -Please write your name and surname here \ No newline at end of file + diff --git a/WebApplication (1).7z b/WebApplication (1).7z new file mode 100644 index 0000000..528a7d7 Binary files /dev/null and b/WebApplication (1).7z differ diff --git a/stylecop/stylecop.json b/stylecop/stylecop.json new file mode 100644 index 0000000..643b8c1 --- /dev/null +++ b/stylecop/stylecop.json @@ -0,0 +1,15 @@ +{ + "$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 + } + }, + "additionalArguments": ["./stylecop.ruleset", "./stylecop.json"] +} diff --git a/stylecop/stylecop.ruleset b/stylecop/stylecop.ruleset new file mode 100644 index 0000000..3350d0e --- /dev/null +++ b/stylecop/stylecop.ruleset @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file