From 11baa539634fd4b44173d5e745c642bbe2d46c01 Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Sat, 2 Oct 2021 11:51:49 +0300 Subject: [PATCH 1/9] PR ClassTask --- CourseApp.Tests/TestForCalculateTasks.cs | 26 --- CourseApp.Tests/TestForClassTask.cs | 2 +- .../CalculateTaskFolder/CalculateTasks.cs | 166 ------------------ .../{DocumentValue.cs => FileValues.cs} | 73 +++----- CourseApp/ConsoleInputOutput.cs | 116 ++++-------- 5 files changed, 62 insertions(+), 321 deletions(-) delete mode 100644 CourseApp.Tests/TestForCalculateTasks.cs delete mode 100644 CourseApp/CalculateTaskFolder/CalculateTasks.cs rename CourseApp/ClassTaskFolder/{DocumentValue.cs => FileValues.cs} (61%) diff --git a/CourseApp.Tests/TestForCalculateTasks.cs b/CourseApp.Tests/TestForCalculateTasks.cs deleted file mode 100644 index fa047174..00000000 --- a/CourseApp.Tests/TestForCalculateTasks.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace CourseApp.Tests -{ - using CourseApp.Calculate; - using Xunit; - using static System.Math; - - public class TestForCalculateTasks - { - [Theory] - [InlineData(0.11, 1.56)] - [InlineData(0.36, 1.488)] - [InlineData(0.08, 1.565)] - [InlineData(0.026, 1.57)] - [InlineData(0.35, 1.491)] - [InlineData(0.41, 1.471)] - [InlineData(0.51, 1.441)] - public void TestCalculate(double x, double expected) - { - var a = 3.0; - var b = 2.0; - var calculateTask = new CalculateTasks(); - var actual = calculateTask.CalculateValue(a, b, x); - Assert.Equal(expected, actual, 3); - } - } -} diff --git a/CourseApp.Tests/TestForClassTask.cs b/CourseApp.Tests/TestForClassTask.cs index cd339fa6..e15aec05 100644 --- a/CourseApp.Tests/TestForClassTask.cs +++ b/CourseApp.Tests/TestForClassTask.cs @@ -3,7 +3,7 @@ namespace CourseApp.Tests using CourseApp.Class; using Xunit; - public class TestForClassTask + public class TestForTask { [Theory] [InlineData("VSCode", ".exe", 1.56, "GB")] diff --git a/CourseApp/CalculateTaskFolder/CalculateTasks.cs b/CourseApp/CalculateTaskFolder/CalculateTasks.cs deleted file mode 100644 index ec5ca8cf..00000000 --- a/CourseApp/CalculateTaskFolder/CalculateTasks.cs +++ /dev/null @@ -1,166 +0,0 @@ -namespace CourseApp.Calculate -{ - using System; - using System.Collections.Generic; - using static System.Math; - - public class CalculateTasks - { - private double _startValue; - private double _endValue; - private double _deltaValue; - private double _aValue; - private double _bValue; - - public CalculateTasks() - { - AValue = 2.0; - BValue = 3.0; - StartValue = 0.11; - EndValue = 0.36; - DeltaValue = 0.05; - var listTaskOne = new List() { }; - var listTaskTwo = new List() { 0.08, 0.026, 0.35, 0.41, 0.51 }; - StartCalculate(listTaskOne, listTaskTwo); - } - - public CalculateTasks(double aValue, double bValue, double startValue, double endValue, double deltaValue) - { - AValue = aValue; - BValue = bValue; - StartValue = startValue; - EndValue = endValue; - DeltaValue = deltaValue; - var listTaskOne = new List() { }; - var listTaskTwo = new List() { 0.08, 0.026, 0.35, 0.41, 0.51 }; - StartCalculate(listTaskOne, listTaskTwo); - } - - public double StartValue - { - get - { - return _startValue; - } - - set - { - CheckValue(value); - _startValue = value; - } - } - - public double EndValue - { - get - { - return _endValue; - } - - set - { - CheckValue(value); - _endValue = value; - } - } - - public double DeltaValue - { - get - { - return _deltaValue; - } - - set - { - CheckValue(value); - _deltaValue = value; - } - } - - public double AValue - { - get - { - return _aValue; - } - - set - { - CheckValue(value); - _aValue = value; - } - } - - public double BValue - { - get - { - return _bValue; - } - - set - { - CheckValue(value); - _bValue = value; - } - } - - public string Output { get; set; } - - public (double, double) CalculateValue(double x) - { - var sin = Asin(Pow(x, AValue)); - var cos = Acos(Pow(x, BValue)); - return (x, sin + cos); - } - - public double CalculateValue(double a, double b, double x) - { - var sin = Asin(Pow(x, a)); - var cos = Acos(Pow(x, b)); - return sin + cos; - } - - private void WriteValueInString(double x) - { - var value = CalculateValue(x); - Output += $"x = {value.Item1:f2} y = {value.Item2:f2} | "; - } - - private void TaskOneList(List listTaskOne) - { - for (double x = StartValue; x <= EndValue; x += DeltaValue) - { - listTaskOne.Add(x); - } - } - - private void StartCalculate(List listTaskOne, List listTaskTwo) - { - TaskOneList(listTaskOne); - Output = "Task One: "; - foreach (double x in listTaskOne) - { - WriteValueInString(x); - } - - Console.WriteLine(Output); - Output = "Task Two: "; - foreach (double x in listTaskTwo) - { - WriteValueInString(x); - } - - Console.WriteLine(Output); - } - - private void CheckValue(double value) - { - if (value == double.NaN) - { - throw new Exception("Invalid value. Value is out of range."); - } - } - } -} \ No newline at end of file diff --git a/CourseApp/ClassTaskFolder/DocumentValue.cs b/CourseApp/ClassTaskFolder/FileValues.cs similarity index 61% rename from CourseApp/ClassTaskFolder/DocumentValue.cs rename to CourseApp/ClassTaskFolder/FileValues.cs index 970f4bef..3f5c533c 100644 --- a/CourseApp/ClassTaskFolder/DocumentValue.cs +++ b/CourseApp/ClassTaskFolder/FileValues.cs @@ -3,9 +3,31 @@ namespace CourseApp.Class using System; using static System.Math; - public class DocumentValue + public class FileValues { - public static int InputIntValue() + public string FileParam(string[] strValues) + { + Console.WriteLine("Chose:"); + ConsoleOutput(strValues); + return strValues[CheckIntInput(strValues.Length)]; + } + + public double Weight() + { + Console.WriteLine(" "); + Console.Write("Enter weight ( weight > 0 ): "); + return InputDoubleValue(); + } + + private void ConsoleOutput(string[] str) + { + for (int i = 0; i < str.Length; i++) + { + Console.WriteLine($"{str[i]} - {i + 1}"); + } + } + + private int InputIntValue() { var isNumber = false; var input = string.Empty; @@ -23,7 +45,7 @@ public static int InputIntValue() return inputValue; } - public static double InputDoubleValue() + private double InputDoubleValue() { var isNumber = false; var input = string.Empty; @@ -41,55 +63,14 @@ public static double InputDoubleValue() return inputValue; } - public string Name() - { - string[] name = { "isuct", "Funny", "Test", "Car", "Page", "IDE", "Game", "Video", "Music", "Work" }; - Console.WriteLine("Chose name:"); - ConsoleOutput(name); - return name[CheckIntInput(name)]; - } - - public string Extension() - { - string[] extension = { ".txt", ".pdf", ".jpg", ".cs", ".html", ".png", ".abb", ".mp3", ".mp4" }; - Console.WriteLine(" "); - Console.WriteLine("Chose extension:"); - ConsoleOutput(extension); - return extension[CheckIntInput(extension)]; - } - - public double Weight() - { - Console.WriteLine(" "); - Console.Write("Enter weight ( weight > 0 ): "); - return InputDoubleValue(); - } - - public string WeightModificator() - { - string[] weightModificator = { "B", "KB", "MB", "GB", "TB", "PB" }; - Console.WriteLine(" "); - Console.WriteLine("Chose weightModificator:"); - ConsoleOutput(weightModificator); - return weightModificator[CheckIntInput(weightModificator)]; - } - - private void ConsoleOutput(string[] str) - { - for (int i = 0; i < str.Length; i++) - { - Console.WriteLine($"{str[i]} - {i + 1}"); - } - } - - private int CheckIntInput(string[] str) + private int CheckIntInput(int strLength) { var input = 0; var isCorrectNumber = false; while (!isCorrectNumber) { input = InputIntValue(); - if (input > str.Length || input <= 0) + if (input > strLength || input <= 0) { Console.WriteLine("Value is out of range"); } diff --git a/CourseApp/ConsoleInputOutput.cs b/CourseApp/ConsoleInputOutput.cs index 9eabf90a..82e3f78e 100644 --- a/CourseApp/ConsoleInputOutput.cs +++ b/CourseApp/ConsoleInputOutput.cs @@ -1,124 +1,76 @@ namespace CourseApp { using System; - using CourseApp.Calculate; using CourseApp.Class; public class ConsoleInputOutput { - public int IntValue() - { - bool isNumber = false; - var input = string.Empty; - while (!isNumber) - { - input = Console.ReadLine(); - isNumber = int.TryParse(input, out int inputValue); - if (!isNumber) - { - Console.WriteLine("Please enter correct value"); - } - } - - return Convert.ToInt32(input); - } - - public double DoubleValue() - { - bool isNumber = false; - var input = string.Empty; - while (!isNumber) - { - input = Console.ReadLine(); - isNumber = double.TryParse(input, out double inputValue); - if (!isNumber) - { - Console.WriteLine("Please enter correct value"); - } - } - - return Convert.ToDouble(input); - } - public void StartProgram() { Console.Clear(); Console.WriteLine("Hello!"); - Console.WriteLine("This program can calculate tasks and create files with default or your values"); - Console.WriteLine("Calculate tasks - 1 | Create files - 2"); + Console.WriteLine("This program can create files with default or your params"); + Console.WriteLine("File with default params - 1 | File with your params - 2"); Console.WriteLine("What you want?"); - switch (IntValue()) - { - case 1: - { - Calculate(); - break; - } - - case 2: - { - Class(); - break; - } - } + Class(); } - private void Calculate() + private void Class() { - Console.Clear(); - Console.WriteLine("Calculate tasks"); - Console.WriteLine("Calculate with default values - 1 | Calculate with your values - 2"); + string[] name = { "isuct", "Funny", "Test", "Car", "Page", "IDE", "Game", "Video", "Music", "Work" }; + string[] extension = { ".txt", ".pdf", ".jpg", ".cs", ".html", ".png", ".abb", ".mp3", ".mp4" }; + string[] weightModificator = { "B", "KB", "MB", "GB", "TB", "PB" }; switch (IntValue()) { case 1: { Console.Clear(); - var task = new CalculateTasks(); + var task = new ClassTask(); break; } case 2: { - Console.WriteLine("Enter your values:"); - Console.Write("a = "); - var a = DoubleValue(); - Console.Write("b = "); - var b = DoubleValue(); - Console.Write("start = "); - var start = DoubleValue(); - Console.Write("end = "); - var end = DoubleValue(); - Console.Write("delta = "); - var delta = DoubleValue(); Console.Clear(); - var task = new CalculateTasks(a, b, start, end, delta); + var value = new FileValues(); + var task = new ClassTask(value.FileParam(name), value.FileParam(extension), value.Weight(), value.FileParam(weightModificator)); break; } } } - private void Class() + private int IntValue() { - Console.Clear(); - Console.WriteLine("Class tasks"); - Console.WriteLine("File with default values - 1 | File with your values - 2"); - switch (IntValue()) + bool isNumber = false; + var input = string.Empty; + while (!isNumber) { - case 1: + input = Console.ReadLine(); + isNumber = int.TryParse(input, out int inputValue); + if (!isNumber) { - Console.Clear(); - var task = new ClassTask(); - break; + Console.WriteLine("Please enter correct value"); } + } - case 2: + return Convert.ToInt32(input); + } + + private double DoubleValue() + { + bool isNumber = false; + var input = string.Empty; + while (!isNumber) + { + input = Console.ReadLine(); + isNumber = double.TryParse(input, out double inputValue); + if (!isNumber) { - Console.Clear(); - var value = new DocumentValue(); - var task = new ClassTask(value.Name(), value.Extension(), value.Weight(), value.WeightModificator()); - break; + Console.WriteLine("Please enter correct value"); } } + + return Convert.ToDouble(input); } } } \ No newline at end of file From 9bd1d486cdaa0b3ab098bb70fd7909338bf2756c Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Mon, 31 Jan 2022 09:31:19 +0300 Subject: [PATCH 2/9] Add Task, Class, Data, Zoo --- CourseApp.Tests/TestForClassTask.cs | 23 --- CourseApp.Tests/UnitTestsClass.cs | 22 +++ CourseApp.Tests/UnitTestsData.cs | 64 +++++++ CourseApp.Tests/UnitTestsInputValue.cs | 59 ++++++ CourseApp.Tests/UnitTestsTask.cs | 69 +++++++ CourseApp/.vscode/launch.json | 2 +- CourseApp/ClassTaskFolder/ClassTask.cs | 20 -- CourseApp/ClassTaskFolder/Document.cs | 39 ---- CourseApp/ClassTaskFolder/FileCreator.cs | 89 --------- CourseApp/ClassTaskFolder/FileValues.cs | 86 --------- CourseApp/ConsoleInputOutput.cs | 76 -------- CourseApp/CourseApp.csproj | 2 +- CourseApp/MainFileClass.cs | 21 +++ CourseApp/Program.cs | 14 -- .../1 - CalculateTask/CalculateTasks.cs | 79 ++++++++ .../1 - CalculateTask/TaskUserInterface.cs | 91 +++++++++ .../2 - ClassTask/ClassUserInterfaceClass.cs | 129 +++++++++++++ .../2 - ClassTask/Enums/EnumExtension.cs | 21 +++ .../Program/2 - ClassTask/Enums/EnumName.cs | 23 +++ .../Enums/EnumWeightModificator.cs | 12 ++ .../Program/2 - ClassTask/FileCreator.cs | 42 +++++ .../Program/3 - DateTask/DataUserInterface.cs | 173 ++++++++++++++++++ CourseApp/Program/3 - DateTask/DateClass.cs | 89 +++++++++ .../Program/4 - ZooTask/Abstract/Animal.cs | 21 +++ .../Program/4 - ZooTask/Abstract/People.cs | 15 ++ .../Program/4 - ZooTask/Abstract/Staff.cs | 18 ++ CourseApp/Program/4 - ZooTask/Animals/Bird.cs | 27 +++ CourseApp/Program/4 - ZooTask/Animals/Fish.cs | 27 +++ .../Program/4 - ZooTask/Animals/FourLegged.cs | 27 +++ .../4 - ZooTask/Interface/IDrawable.cs | 7 + .../4 - ZooTask/Interface/ZooUserInterface.cs | 20 ++ .../Program/4 - ZooTask/Objects/Building.cs | 25 +++ .../4 - ZooTask/Objects/InteriorObject.cs | 25 +++ .../Program/4 - ZooTask/Peoples/Employee.cs | 31 ++++ .../Program/4 - ZooTask/Peoples/Visitor.cs | 23 +++ CourseApp/Program/4 - ZooTask/Zoo.cs | 63 +++++++ CourseApp/Program/Input/CheckValues.cs | 43 +++++ CourseApp/Program/Input/InputValues.cs | 97 ++++++++++ courseworkspace.code-workspace | 8 +- 39 files changed, 1370 insertions(+), 352 deletions(-) delete mode 100644 CourseApp.Tests/TestForClassTask.cs create mode 100644 CourseApp.Tests/UnitTestsClass.cs create mode 100644 CourseApp.Tests/UnitTestsData.cs create mode 100644 CourseApp.Tests/UnitTestsInputValue.cs create mode 100644 CourseApp.Tests/UnitTestsTask.cs delete mode 100644 CourseApp/ClassTaskFolder/ClassTask.cs delete mode 100644 CourseApp/ClassTaskFolder/Document.cs delete mode 100644 CourseApp/ClassTaskFolder/FileCreator.cs delete mode 100644 CourseApp/ClassTaskFolder/FileValues.cs delete mode 100644 CourseApp/ConsoleInputOutput.cs create mode 100644 CourseApp/MainFileClass.cs delete mode 100644 CourseApp/Program.cs create mode 100644 CourseApp/Program/1 - CalculateTask/CalculateTasks.cs create mode 100644 CourseApp/Program/1 - CalculateTask/TaskUserInterface.cs create mode 100644 CourseApp/Program/2 - ClassTask/ClassUserInterfaceClass.cs create mode 100644 CourseApp/Program/2 - ClassTask/Enums/EnumExtension.cs create mode 100644 CourseApp/Program/2 - ClassTask/Enums/EnumName.cs create mode 100644 CourseApp/Program/2 - ClassTask/Enums/EnumWeightModificator.cs create mode 100644 CourseApp/Program/2 - ClassTask/FileCreator.cs create mode 100644 CourseApp/Program/3 - DateTask/DataUserInterface.cs create mode 100644 CourseApp/Program/3 - DateTask/DateClass.cs create mode 100644 CourseApp/Program/4 - ZooTask/Abstract/Animal.cs create mode 100644 CourseApp/Program/4 - ZooTask/Abstract/People.cs create mode 100644 CourseApp/Program/4 - ZooTask/Abstract/Staff.cs create mode 100644 CourseApp/Program/4 - ZooTask/Animals/Bird.cs create mode 100644 CourseApp/Program/4 - ZooTask/Animals/Fish.cs create mode 100644 CourseApp/Program/4 - ZooTask/Animals/FourLegged.cs create mode 100644 CourseApp/Program/4 - ZooTask/Interface/IDrawable.cs create mode 100644 CourseApp/Program/4 - ZooTask/Interface/ZooUserInterface.cs create mode 100644 CourseApp/Program/4 - ZooTask/Objects/Building.cs create mode 100644 CourseApp/Program/4 - ZooTask/Objects/InteriorObject.cs create mode 100644 CourseApp/Program/4 - ZooTask/Peoples/Employee.cs create mode 100644 CourseApp/Program/4 - ZooTask/Peoples/Visitor.cs create mode 100644 CourseApp/Program/4 - ZooTask/Zoo.cs create mode 100644 CourseApp/Program/Input/CheckValues.cs create mode 100644 CourseApp/Program/Input/InputValues.cs diff --git a/CourseApp.Tests/TestForClassTask.cs b/CourseApp.Tests/TestForClassTask.cs deleted file mode 100644 index e15aec05..00000000 --- a/CourseApp.Tests/TestForClassTask.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace CourseApp.Tests -{ - using CourseApp.Class; - using Xunit; - - public class TestForTask - { - [Theory] - [InlineData("VSCode", ".exe", 1.56, "GB")] - [InlineData("ISUCT", ".HTML", 0.79, "KB")] - [InlineData("Program", ".cs", 0.47, "B")] - [InlineData("Music", ".mp3", 1.56, "KB")] - [InlineData("Cat", ".exe", 1.56, "MB")] - [InlineData("Video", ".mov", 0.63, "TB")] - public void TestClass(string name, string extension, double weight, string weightModificator) - { - var expected = $"{name}{extension} {weight}{weightModificator}"; - Document file = new FileCreator(name, extension, weight, weightModificator); - var actual = file.Display(); - Assert.Equal(expected, actual); - } - } -} diff --git a/CourseApp.Tests/UnitTestsClass.cs b/CourseApp.Tests/UnitTestsClass.cs new file mode 100644 index 00000000..0a66f735 --- /dev/null +++ b/CourseApp.Tests/UnitTestsClass.cs @@ -0,0 +1,22 @@ +namespace CourseApp.Tests +{ + using Xunit; + + public class UnitTestsClass + { + [Theory] + [InlineData("VSCode", "Exe", "1.56", "GB")] + [InlineData("ISUCT", "HTML", "0.79", "KB")] + [InlineData("Program", "Cs", "0.47", "B")] + [InlineData("Music", "Mp3", "1.56", "KB")] + [InlineData("Cat", "Exe", "1.56", "MB")] + [InlineData("Video", "Mov", "0.63", "TB")] + public void TestClass(string name, string extension, string weight, string weightModificator) + { + var expected = $"{name}.{extension} {weight}{weightModificator}"; + var file = new FileCreator(name, extension, weight, weightModificator); + var actual = file.Display(); + Assert.Equal(expected, actual); + } + } +} diff --git a/CourseApp.Tests/UnitTestsData.cs b/CourseApp.Tests/UnitTestsData.cs new file mode 100644 index 00000000..3e84a5ac --- /dev/null +++ b/CourseApp.Tests/UnitTestsData.cs @@ -0,0 +1,64 @@ +namespace CourseApp.Tests +{ + using System; + using Xunit; + + public class UnitTestsData + { + [Theory] + [InlineData(2021, 10, 15, 2002, 4, 24, "19 5 21")] + [InlineData(2021, 10, 15, 2006, 4, 21, "15 5 24")] + [InlineData(2021, 10, 15, 2012, 5, 24, "9 4 21")] + public void TestAge(int todayYear, int todayMonth, int todayDay, int birthYear, int birthMonth, int birthDay, string expected) + { + DateTime birth = new DateTime(birthYear, birthMonth, birthDay); + DateTime today = new DateTime(todayYear, todayMonth, todayDay); + var dateClass = new DateClass(); + var date = dateClass.CalculateAge(birth, today); + var actual = $"{date.Item1} {date.Item2} {date.Item3}"; + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2021, 10, 15, 2002, 4, 24, "19 year`s 5 month`s 21 day ")] + [InlineData(2021, 10, 15, 2006, 4, 21, "15 year`s 5 month`s 24 day`s")] + [InlineData(2021, 10, 15, 2012, 5, 24, "9 year`s 4 month`s 21 day ")] + public void TestCreateOutputAge(int todayYear, int todayMonth, int todayDay, int birthYear, int birthMonth, int birthDay, string expected) + { + DateTime birth = new DateTime(birthYear, birthMonth, birthDay); + DateTime today = new DateTime(todayYear, todayMonth, todayDay); + var dateClass = new DateClass(); + var date = dateClass.CreateOutput(dateClass.CalculateAge(birth, today)); + var actual = $"{date.Item1} {date.Item2} {date.Item3}"; + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2021, 10, 15, 2002, 4, 24, "6 9")] + [InlineData(2021, 10, 15, 2006, 4, 21, "6 6")] + [InlineData(2021, 10, 15, 2012, 5, 24, "7 9")] + public void TestDaysToBirthDay(int todayYear, int todayMonth, int todayDay, int birthYear, int birthMonth, int birthDay, string expected) + { + DateTime birth = new DateTime(birthYear, birthMonth, birthDay); + DateTime today = new DateTime(todayYear, todayMonth, todayDay); + var dateClass = new DateClass(); + var date = dateClass.CalculateDaysToBirthDay(birth, today); + var actual = $"{date.Item1} {date.Item2}"; + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2021, 10, 15, 2002, 4, 24, "6 month`s 9 day`s to your birthDay")] + [InlineData(2021, 10, 15, 2006, 10, 15, " Happy birthDay!")] + [InlineData(2021, 10, 15, 2012, 10, 14, " 1 day from your birthDay")] + public void TestCreateOutputDaysToBirthDay(int todayYear, int todayMonth, int todayDay, int birthYear, int birthMonth, int birthDay, string expected) + { + DateTime birth = new DateTime(birthYear, birthMonth, birthDay); + DateTime today = new DateTime(todayYear, todayMonth, todayDay); + var dateClass = new DateClass(); + var date = dateClass.CreateOutput(dateClass.CalculateDaysToBirthDay(birth, today)); + var actual = $"{date.Item1} {date.Item2} {date.Item3}"; + Assert.Equal(expected, actual); + } + } +} diff --git a/CourseApp.Tests/UnitTestsInputValue.cs b/CourseApp.Tests/UnitTestsInputValue.cs new file mode 100644 index 00000000..58bd4680 --- /dev/null +++ b/CourseApp.Tests/UnitTestsInputValue.cs @@ -0,0 +1,59 @@ +namespace CourseApp.Tests +{ + using Xunit; + + public class UnitTestsInputValue + { + [Theory] + [InlineData(0, -1, 2, true)] + [InlineData(0, 1, 2, false)] + [InlineData(1, 0, 2, true)] + [InlineData(1, 1, 2, true)] + public void TestCheckValuesInputInt(int input, int min, int max, bool expected) + { + var check = new CheckValues(); + var actual = check.IsValidInt(input, min, max); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(0.1, -1, 2, true)] + [InlineData(0.5, 1, 2, false)] + [InlineData(1, 0, 2, true)] + [InlineData(1.2, 1, 2, true)] + public void TestCheckValuesInputDouble(double input, double min, double max, bool expected) + { + var check = new CheckValues(); + var actual = check.IsValidDouble(input, min, max); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("2", 0, 3, true)] + [InlineData("-1", 0, 3, false)] + [InlineData("r", 0, 3, false)] + [InlineData("-1.2", -2, -1, false)] + [InlineData("4.1", 4, 5, false)] + [InlineData(" ", 4, 4, false)] + public void TestInputInt(string item, int minValue, int maxValue, bool expected) + { + var input = new InputValues(); + var (_, actual) = input.InputInt(minValue, maxValue, item); + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData("0", 0, 3, true)] + [InlineData("-1.5", 0, 3, false)] + [InlineData("r", 0, 3, false)] + [InlineData("-1", -2, -1, true)] + [InlineData("4", 4, 5, true)] + [InlineData(" ", 4, 4, false)] + public void TestInputDouble(string item, int minValue, int maxValue, bool expected) + { + var input = new InputValues(); + var (_, actual) = input.InputDouble(minValue, maxValue, item); + Assert.Equal(expected, actual); + } + } +} diff --git a/CourseApp.Tests/UnitTestsTask.cs b/CourseApp.Tests/UnitTestsTask.cs new file mode 100644 index 00000000..a7e8a6c1 --- /dev/null +++ b/CourseApp.Tests/UnitTestsTask.cs @@ -0,0 +1,69 @@ +namespace CourseApp.Tests +{ + using System.Collections.Generic; + using Xunit; + using static System.Math; + + public class UnitTestsTask + { + [Theory] + [InlineData(3, 2, 0.11, 1.56)] + [InlineData(3, 2, 0.36, 1.488)] + [InlineData(3, 2, 0.08, 1.565)] + [InlineData(3, 2, 0.026, 1.57)] + [InlineData(3, 2, 0.35, 1.491)] + [InlineData(3, 2, 0.41, 1.471)] + [InlineData(3, 2, 0.51, 1.441)] + public void TestCalculate(double a, double b, double x, double expected) + { + var task = new CalculateTasks(a, b); + var (_, actual) = task.CalculateValue(x); + Assert.Equal(expected, actual, 3); + } + + [Theory] + [InlineData(0.1, 0.5, 0.1, 5)] + [InlineData(0, 5, 1, 6)] + [InlineData(0.25, 0.5, 0.05, 6)] + [InlineData(1.2, 2.4, 1.2, 2)] + public void TestListCount(double start, double end, double delta, int expected) + { + var task = new CalculateTasks(start, end, delta); + var actual = task.ListValue().Count; + Assert.Equal(expected, actual); + } + + [Theory] + [InlineData(2, 3, 0.1, 0.5, 0.1, new double[] { 1.58, 1.603, 1.634, 1.667, 1.698 })] + [InlineData(2, 3, 3, 9, 3, new double[] { double.NaN, double.NaN, double.NaN })] + [InlineData(2, 3, 0.5, 2.5, 0.5, new double[] { 1.698, 1.571, double.NaN, double.NaN, double.NaN })] + public void TestTaskOne(double a, double b, double start, double end, double delta, double[] expected) + { + var task = new CalculateTasks(a, b, start, end, delta); + var list = task.ListValue(); + var actual = new List(); + foreach (var item in list) + { + actual.Add(Round(task.CalculateValue(item).Item2, 3)); + } + + Assert.Equal(expected, actual.ToArray()); + } + + [Theory] + [InlineData(2, 3, new double[] { 1, 2, 3, 4 }, new double[] { 1.571, double.NaN, double.NaN, double.NaN })] + [InlineData(2, 3, new double[] { 0.1, 0.2, 0.3, 0.4 }, new double[] { 1.58, 1.603, 1.634, 1.667 })] + [InlineData(2, 3, new double[] { 0.5, 0.75, 0.8, 0.9 }, new double[] { 1.698, 1.733, 1.728, 1.698 })] + public void TestTaskTwo(double a, double b, double[] list, double[] expected) + { + var task = new CalculateTasks(a, b); + var actual = new List(); + foreach (var item in list) + { + actual.Add(Round(task.CalculateValue(item).Item2, 3)); + } + + Assert.Equal(expected, actual.ToArray()); + } + } +} diff --git a/CourseApp/.vscode/launch.json b/CourseApp/.vscode/launch.json index 1f5c1207..03bbd5f9 100644 --- a/CourseApp/.vscode/launch.json +++ b/CourseApp/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/netcoreapp2.1/CourseApp.dll", + "program": "${workspaceFolder}/bin/Debug/netcoreapp6.0/CourseApp.dll", "args": [], "cwd": "${workspaceFolder}", "console": "externalTerminal", diff --git a/CourseApp/ClassTaskFolder/ClassTask.cs b/CourseApp/ClassTaskFolder/ClassTask.cs deleted file mode 100644 index 30fae1a2..00000000 --- a/CourseApp/ClassTaskFolder/ClassTask.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace CourseApp.Class -{ - using System; - using System.Collections.Generic; - - public class ClassTask - { - public ClassTask(string name, string extension, double weight, string weightModificator) - { - Document file = new FileCreator(name, extension, weight, weightModificator); - Console.WriteLine($"Your file: {file.Display()}"); - } - - public ClassTask() - { - Document file = new FileCreator(); - Console.WriteLine($"Default file: {file.Display()}"); - } - } -} diff --git a/CourseApp/ClassTaskFolder/Document.cs b/CourseApp/ClassTaskFolder/Document.cs deleted file mode 100644 index 3ab0d928..00000000 --- a/CourseApp/ClassTaskFolder/Document.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace CourseApp.Class -{ - using System; - - public abstract class Document - { - private string _name; - - public Document(string name) - { - Name = name; - } - - public Document() - { - Name = "Program"; - } - - public string Name - { - get - { - return _name; - } - - set - { - if (string.IsNullOrEmpty(value)) - { - throw new Exception("Invalid name. Name can not be null or empty."); - } - - _name = value; - } - } - - public abstract string Display(); - } -} \ No newline at end of file diff --git a/CourseApp/ClassTaskFolder/FileCreator.cs b/CourseApp/ClassTaskFolder/FileCreator.cs deleted file mode 100644 index 992e316d..00000000 --- a/CourseApp/ClassTaskFolder/FileCreator.cs +++ /dev/null @@ -1,89 +0,0 @@ -namespace CourseApp.Class -{ - using System; - using static System.Math; - - public class FileCreator : Document - { - private string _extension; - private double _weight; - private string _weightModificator; - - public FileCreator(string name, string extension, double weight, string weightModificator) - : base(name) - { - Name = name; - Extension = extension; - Weight = weight; - WeightModificator = weightModificator; - } - - public FileCreator() - : base() - { - Extension = ".cs"; - Weight = 0.45; - WeightModificator = "B"; - } - - public string Extension - { - get - { - return _extension; - } - - set - { - if (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value)) - { - throw new Exception("Invalid extension. Extension can not be null or empty."); - } - - _extension = value; - } - } - - public double Weight - { - get - { - return _weight; - } - - set - { - if (value <= 0) - { - throw new Exception("Invalid weight. Weight can not be below zero."); - } - - _weight = value; - } - } - - public string WeightModificator - { - get - { - return _weightModificator; - } - - set - { - if (string.IsNullOrEmpty(value)) - { - throw new Exception("Invalid weightModificator. WeightModificator can not be null or empty."); - } - - _weightModificator = value; - } - } - - public override string Display() - { - Console.Clear(); - return $"{Name}{Extension} {Weight}{WeightModificator}"; - } - } -} \ No newline at end of file diff --git a/CourseApp/ClassTaskFolder/FileValues.cs b/CourseApp/ClassTaskFolder/FileValues.cs deleted file mode 100644 index 3f5c533c..00000000 --- a/CourseApp/ClassTaskFolder/FileValues.cs +++ /dev/null @@ -1,86 +0,0 @@ -namespace CourseApp.Class -{ - using System; - using static System.Math; - - public class FileValues - { - public string FileParam(string[] strValues) - { - Console.WriteLine("Chose:"); - ConsoleOutput(strValues); - return strValues[CheckIntInput(strValues.Length)]; - } - - public double Weight() - { - Console.WriteLine(" "); - Console.Write("Enter weight ( weight > 0 ): "); - return InputDoubleValue(); - } - - private void ConsoleOutput(string[] str) - { - for (int i = 0; i < str.Length; i++) - { - Console.WriteLine($"{str[i]} - {i + 1}"); - } - } - - private int InputIntValue() - { - var isNumber = false; - var input = string.Empty; - int inputValue = 0; - while (!isNumber) - { - input = Console.ReadLine(); - isNumber = int.TryParse(input, out inputValue); - if (!isNumber) - { - Console.WriteLine($"Value is incorrect. Please enter correct value!"); - } - } - - return inputValue; - } - - private double InputDoubleValue() - { - var isNumber = false; - var input = string.Empty; - double inputValue = 0; - while (!isNumber) - { - input = Console.ReadLine(); - isNumber = double.TryParse(input, out inputValue); - if (!isNumber) - { - Console.WriteLine($"Value is incorrect. Please enter correct value!"); - } - } - - return inputValue; - } - - private int CheckIntInput(int strLength) - { - var input = 0; - var isCorrectNumber = false; - while (!isCorrectNumber) - { - input = InputIntValue(); - if (input > strLength || input <= 0) - { - Console.WriteLine("Value is out of range"); - } - else - { - isCorrectNumber = true; - } - } - - return input; - } - } -} \ No newline at end of file diff --git a/CourseApp/ConsoleInputOutput.cs b/CourseApp/ConsoleInputOutput.cs deleted file mode 100644 index 82e3f78e..00000000 --- a/CourseApp/ConsoleInputOutput.cs +++ /dev/null @@ -1,76 +0,0 @@ -namespace CourseApp -{ - using System; - using CourseApp.Class; - - public class ConsoleInputOutput - { - public void StartProgram() - { - Console.Clear(); - Console.WriteLine("Hello!"); - Console.WriteLine("This program can create files with default or your params"); - Console.WriteLine("File with default params - 1 | File with your params - 2"); - Console.WriteLine("What you want?"); - Class(); - } - - private void Class() - { - string[] name = { "isuct", "Funny", "Test", "Car", "Page", "IDE", "Game", "Video", "Music", "Work" }; - string[] extension = { ".txt", ".pdf", ".jpg", ".cs", ".html", ".png", ".abb", ".mp3", ".mp4" }; - string[] weightModificator = { "B", "KB", "MB", "GB", "TB", "PB" }; - switch (IntValue()) - { - case 1: - { - Console.Clear(); - var task = new ClassTask(); - break; - } - - case 2: - { - Console.Clear(); - var value = new FileValues(); - var task = new ClassTask(value.FileParam(name), value.FileParam(extension), value.Weight(), value.FileParam(weightModificator)); - break; - } - } - } - - private int IntValue() - { - bool isNumber = false; - var input = string.Empty; - while (!isNumber) - { - input = Console.ReadLine(); - isNumber = int.TryParse(input, out int inputValue); - if (!isNumber) - { - Console.WriteLine("Please enter correct value"); - } - } - - return Convert.ToInt32(input); - } - - private double DoubleValue() - { - bool isNumber = false; - var input = string.Empty; - while (!isNumber) - { - input = Console.ReadLine(); - isNumber = double.TryParse(input, out double inputValue); - if (!isNumber) - { - Console.WriteLine("Please enter correct value"); - } - } - - return Convert.ToDouble(input); - } - } -} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index 260260d3..d5480420 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp2.1 + netcoreapp6.0 True diff --git a/CourseApp/MainFileClass.cs b/CourseApp/MainFileClass.cs new file mode 100644 index 00000000..a42140e2 --- /dev/null +++ b/CourseApp/MainFileClass.cs @@ -0,0 +1,21 @@ +namespace CourseApp +{ + using System; + + public class MainFileClass + { + public static void Main(string[] args) + { + var taskUserInterface = new TaskUserInterface(); + taskUserInterface.StartPage(); + var classUserInterface = new ClassUserInterfaceClass(); + classUserInterface.StartPage(); + var dataUserInterface = new DataUserInterface(); + dataUserInterface.StartPage(); + var zooUserInterface = new ZooUserInterface(); + var zoo = new Zoo("Moscow zoo"); + zooUserInterface.Draw(zoo); + Console.ReadLine(); + } + } +} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs deleted file mode 100644 index 656c4acb..00000000 --- a/CourseApp/Program.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace CourseApp -{ - using System; - - public class Program - { - public static void Main(string[] args) - { - var program = new ConsoleInputOutput(); - program.StartProgram(); - Console.ReadLine(); - } - } -} \ No newline at end of file diff --git a/CourseApp/Program/1 - CalculateTask/CalculateTasks.cs b/CourseApp/Program/1 - CalculateTask/CalculateTasks.cs new file mode 100644 index 00000000..4f4089a3 --- /dev/null +++ b/CourseApp/Program/1 - CalculateTask/CalculateTasks.cs @@ -0,0 +1,79 @@ +namespace CourseApp +{ + using System.Collections.Generic; + using static System.Math; + + public class CalculateTasks + { + public CalculateTasks(double aValue, double bValue, double startValue, double endValue, double deltaValue) + { + AValue = aValue; + BValue = bValue; + StartValue = startValue; + EndValue = endValue; + DeltaValue = deltaValue; + } + + public CalculateTasks(List listValues) + { + AValue = listValues[0]; + BValue = listValues[1]; + StartValue = listValues[2]; + EndValue = listValues[3]; + DeltaValue = listValues[4]; + } + + public CalculateTasks(double aValue, double bValue) + { + AValue = aValue; + BValue = bValue; + } + + public CalculateTasks(double startValue, double endValue, double deltaValue) + { + StartValue = startValue; + EndValue = endValue; + DeltaValue = deltaValue; + } + + public double StartValue { get; set; } + + public double EndValue { get; set; } + + public double DeltaValue { get; set; } + + public double AValue { get; set; } + + public double BValue { get; set; } + + public List<(double, double)> StartCalculate(List listValue) + { + var list = new List<(double, double)>(); + foreach (var x in listValue) + { + var value = CalculateValue(x); + list.Add(value); + } + + return list; + } + + public List ListValue() + { + var listValue = new List(); + for (var x = StartValue; x <= EndValue; x += DeltaValue) + { + listValue.Add(x); + } + + return listValue; + } + + public (double, double) CalculateValue(double x) + { + var sin = Asin(Pow(x, AValue)); + var cos = Acos(Pow(x, BValue)); + return (x, sin + cos); + } + } +} diff --git a/CourseApp/Program/1 - CalculateTask/TaskUserInterface.cs b/CourseApp/Program/1 - CalculateTask/TaskUserInterface.cs new file mode 100644 index 00000000..07d6914b --- /dev/null +++ b/CourseApp/Program/1 - CalculateTask/TaskUserInterface.cs @@ -0,0 +1,91 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class TaskUserInterface + { + public TaskUserInterface() + { + Console.WriteLine("Hello!"); + } + + public void StartPage() + { + var isEnabled = true; + while (isEnabled) + { + var input = new InputValues(); + var listValues = new List() { 0.08, 0.026, 0.35, 0.41, 0.51 }; + Console.WriteLine(@" + In this program you can: + 1 - Get calculating with default values + 2 - Get calculating with custom values + 3 - Exit program + What you want? Enter integer values."); + switch (input.InputInt(1, 3)) + { + case 1: + DefaultCalculations(listValues); + break; + + case 2: + CustomCalculations(listValues, InputCustomValues()); + break; + + case 3: + isEnabled = false; + break; + } + } + } + + private void DefaultCalculations(List listValues) + { + Console.Clear(); + var input = new InputValues(); + var task = new CalculateTasks(2.0, 3.0, 0.11, 0.36, 0.05); + Console.WriteLine($"Calculated with default values:"); + Output(task.StartCalculate(task.ListValue())); + Output(task.StartCalculate(listValues)); + } + + private void CustomCalculations(List listValues, List listCustomValues) + { + Console.Clear(); + var task = new CalculateTasks(listCustomValues); + Console.WriteLine($"Calculated with custom values:"); + Output(task.StartCalculate(task.ListValue())); + Output(task.StartCalculate(listValues)); + } + + private void Output(List<(double, double)> lst) + { + Console.WriteLine("Task:"); + foreach (var (x, y) in lst) + { + Console.WriteLine($" x = {x:f2} y = {y:f2}"); + } + } + + private List InputCustomValues() + { + Console.Clear(); + var input = new InputValues(); + var listCustomValues = new List(); + Console.WriteLine("Enter your values:"); + Console.Write("a = "); + listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); + Console.Write("b = "); + listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); + Console.Write("start = "); + listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); + Console.Write("end = "); + listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); + Console.Write("delta = "); + listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); + Console.Clear(); + return listCustomValues; + } + } +} diff --git a/CourseApp/Program/2 - ClassTask/ClassUserInterfaceClass.cs b/CourseApp/Program/2 - ClassTask/ClassUserInterfaceClass.cs new file mode 100644 index 00000000..3390ff08 --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/ClassUserInterfaceClass.cs @@ -0,0 +1,129 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class ClassUserInterfaceClass + { + public void StartPage() + { + var isEnabled = true; + while (isEnabled) + { + var input = new InputValues(); + Console.WriteLine(@" + In this program you can: + 1 - Get default file + 2 - Get custom file + 3 - Exit program + What you want? Enter integer values."); + switch (input.InputInt(1, 3)) + { + case 1: + DefaultFile(); + break; + + case 2: + CustomFile(); + break; + case 3: + isEnabled = false; + break; + } + } + } + + private void DefaultFile() + { + Console.Clear(); + var input = new InputValues(); + var file = new FileCreator("Program", "Cs", "0.34", "MB"); + Console.WriteLine($@"Default file: +{file.Display()}"); + } + + private void CustomFile() + { + Console.Clear(); + List customValues = InputCustomValues(); + while (customValues.Count != 4) + { + customValues = InputCustomValues(); + } + + var file = new FileCreator(customValues); + Console.WriteLine($"Custom file{file.Display()}"); + } + + private List InputCustomValues() + { + Console.Clear(); + var customValues = new List(); + customValues.Add(EnumValueName()); + customValues.Add(EnumValueExtension()); + customValues.Add(EnterValue()); + customValues.Add(EnumValueWeightModificator()); + Console.Clear(); + return customValues; + } + + private string EnumValueName() + { + Console.Clear(); + var name = string.Empty; + var input = new InputValues(); + var enumLength = Enum.GetNames(typeof(EnumName)).Length; + Console.WriteLine($"Choose avaible name. Enter integer values."); + for (int i = 0; i < enumLength; i++) + { + Console.WriteLine($"{i + 1} - {Enum.GetName(typeof(EnumName), i)}"); + } + + Console.WriteLine("Your variant:"); + var id = input.InputInt(1, enumLength) - 1; + name = Enum.GetName(typeof(EnumName), id); + return name; + } + + private string EnumValueExtension() + { + Console.Clear(); + var input = new InputValues(); + var enumLength = Enum.GetNames(typeof(EnumExtension)).Length; + Console.WriteLine($"Choose avaible extension. Enter integer values."); + for (var i = 0; i < enumLength; i++) + { + Console.WriteLine($"{i + 1} - {Enum.GetName(typeof(EnumExtension), i)}"); + } + + Console.WriteLine("Your variant:"); + var id = input.InputInt(1, enumLength) - 1; + return Enum.GetName(typeof(EnumExtension), id); + } + + private string EnumValueWeightModificator() + { + Console.Clear(); + var input = new InputValues(); + var enumLength = Enum.GetNames(typeof(EnumWeightModificator)).Length; + Console.WriteLine($"Choose avaible weightModificator. Enter integer values."); + for (var i = 0; i < enumLength; i++) + { + Console.WriteLine($"{i + 1} - {Enum.GetName(typeof(EnumWeightModificator), i)}"); + } + + Console.WriteLine("Your variant:"); + var id = input.InputInt(1, Enum.GetNames(typeof(EnumWeightModificator)).Length) - 1; + return Enum.GetName(typeof(EnumWeightModificator), id); + } + + private string EnterValue() + { + var input = new InputValues(); + Console.Clear(); + Console.WriteLine(@"Enter weight. Weight must be positive. Value range is (0.001 to 1023). +Your value:"); + return input.InputDouble(0.001, 1023).ToString(); + } + } +} diff --git a/CourseApp/Program/2 - ClassTask/Enums/EnumExtension.cs b/CourseApp/Program/2 - ClassTask/Enums/EnumExtension.cs new file mode 100644 index 00000000..8e2855ae --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/Enums/EnumExtension.cs @@ -0,0 +1,21 @@ +namespace CourseApp +{ + public enum EnumExtension + { + Txt, + Pdf, + Jpeg, + Cs, + Html, + Png, + Abb, + Mp3, + Mp4, + Apk, + Exe, + Tif, + Gif, + Jpg, + Bak, + } +} diff --git a/CourseApp/Program/2 - ClassTask/Enums/EnumName.cs b/CourseApp/Program/2 - ClassTask/Enums/EnumName.cs new file mode 100644 index 00000000..a120a421 --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/Enums/EnumName.cs @@ -0,0 +1,23 @@ +namespace CourseApp +{ + public enum EnumName + { + ISUCT, + Funny, + Test, + Car, + Page, + IDE, + Game, + Video, + Music, + Work, + Phone, + Note, + File, + Diploma, + Peoples, + IT, + CsharpCourse, + } +} \ No newline at end of file diff --git a/CourseApp/Program/2 - ClassTask/Enums/EnumWeightModificator.cs b/CourseApp/Program/2 - ClassTask/Enums/EnumWeightModificator.cs new file mode 100644 index 00000000..978cf337 --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/Enums/EnumWeightModificator.cs @@ -0,0 +1,12 @@ +namespace CourseApp +{ + public enum EnumWeightModificator + { + B, + KB, + MB, + GB, + TB, + PB, + } +} \ No newline at end of file diff --git a/CourseApp/Program/2 - ClassTask/FileCreator.cs b/CourseApp/Program/2 - ClassTask/FileCreator.cs new file mode 100644 index 00000000..80b0b97b --- /dev/null +++ b/CourseApp/Program/2 - ClassTask/FileCreator.cs @@ -0,0 +1,42 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class FileCreator + { + public FileCreator(string filename, string extension, string weight, string weightModificator) + { + FileName = filename; + Extension = extension; + Weight = weight; + WeightModificator = weightModificator; + } + + public FileCreator(List customValues) + { + if (customValues.Count != 4) + { + throw new NullReferenceException(); + } + + FileName = customValues[0]; + Extension = customValues[1]; + Weight = customValues[2]; + WeightModificator = customValues[3]; + } + + public string FileName { get; set; } + + public string Extension { get; set; } + + public string Weight { get; set; } + + public string WeightModificator { get; set; } + + public string Display() + { + return $"{FileName}.{Extension} {Weight}{WeightModificator}"; + } + } +} diff --git a/CourseApp/Program/3 - DateTask/DataUserInterface.cs b/CourseApp/Program/3 - DateTask/DataUserInterface.cs new file mode 100644 index 00000000..5b1ef4fe --- /dev/null +++ b/CourseApp/Program/3 - DateTask/DataUserInterface.cs @@ -0,0 +1,173 @@ +namespace CourseApp +{ + using System; + + public class DataUserInterface + { + public DataUserInterface() + { + Console.WriteLine("Hello!"); + IsValuesEnter = false; + } + + public bool IsValuesEnter { get; set; } + + public int Year { get; set; } + + public int Month { get; set; } + + public int Day { get; set; } + + public void StartPage() + { + var isEnabled = true; + while (isEnabled) + { + var input = new InputValues(); + Console.WriteLine(@" +Avaible actions: +1 - Set your birthDay +2 - Get your age +3 - Get date to your birthDay +4 - Exit program +What you want? Enter integer values."); + switch (input.InputInt(1, 4)) + { + case 1: + SetYourBirthDate(); + break; + + case 2: + GetAge(); + break; + + case 3: + GetDateToYourBirth(); + break; + + case 4: + isEnabled = false; + break; + } + } + } + + public void Output(string message) + { + switch (message) + { + case "days": + var days = Date(); + var line = string.Empty; + if (string.IsNullOrEmpty(days.Item1) && string.IsNullOrEmpty(days.Item2)) + { + line = $"{days.Item3}"; + } + + if (!string.IsNullOrEmpty(days.Item1) && !string.IsNullOrEmpty(days.Item2)) + { + line = $"{days.Item1}, {days.Item2} {days.Item3}"; + } + + if (string.IsNullOrEmpty(days.Item1) || string.IsNullOrEmpty(days.Item2)) + { + if (string.IsNullOrEmpty(days.Item1)) + { + line = $"{days.Item2} {days.Item3}"; + } + + if (string.IsNullOrEmpty(days.Item2)) + { + line = $"{days.Item1} {days.Item3}"; + } + } + + Console.WriteLine(line); + break; + + case "age": + var age = Age(); + Console.WriteLine($"Your age: {age.Item1}, {age.Item2} and {age.Item3}"); + break; + } + } + + private void SetYourBirthDate() + { + Console.Clear(); + var input = new InputValues(); + var today = DateTime.Now; + Console.WriteLine("Enter your birthday"); + Console.WriteLine("Year:"); + Year = input.InputInt(0001, today.Year); + Console.WriteLine("Month:"); + if (Year == today.Year) + { + Month = input.InputInt(1, today.Month); + } + else + { + Month = input.InputInt(1, 12); + } + + Console.WriteLine("Day:"); + if (Month == today.Month) + { + Day = input.InputInt(1, today.Day); + } + else + { + Day = input.InputInt(1, 31); + } + + IsValuesEnter = true; + Console.Clear(); + } + + private void GetAge() + { + Console.Clear(); + var input = new InputValues(); + if (IsValuesEnter) + { + Output("age"); + } + else + { + Console.WriteLine("You dont enter your birthDay!"); + } + } + + private void GetDateToYourBirth() + { + Console.Clear(); + var input = new InputValues(); + if (IsValuesEnter) + { + Output("days"); + } + else + { + Console.WriteLine("You dont enter your birthDay!"); + } + } + + private (string, string, string) Age() + { + var dateClass = new DateClass(); + var birthDay = new DateTime(Year, Month, Day); + var dateToday = DateTime.Today; + var date = dateClass.CreateOutput(dateClass.CalculateAge(birthDay, dateToday)); + return (date.Item1, date.Item2, date.Item3); + } + + private (string, string, string) Date() + { + var dateClass = new DateClass(); + var birthDay = new DateTime(Year, Month, Day); + var dateToday = DateTime.Today; + var date = dateClass.CreateOutput(dateClass.CalculateDaysToBirthDay(birthDay, dateToday)); + return (date.Item1, date.Item2, date.Item3); + } + } +} diff --git a/CourseApp/Program/3 - DateTask/DateClass.cs b/CourseApp/Program/3 - DateTask/DateClass.cs new file mode 100644 index 00000000..02499e9c --- /dev/null +++ b/CourseApp/Program/3 - DateTask/DateClass.cs @@ -0,0 +1,89 @@ +namespace CourseApp +{ + using System; + using static System.Math; + + public class DateClass + { + public (int, int, int) CalculateAge(DateTime birthDay, DateTime dateToday) + { + var months = dateToday.Month - birthDay.Month; + var years = dateToday.Year - birthDay.Year; + if (dateToday.Day < birthDay.Day) + { + months--; + } + + if (months < 0) + { + years--; + months += 12; + } + + var days = (dateToday - birthDay.AddMonths((years * 12) + months)).Days; + return (years, months, days); + } + + public (string, string, string) CreateOutput((int, int, int) age) + { + var years = $"{age.Item1} year{(age.Item1 % 10 == 1 ? " " : "`s")}"; + var months = $"{age.Item2} month{(age.Item2 % 10 == 1 ? " " : "`s")}"; + var days = $"{age.Item3} day{(age.Item3 % 10 == 1 ? " " : "`s")}"; + return (years, months, days); + } + + public (string, string, string) CreateOutput((int, int) age) + { + var months = string.Empty; + var days = string.Empty; + var mod = "Happy birthDay!"; + if (age.Item1 + age.Item2 != 0) + { + months = string.Empty; + days = string.Empty; + if (age.Item1 != 0) + { + months = $"{age.Item1} {(age.Item1 % 10 == 1 ? "month" : "month`s")}"; + mod = "to your birthDay"; + if (age.Item1 < 0) + { + months = $"{Abs(age.Item1)} {(Abs(age.Item1) % 10 == 1 ? "month" : "month`s")}"; + mod = "from your birthDay"; + } + } + + if (age.Item2 != 0) + { + days = $"{age.Item2} {(age.Item2 % 10 == 1 ? "day" : "day`s")}"; + mod = "to your birthDay"; + if (age.Item2 < 0) + { + days = $"{Abs(age.Item2)} {(Abs(age.Item2) % 10 == 1 ? "day" : "day`s")}"; + mod = "from your birthDay"; + } + } + } + + return (months, days, mod); + } + + public (int, int) CalculateDaysToBirthDay(DateTime birthDay, DateTime dateToday) + { + var months = birthDay.Month - dateToday.Month; + var years = birthDay.Year - dateToday.Year; + if (birthDay.Year < dateToday.Day) + { + months--; + } + + if (months < 0) + { + years--; + months += 12; + } + + var days = (birthDay - dateToday.AddMonths((years * 12) + months)).Days; + return (months, days); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Abstract/Animal.cs b/CourseApp/Program/4 - ZooTask/Abstract/Animal.cs new file mode 100644 index 00000000..a89b62b2 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Abstract/Animal.cs @@ -0,0 +1,21 @@ +namespace CourseApp +{ + public abstract class Animal + { + public Animal(string type, string size, int age, string ability) + { + Type = type; + Size = size; + Age = age; + Ability = ability; + } + + public string Type { get; set; } + + public string Size { get; set; } + + public int Age { get; set; } + + public string Ability { get; set; } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Abstract/People.cs b/CourseApp/Program/4 - ZooTask/Abstract/People.cs new file mode 100644 index 00000000..1ec8f57a --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Abstract/People.cs @@ -0,0 +1,15 @@ +namespace CourseApp +{ + public abstract class People + { + public People(string name, int age) + { + Name = name; + Age = age; + } + + public string Name { get; set; } + + public int Age { get; set; } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Abstract/Staff.cs b/CourseApp/Program/4 - ZooTask/Abstract/Staff.cs new file mode 100644 index 00000000..eb4691ad --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Abstract/Staff.cs @@ -0,0 +1,18 @@ +namespace CourseApp +{ + public abstract class Staff + { + public Staff(string type, string size, string material) + { + Type = type; + Size = size; + Material = material; + } + + public string Type { get; set; } + + public string Size { get; set; } + + public string Material { get; set; } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Animals/Bird.cs b/CourseApp/Program/4 - ZooTask/Animals/Bird.cs new file mode 100644 index 00000000..25489f50 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Animals/Bird.cs @@ -0,0 +1,27 @@ +namespace CourseApp +{ + using System; + + public class Bird : Animal, IDrawable + { + public Bird(string type, string size, int age, string ability) + : base(type, size, age, ability) + { + Type = type; + Size = size; + Age = age; + Ability = ability; + } + + public void Draw() + { + var information = @$" Class: Bird + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Age: {(Age <= 0 ? "none" : Age)}y + Ability: {(string.IsNullOrEmpty(Ability) ? "none" : Ability)} + "; + Console.WriteLine(information); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Animals/Fish.cs b/CourseApp/Program/4 - ZooTask/Animals/Fish.cs new file mode 100644 index 00000000..0a73384c --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Animals/Fish.cs @@ -0,0 +1,27 @@ +namespace CourseApp +{ + using System; + + public class Fish : Animal, IDrawable + { + public Fish(string type, string size, int age, string ability) + : base(type, size, age, ability) + { + Type = type; + Size = size; + Age = age; + Ability = ability; + } + + public void Draw() + { + var information = @$" Class: Fish + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Age: {(Age <= 0 ? "none" : Age)}y + Ability: {(string.IsNullOrEmpty(Ability) ? "none" : Ability)} + "; + Console.WriteLine(information); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Animals/FourLegged.cs b/CourseApp/Program/4 - ZooTask/Animals/FourLegged.cs new file mode 100644 index 00000000..b277064b --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Animals/FourLegged.cs @@ -0,0 +1,27 @@ +namespace CourseApp +{ + using System; + + public class FourLegged : Animal, IDrawable + { + public FourLegged(string type, string size, int age, string ability) + : base(type, size, age, ability) + { + Type = type; + Size = size; + Age = age; + Ability = ability; + } + + public void Draw() + { + var information = @$" Class: FourLegged + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Age: {(Age <= 0 ? "none" : Age)}y + Ability: {(string.IsNullOrEmpty(Ability) ? "none" : Ability)} + "; + Console.WriteLine(information); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Interface/IDrawable.cs b/CourseApp/Program/4 - ZooTask/Interface/IDrawable.cs new file mode 100644 index 00000000..c9062f60 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Interface/IDrawable.cs @@ -0,0 +1,7 @@ +namespace CourseApp +{ + public interface IDrawable + { + public void Draw(); + } +} diff --git a/CourseApp/Program/4 - ZooTask/Interface/ZooUserInterface.cs b/CourseApp/Program/4 - ZooTask/Interface/ZooUserInterface.cs new file mode 100644 index 00000000..78ea212c --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Interface/ZooUserInterface.cs @@ -0,0 +1,20 @@ +namespace CourseApp +{ + using System.Collections.Generic; + + public class ZooUserInterface + { + public void Draw(IDrawable obj) + { + obj.Draw(); + } + + public void Draw(List objects) + { + foreach (IDrawable obj in objects) + { + this.Draw(obj); + } + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Objects/Building.cs b/CourseApp/Program/4 - ZooTask/Objects/Building.cs new file mode 100644 index 00000000..98c1bc63 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Objects/Building.cs @@ -0,0 +1,25 @@ +namespace CourseApp +{ + using System; + + public class Building : Staff, IDrawable + { + public Building(string type, string size, string material) + : base(type, size, material) + { + Type = type; + Size = size; + Material = material; + } + + public void Draw() + { + var information = @$" Class: Building + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Material: {(string.IsNullOrEmpty(Material) ? "none" : Material)} + "; + Console.WriteLine(information); + } + } +} diff --git a/CourseApp/Program/4 - ZooTask/Objects/InteriorObject.cs b/CourseApp/Program/4 - ZooTask/Objects/InteriorObject.cs new file mode 100644 index 00000000..fb81340f --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Objects/InteriorObject.cs @@ -0,0 +1,25 @@ +namespace CourseApp +{ + using System; + + public class InteriorObject : Staff, IDrawable + { + public InteriorObject(string type, string size, string material) + : base(type, size, material) + { + Type = type; + Size = size; + Material = material; + } + + public void Draw() + { + var information = @$" Class: InteriorObject + Type: {(string.IsNullOrEmpty(Type) ? "none" : Type)} + Size: {(string.IsNullOrEmpty(Size) ? "none" : Size)} + Material: {(string.IsNullOrEmpty(Material) ? "none" : Material)} + "; + Console.WriteLine(information); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program/4 - ZooTask/Peoples/Employee.cs b/CourseApp/Program/4 - ZooTask/Peoples/Employee.cs new file mode 100644 index 00000000..05e34495 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Peoples/Employee.cs @@ -0,0 +1,31 @@ +namespace CourseApp +{ + using System; + + public class Employee : People, IDrawable + { + public Employee(string name, string post, int age, int salary) + : base(name, age) + { + Name = name; + Post = post; + Age = age; + Salary = salary; + } + + public int Salary { get; set; } + + public string Post { get; set; } + + public void Draw() + { + var information = @$" Class: Employee + Name: {(string.IsNullOrEmpty(Name) ? "none" : Name)} + Post: {(string.IsNullOrEmpty(Post) ? "none" : Post)} + Age: {(Age <= 0 ? "none" : Age)}y + Salary: {(string.IsNullOrEmpty(Salary.ToString()) ? "none" : Salary)}$ + "; + Console.WriteLine(information); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program/4 - ZooTask/Peoples/Visitor.cs b/CourseApp/Program/4 - ZooTask/Peoples/Visitor.cs new file mode 100644 index 00000000..34fc2789 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Peoples/Visitor.cs @@ -0,0 +1,23 @@ +namespace CourseApp +{ + using System; + + public class Visitor : People, IDrawable + { + public Visitor(string name, int age) + : base(name, age) + { + Name = name; + Age = age; + } + + public void Draw() + { + var information = @$" Class: Employee + Name: {(string.IsNullOrEmpty(Name) ? "none" : Name)} + Age: {(string.IsNullOrEmpty(Age.ToString()) ? "none" : Age)}y + "; + Console.WriteLine(information); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program/4 - ZooTask/Zoo.cs b/CourseApp/Program/4 - ZooTask/Zoo.cs new file mode 100644 index 00000000..d51e2453 --- /dev/null +++ b/CourseApp/Program/4 - ZooTask/Zoo.cs @@ -0,0 +1,63 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public class Zoo : IDrawable + { + public Zoo(string name) + { + Name = name; + } + + public string Name { get; set; } + + public void Draw() + { + var zooUserInterface = new ZooUserInterface(); + Console.WriteLine($"Zoo: {Name}"); + Console.WriteLine($"Animals:"); + zooUserInterface.Draw(Animals()); + Console.WriteLine($"Peoples:"); + zooUserInterface.Draw(Peoples()); + Console.WriteLine($"Objects:"); + zooUserInterface.Draw(Objects()); + } + + public List Animals() + { + var list = new List(); + list.Add(new Bird("Hummingbird", "Very small", 1, null)); + list.Add(new Bird("Eagle", "Small", 2, "Fly")); + list.Add(new FourLegged("Lion", "Medium", 5, null)); + list.Add(new FourLegged("Wolf", "Medium", 2, "Howl")); + list.Add(new Fish("Shark", "Big", 2, "Swim")); + list.Add(new Fish("Swordfish", "Medium", 3, "Swim")); + return list; + } + + public List Peoples() + { + var list = new List(); + list.Add(new Employee("Mike", "Director", 35, 0)); + list.Add(new Employee("Leo", "Сleaner", 56, 1300)); + list.Add(new Employee("Mark", "Worker", 0, 1300)); + list.Add(new Visitor("Stepa", 19)); + list.Add(new Visitor("Daniil", 11)); + list.Add(new Visitor("Gleb", 34)); + return list; + } + + public List Objects() + { + var list = new List(); + list.Add(new Building("Administration", "Big", null)); + list.Add(new Building("Toilet", "Small", "Wood")); + list.Add(new Building("Shop", "Medium", "Concrete")); + list.Add(new InteriorObject("Table", "Medium", "Wood")); + list.Add(new InteriorObject("Laptop", "Medium", null)); + list.Add(new InteriorObject("Char", null, null)); + return list; + } + } +} \ No newline at end of file diff --git a/CourseApp/Program/Input/CheckValues.cs b/CourseApp/Program/Input/CheckValues.cs new file mode 100644 index 00000000..7eae6ef4 --- /dev/null +++ b/CourseApp/Program/Input/CheckValues.cs @@ -0,0 +1,43 @@ +namespace CourseApp +{ + using System; + + public class CheckValues + { + public bool IsValidString(string item) + { + var isValidValue = true; + if (string.IsNullOrEmpty(item) || string.IsNullOrWhiteSpace(item)) + { + isValidValue = false; + Console.WriteLine("Value is null or empty or contains invalid characters or whitespace. Please enter correct value!"); + } + + return isValidValue; + } + + public bool IsValidInt(int item, int minValue, int maxValue) + { + var isValidValue = true; + if (item < minValue || item > maxValue) + { + Console.WriteLine($"Value ({item}) is out of range. Please enter correct value!"); + isValidValue = false; + } + + return isValidValue; + } + + public bool IsValidDouble(double item, double minValue, double maxValue) + { + var isValidValue = true; + if (item < minValue || item > maxValue) + { + Console.WriteLine($"Value ({item}) is out of range. Please enter correct value!"); + isValidValue = false; + } + + return isValidValue; + } + } +} diff --git a/CourseApp/Program/Input/InputValues.cs b/CourseApp/Program/Input/InputValues.cs new file mode 100644 index 00000000..e42b7c4c --- /dev/null +++ b/CourseApp/Program/Input/InputValues.cs @@ -0,0 +1,97 @@ +namespace CourseApp +{ + using System; + + public class InputValues + { + public string InputString() + { + var item = string.Empty; + var isCorrect = false; + var check = new CheckValues(); + while (!isCorrect) + { + item = Console.ReadLine(); + isCorrect = check.IsValidString(item); + } + + return item; + } + + public int InputInt(int maxValue) + { + return InputInt(0, maxValue); + } + + public int InputInt(int minValue, int maxValue) + { + var isCorrect = false; + var number = 0; + while (true) + { + var item = Console.ReadLine(); + (number, isCorrect) = InputInt(minValue, maxValue, item); + if (isCorrect) + { + break; + } + else + { + Console.WriteLine($"Please enter correct value!"); + } + } + + return number; + } + + public (int, bool) InputInt(int minValue, int maxValue, string item) + { + int intInput = 0; + var isCorrect = false; + var check = new CheckValues(); + if (int.TryParse(item, out intInput)) + { + isCorrect = check.IsValidInt(intInput, minValue, maxValue); + } + + return (intInput, isCorrect); + } + + public double InputDouble(double maxValue) + { + return InputDouble(0, maxValue); + } + + public double InputDouble(double minValue, double maxValue) + { + var isCorrect = false; + var number = 0d; + while (true) + { + var item = Console.ReadLine(); + (number, isCorrect) = InputDouble(minValue, maxValue, item); + if (isCorrect) + { + return number; + } + else + { + Console.WriteLine($"Please enter correct value!"); + } + } + } + + public (double, bool) InputDouble(double minValue, double maxValue, string item) + { + double doubleInput = 0; + var isCorrect = false; + var check = new CheckValues(); + if (double.TryParse(item, out doubleInput)) + { + isCorrect = check.IsValidDouble(doubleInput, minValue, maxValue); + } + + return (doubleInput, isCorrect); + } + } +} diff --git a/courseworkspace.code-workspace b/courseworkspace.code-workspace index a24280d9..bdc25edf 100644 --- a/courseworkspace.code-workspace +++ b/courseworkspace.code-workspace @@ -1,15 +1,17 @@ { "folders": [ { + "name": "CourseApp", "path": "CourseApp" }, { + "name": "CourseApp.Tests", "path": "CourseApp.Tests" }, { - "name": "Configs (Root)", - "path": "." - }, + "name": "Configs (Root)", + "path": "." + } ], "settings": {} } \ No newline at end of file From 66e833315aa7de5e1b9f67405a20430bceb64f70 Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Mon, 31 Jan 2022 10:02:36 +0300 Subject: [PATCH 3/9] Delete some files --- CourseApp.Tests/UnitTests.cs | 70 --------------------- CourseApp/MainFile.cs | 15 ----- CourseApp/Program/CalculateTasks.cs | 79 ------------------------ CourseApp/Program/UserInterface.cs | 94 ----------------------------- 4 files changed, 258 deletions(-) delete mode 100644 CourseApp.Tests/UnitTests.cs delete mode 100644 CourseApp/MainFile.cs delete mode 100644 CourseApp/Program/CalculateTasks.cs delete mode 100644 CourseApp/Program/UserInterface.cs diff --git a/CourseApp.Tests/UnitTests.cs b/CourseApp.Tests/UnitTests.cs deleted file mode 100644 index e6a403a8..00000000 --- a/CourseApp.Tests/UnitTests.cs +++ /dev/null @@ -1,70 +0,0 @@ -namespace CourseApp.Tests -{ - using System.Collections.Generic; - using CourseApp.Program; - using Xunit; - using static System.Math; - - public class UnitTests - { - [Theory] - [InlineData(3, 2, 0.11, 1.56)] - [InlineData(3, 2, 0.36, 1.488)] - [InlineData(3, 2, 0.08, 1.565)] - [InlineData(3, 2, 0.026, 1.57)] - [InlineData(3, 2, 0.35, 1.491)] - [InlineData(3, 2, 0.41, 1.471)] - [InlineData(3, 2, 0.51, 1.441)] - public void TestCalculate(double a, double b, double x, double expected) - { - var task = new CalculateTasks(a, b); - var (_, actual) = task.CalculateValue(x); - Assert.Equal(expected, actual, 3); - } - - [Theory] - [InlineData(0.1, 0.5, 0.1, 5)] - [InlineData(0, 5, 1, 6)] - [InlineData(0.25, 0.5, 0.05, 6)] - [InlineData(1.2, 2.4, 1.2, 2)] - public void TestListCount(double start, double end, double delta, int expected) - { - var task = new CalculateTasks(start, end, delta); - var actual = task.ListValue().Count; - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(2, 3, 0.1, 0.5, 0.1, new double[] { 1.58, 1.603, 1.634, 1.667, 1.698 })] - [InlineData(2, 3, 3, 9, 3, new double[] { double.NaN, double.NaN, double.NaN })] - [InlineData(2, 3, 0.5, 2.5, 0.5, new double[] { 1.698, 1.571, double.NaN, double.NaN, double.NaN })] - public void TestTaskOne(double a, double b, double start, double end, double delta, double[] expected) - { - var task = new CalculateTasks(a, b, start, end, delta); - var list = task.ListValue(); - var actual = new List(); - foreach (var item in list) - { - actual.Add(Round(task.CalculateValue(item).Item2, 3)); - } - - Assert.Equal(expected, actual.ToArray()); - } - - [Theory] - [InlineData(2, 3, new double[] { 1, 2, 3, 4 }, new double[] { 1.571, double.NaN, double.NaN, double.NaN })] - [InlineData(2, 3, new double[] { 0.1, 0.2, 0.3, 0.4 }, new double[] { 1.58, 1.603, 1.634, 1.667 })] - [InlineData(2, 3, new double[] { 0.5, 0.75, 0.8, 0.9 }, new double[] { 1.698, 1.733, 1.728, 1.698 })] - public void TestTaskTwo(double a, double b, double[] list, double[] expected) - { - var task = new CalculateTasks(a, b); - var actual = new List(); - foreach (var item in list) - { - actual.Add(Round(task.CalculateValue(item).Item2, 3)); - } - - Assert.Equal(expected, actual.ToArray()); - } - } -} diff --git a/CourseApp/MainFile.cs b/CourseApp/MainFile.cs deleted file mode 100644 index 00111e58..00000000 --- a/CourseApp/MainFile.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace CourseApp -{ - using System; - using CourseApp.Program; - - public class MainFile - { - public static void Main(string[] args) - { - var userInterface = new UserInterface(); - userInterface.StartPage(); - Console.ReadLine(); - } - } -} diff --git a/CourseApp/Program/CalculateTasks.cs b/CourseApp/Program/CalculateTasks.cs deleted file mode 100644 index d37568bb..00000000 --- a/CourseApp/Program/CalculateTasks.cs +++ /dev/null @@ -1,79 +0,0 @@ -namespace CourseApp.Program -{ - using System.Collections.Generic; - using static System.Math; - - public class CalculateTasks - { - public CalculateTasks(double aValue, double bValue, double startValue, double endValue, double deltaValue) - { - AValue = aValue; - BValue = bValue; - StartValue = startValue; - EndValue = endValue; - DeltaValue = deltaValue; - } - - public CalculateTasks(List listValues) - { - AValue = listValues[0]; - BValue = listValues[1]; - StartValue = listValues[2]; - EndValue = listValues[3]; - DeltaValue = listValues[4]; - } - - public CalculateTasks(double aValue, double bValue) - { - AValue = aValue; - BValue = bValue; - } - - public CalculateTasks(double startValue, double endValue, double deltaValue) - { - StartValue = startValue; - EndValue = endValue; - DeltaValue = deltaValue; - } - - public double StartValue { get; set; } - - public double EndValue { get; set; } - - public double DeltaValue { get; set; } - - public double AValue { get; set; } - - public double BValue { get; set; } - - public List<(double, double)> StartCalculate(List listValue) - { - var list = new List<(double, double)>(); - foreach (var x in listValue) - { - var value = CalculateValue(x); - list.Add(value); - } - - return list; - } - - public List ListValue() - { - var listValue = new List(); - for (var x = StartValue; x <= EndValue; x += DeltaValue) - { - listValue.Add(x); - } - - return listValue; - } - - public (double, double) CalculateValue(double x) - { - var sin = Asin(Pow(x, AValue)); - var cos = Acos(Pow(x, BValue)); - return (x, sin + cos); - } - } -} diff --git a/CourseApp/Program/UserInterface.cs b/CourseApp/Program/UserInterface.cs deleted file mode 100644 index f19481a7..00000000 --- a/CourseApp/Program/UserInterface.cs +++ /dev/null @@ -1,94 +0,0 @@ -namespace CourseApp.Program -{ - using System; - using System.Collections.Generic; - using CourseApp.Program.Input; - - public class UserInterface - { - public UserInterface() - { - Console.WriteLine("Hello!"); - } - - public void StartPage() - { - var isEnabled = true; - while (isEnabled) - { - var input = new InputValues(); - var listValues = new List() { 0.08, 0.026, 0.35, 0.41, 0.51 }; - Console.WriteLine(@" - In this program you can: - 1 - Get calculating with default values - 2 - Get calculating with custom values - 3 - Exit program - What you want? Enter integer values."); - switch (input.InputInt(1, 3)) - { - case 1: - DefaultCalculations(listValues); - break; - - case 2: - CustomCalculations(listValues, InputCustomValues()); - break; - - case 3: - isEnabled = false; - break; - } - } - - Environment.Exit(0); - } - - private void DefaultCalculations(List listValues) - { - Console.Clear(); - var input = new InputValues(); - var task = new CalculateTasks(2.0, 3.0, 0.11, 0.36, 0.05); - Console.WriteLine($"Calculated with default values:"); - Output(task.StartCalculate(task.ListValue())); - Output(task.StartCalculate(listValues)); - } - - private void CustomCalculations(List listValues, List listCustomValues) - { - Console.Clear(); - var task = new CalculateTasks(listCustomValues); - Console.WriteLine($"Calculated with custom values:"); - Output(task.StartCalculate(task.ListValue())); - Output(task.StartCalculate(listValues)); - } - - private void Output(List<(double, double)> lst) - { - Console.WriteLine("Task:"); - foreach (var (x, y) in lst) - { - Console.WriteLine($" x = {x:f2} y = {y:f2}"); - } - } - - private List InputCustomValues() - { - Console.Clear(); - var input = new InputValues(); - var listCustomValues = new List(); - Console.WriteLine("Enter your values:"); - Console.Write("a = "); - listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); - Console.Write("b = "); - listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); - Console.Write("start = "); - listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); - Console.Write("end = "); - listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); - Console.Write("delta = "); - listCustomValues.Add(input.InputDouble(double.MinValue, double.MaxValue)); - Console.Clear(); - return listCustomValues; - } - } -} From 67808a48f4ce0b1a4ca71136aa8e05a532500b68 Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Wed, 2 Feb 2022 01:04:56 +0300 Subject: [PATCH 4/9] Update and rename MainFileClass.cs to MainFile.cs --- CourseApp/{MainFileClass.cs => MainFile.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename CourseApp/{MainFileClass.cs => MainFile.cs} (95%) diff --git a/CourseApp/MainFileClass.cs b/CourseApp/MainFile.cs similarity index 95% rename from CourseApp/MainFileClass.cs rename to CourseApp/MainFile.cs index a42140e2..60ec8f91 100644 --- a/CourseApp/MainFileClass.cs +++ b/CourseApp/MainFile.cs @@ -2,7 +2,7 @@ namespace CourseApp { using System; - public class MainFileClass + public class MainFile { public static void Main(string[] args) { From e81785208d13efe438a01dda392e34969b90ea19 Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Wed, 2 Feb 2022 01:15:25 +0300 Subject: [PATCH 5/9] Update MainFile.cs --- CourseApp/{MainFileClass.cs => MainFile.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename CourseApp/{MainFileClass.cs => MainFile.cs} (95%) diff --git a/CourseApp/MainFileClass.cs b/CourseApp/MainFile.cs similarity index 95% rename from CourseApp/MainFileClass.cs rename to CourseApp/MainFile.cs index a42140e2..60ec8f91 100644 --- a/CourseApp/MainFileClass.cs +++ b/CourseApp/MainFile.cs @@ -2,7 +2,7 @@ namespace CourseApp { using System; - public class MainFileClass + public class MainFile { public static void Main(string[] args) { From ab178190f89179e4e238c7a7609830341ea04813 Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Sun, 6 Feb 2022 18:59:16 +0300 Subject: [PATCH 6/9] Update dotnetcore.yml --- .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 95b27949..6cb7483c 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '2.1', '3.1.x', '5.0.x' ] + dotnet: [ '2.1', '3.1.x', '5.0.x', '6.0.x' ] steps: - uses: actions/checkout@v1 From 316d23ff344ac21f8059aba8ca32ac33bb8f3106 Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Sun, 6 Feb 2022 19:00:55 +0300 Subject: [PATCH 7/9] Update dotnetcore.yml --- .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 6cb7483c..eda431a2 100644 --- a/.github/workflows/dotnetcore.yml +++ b/.github/workflows/dotnetcore.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dotnet: [ '2.1', '3.1.x', '5.0.x', '6.0.x' ] + dotnet: [ '6.0.x' ] steps: - uses: actions/checkout@v1 From fe4bed83765faeb604ba9a0538e5b4522db30561 Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Sun, 6 Feb 2022 19:02:24 +0300 Subject: [PATCH 8/9] Update CourseApp.Tests.csproj --- CourseApp.Tests/CourseApp.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 158d6300..cff59f20 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp5 + netcoreapp6.0 True false From b9a78064f529321cdfa6aa1fcc9dd9b47dbb1956 Mon Sep 17 00:00:00 2001 From: Alexander <71167144+SanyaKirilv@users.noreply.github.com> Date: Sun, 6 Feb 2022 19:03:43 +0300 Subject: [PATCH 9/9] Delete InputValueUnitTests.cs --- CourseApp.Tests/InputValueUnitTests.cs | 60 -------------------------- 1 file changed, 60 deletions(-) delete mode 100644 CourseApp.Tests/InputValueUnitTests.cs diff --git a/CourseApp.Tests/InputValueUnitTests.cs b/CourseApp.Tests/InputValueUnitTests.cs deleted file mode 100644 index 4b055458..00000000 --- a/CourseApp.Tests/InputValueUnitTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -namespace CourseApp.Tests -{ - using CourseApp.Program.Input; - using Xunit; - - public class InputValueUnitTests - { - [Theory] - [InlineData(0, -1, 2, true)] - [InlineData(0, 1, 2, false)] - [InlineData(1, 0, 2, true)] - [InlineData(1, 1, 2, true)] - public void TestCheckValuesInputInt(int input, int min, int max, bool expected) - { - var check = new CheckValues(); - var actual = check.IsValidInt(input, min, max); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData(0.1, -1, 2, true)] - [InlineData(0.5, 1, 2, false)] - [InlineData(1, 0, 2, true)] - [InlineData(1.2, 1, 2, true)] - public void TestCheckValuesInputDouble(double input, double min, double max, bool expected) - { - var check = new CheckValues(); - var actual = check.IsValidDouble(input, min, max); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData("2", 0, 3, true)] - [InlineData("-1", 0, 3, false)] - [InlineData("r", 0, 3, false)] - [InlineData("-1.2", -2, -1, false)] - [InlineData("4.1", 4, 5, false)] - [InlineData(" ", 4, 4, false)] - public void TestInputInt(string item, int minValue, int maxValue, bool expected) - { - var input = new InputValues(); - var (_, actual) = input.InputInt(minValue, maxValue, item); - Assert.Equal(expected, actual); - } - - [Theory] - [InlineData("2.2", 0, 3, true)] - [InlineData("-1.5", 0, 3, false)] - [InlineData("r", 0, 3, false)] - [InlineData("-1", -2, -1, true)] - [InlineData("4.1", 4, 5, true)] - [InlineData(" ", 4, 4, false)] - public void TestInputDouble(string item, int minValue, int maxValue, bool expected) - { - var input = new InputValues(); - var (_, actual) = input.InputDouble(minValue, maxValue, item); - Assert.Equal(expected, actual); - } - } -}