From 29ce50c1d8f92a0d0bb4c464dd8766fe81abd514 Mon Sep 17 00:00:00 2001 From: mahaikova Date: Sat, 23 Nov 2019 13:46:59 +0400 Subject: [PATCH 1/3] Added initial lab --- CourseApp/Program.cs | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 6a05310..7cc97a8 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -28,7 +28,7 @@ public static double[] TaskB(double a, double b, double[] x) public static void Main(string[] args) { - Console.WriteLine("Hello World!"); + Console.WriteLine("Nikita_Bogomazov"); const double a = 2.2; const double b = 3.8; var resSingle = MyFunction(a, b, 4); diff --git a/README.md b/README.md index 02c3f27..965104c 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# Tprogramming_42_2019 \ No newline at end of file +# Nikita Bogomazov \ No newline at end of file From 879238f22a7696439a45726426f8492e3eab0566 Mon Sep 17 00:00:00 2001 From: mahaikova Date: Mon, 16 Dec 2019 09:34:48 +0400 Subject: [PATCH 2/3] Added initial lab --- .vscode/launch.json | 7 ++++ CourseApp.Tests/CourseApp.Tests.csproj | 2 +- CourseApp.Tests/DemoTest.cs | 37 +++++++++++++++----- CourseApp/CourseApp.csproj | 2 +- CourseApp/Program.cs | 47 ++++++++++++++++++-------- 5 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..655f330 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Используйте IntelliSense, чтобы узнать о возможных атрибутах. + // Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов. + // Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 668406b..58dffa3 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp2.0 True 1573,1591,1701;1702;1705 false diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index 61ea75a..6cb56ca 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using Xunit; namespace CourseApp.Tests @@ -8,17 +9,37 @@ public class DemoTest [Fact] public void Test1() { - Assert.True(true); + Xunit.Assert.True(true); } [Theory] - [InlineData(0, 0, 0, 0)] - [InlineData(0, 2, 1, 2)] - [InlineData(1, 2, 1, 3)] - public void TestFunctionCalculationVal(double a, double b, double x, double exp) + [InlineData(2.0, 3.0, 0.11, 0.36, 0.05)] + public void TestElementsA(double a, double b, double xn, double xk, double dx) { - var res = Program.MyFunction(a, b, x); - Assert.Equal(exp, res, 3); + var res = Program.TaskA(a, b, xn, xk, dx); + ArrayList list = new ArrayList() { a, b, xn, xk, dx }; + double massElemExpected = (xk - xn) / dx; + Xunit.Assert.Equal(massElemExpected, list.Count); + } + + [Fact] + public void TestTaskBNullMass() + { + var mass = new double[0]; + var res = Program.TaskB(1, 2, mass); + Xunit.Assert.Equal(mass, res); + } + + [Fact] + public void TestTaskB() + { + var x = new double[] { 0.08, 0.26, 0.35, 0.41, 0.53 }; + var res = Program.TaskB(2.0, 3.0, x); + var expy = new double[] { 1.576684370464, 1.62087101387868, 1.65071664516254, 1.67072256986309, 1.70609554498699 }; + for (int i = 0; i < 5; i++) + { + Xunit.Assert.Equal(expy[i], res[i], 3); + } } } -} +} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index ac43c7c..84f4c46 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp2.0 True 1573,1591,1701;1702;1705; diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index 7cc97a8..ee99dfc 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -4,15 +4,23 @@ namespace CourseApp { public class Program { - public static double MyFunction(double a, double b, double x) + public static double MyFunction(double a, double b, double x) { - var y = (a * Math.Pow(x, 2)) + (b * x); + var y = Math.Asin(Math.Pow(x, a)) + Math.Acos(Math.Pow(x, b)); return y; } public static double[] TaskA(double a, double b, double xn, double xk, double dx) { - return new double[0]; + int i = 0; + var y = new double[(int)((xk - xn) / dx)]; + for (double 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) @@ -20,7 +28,7 @@ public static double[] TaskB(double a, double b, double[] x) var y = new double[x.Length]; for (var i = 0; i < x.Length; i++) { - y[i] = MyFunction(a, b, x[i]); + y[i] = MyFunction(a, b, x[i]); } return y; @@ -28,19 +36,28 @@ public static double[] TaskB(double a, double b, double[] x) public static void Main(string[] args) { - Console.WriteLine("Nikita_Bogomazov"); - const double a = 2.2; - const double b = 3.8; - var resSingle = MyFunction(a, b, 4); - Console.WriteLine(resSingle); - var x = new double[] { 1, 2, 3, 4, 5 }; - var taskBRes = TaskB(a, b, x); - foreach (var item in taskBRes) + const double a = 2.0; + const double b = 3.0; + const double xn = 0.11; + const double xk = 0.36; + const double dx = 0.05; + double count = xn; + Console.WriteLine("Task A:"); + foreach (var i in TaskA(a, b, xn, xk, dx)) + { + Console.WriteLine($"x = {count += dx}, y = {i}"); + } + + Console.WriteLine(); + var x = new double[] { 0.08, 0.26, 0.35, 0.41, 0.53 }; + count = 0; + Console.WriteLine("Task B:"); + foreach (var i in TaskB(a, b, x)) { - Console.WriteLine($"y = {item}"); + Console.WriteLine($"x = {x[(int)count++]}, y = {i}"); } - Console.ReadLine(); + Console.ReadKey(); } } -} +} \ No newline at end of file From c70b9a6757e21798a57f5d3c7bd25cf6e2126081 Mon Sep 17 00:00:00 2001 From: User of A309 Date: Mon, 23 Dec 2019 09:29:04 +0400 Subject: [PATCH 3/3] Added Test --- CourseApp.Tests/DemoTest.cs | 12 ++++++++++-- CourseApp/.vscode/launch.json | 1 + CourseApp/Program.cs | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs index 6cb56ca..8edc16f 100644 --- a/CourseApp.Tests/DemoTest.cs +++ b/CourseApp.Tests/DemoTest.cs @@ -1,5 +1,6 @@ using System; using System.Collections; +using System.Collections.Generic; using Xunit; namespace CourseApp.Tests @@ -12,6 +13,13 @@ public void Test1() Xunit.Assert.True(true); } + [Fact] + public void TestMyFunctionZeros() + { + var res = Program.MyFunction(1.0, 0.0, 0.0); + Xunit.Assert.Equal(0, res); + } + [Theory] [InlineData(2.0, 3.0, 0.11, 0.36, 0.05)] public void TestElementsA(double a, double b, double xn, double xk, double dx) @@ -25,7 +33,7 @@ public void TestElementsA(double a, double b, double xn, double xk, double dx) [Fact] public void TestTaskBNullMass() { - var mass = new double[0]; + List mass = new List(); var res = Program.TaskB(1, 2, mass); Xunit.Assert.Equal(mass, res); } @@ -33,7 +41,7 @@ public void TestTaskBNullMass() [Fact] public void TestTaskB() { - var x = new double[] { 0.08, 0.26, 0.35, 0.41, 0.53 }; + List x = new List { 0.08, 0.26, 0.35, 0.41, 0.53 }; var res = Program.TaskB(2.0, 3.0, x); var expy = new double[] { 1.576684370464, 1.62087101387868, 1.65071664516254, 1.67072256986309, 1.70609554498699 }; for (int i = 0; i < 5; i++) diff --git a/CourseApp/.vscode/launch.json b/CourseApp/.vscode/launch.json index cb90cf9..80c7e55 100644 --- a/CourseApp/.vscode/launch.json +++ b/CourseApp/.vscode/launch.json @@ -4,6 +4,7 @@ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ + { "name": ".NET Core Launch (console)", "type": "coreclr", diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index ee99dfc..4acedc7 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Collections; namespace CourseApp { @@ -10,25 +12,23 @@ public static double MyFunction(double a, double b, double x) return y; } - public static double[] TaskA(double a, double b, double xn, double xk, double dx) + public static List TaskA(double a, double b, double xn, double xk, double dx) { - int i = 0; - var y = new double[(int)((xk - xn) / dx)]; + List y = new List(); for (double x = xn; x < xk; x += dx) { - y[i] = MyFunction(a, b, x); - i++; + y.Add(MyFunction(a, b, x)); } return y; } - public static double[] TaskB(double a, double b, double[] x) + public static List TaskB(double a, double b, List x) { - var y = new double[x.Length]; - for (var i = 0; i < x.Length; i++) + List y = new List(); + for (var i = 0; i < x.Count; i++) { - y[i] = MyFunction(a, b, x[i]); + y.Add(MyFunction(a, b, x[i])); } return y; @@ -49,7 +49,7 @@ public static void Main(string[] args) } Console.WriteLine(); - var x = new double[] { 0.08, 0.26, 0.35, 0.41, 0.53 }; + List x = new List { 0.08, 0.26, 0.35, 0.41, 0.53 }; count = 0; Console.WriteLine("Task B:"); foreach (var i in TaskB(a, b, x))