From 7d24737e09c8f0bae6e7f660760b4d04bb5809c2 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Sat, 3 Sep 2022 12:32:52 +0300 Subject: [PATCH 1/6] 1 classes sample --- CourseApp/Phone.cs | 38 ++++++++++++++++++++++++++++++++++++++ CourseApp/Program.cs | 14 ++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 CourseApp/Phone.cs diff --git a/CourseApp/Phone.cs b/CourseApp/Phone.cs new file mode 100644 index 0000000..1c8e407 --- /dev/null +++ b/CourseApp/Phone.cs @@ -0,0 +1,38 @@ +namespace CourseApp +{ + using System; + + public class Phone + { + private float diaonal; + + public Phone(string name, float diagonal) + { + Name = name; + Diagonal = diagonal; + } + + public string Name { get; set; } + + public float Diagonal + { + get + { + return diaonal; + } + + set + { + if (value > 0 && value < 20) + { + this.diaonal = value; + } + } + } + + public void Show() + { + Console.WriteLine($"{Name} with diagonal {diaonal}"); + } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index d6d2c87..030f047 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -6,6 +6,20 @@ public class Program { public static void Main(string[] args) { + Phone phone1 = new Phone("iPhone", -7); + phone1.Show(); + phone1.Diagonal = 7; + phone1.Show(); + phone1.Diagonal = -16; + phone1.Show(); + + Phone tablet = new Phone("Android", 6); + tablet.Diagonal = 6; + tablet.Show(); + tablet.Diagonal = -10; + tablet.Show(); + tablet.Diagonal = 8; + tablet.Show(); Console.WriteLine("Hello World"); } } From fc7b16ba81806b4c328edf4bbe63226e66091d75 Mon Sep 17 00:00:00 2001 From: Eugeny Konstantinov Date: Sat, 17 Sep 2022 14:00:56 +0300 Subject: [PATCH 2/6] check workflow --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a79bfa3..2611643 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,4 @@ Finally you may work with migration (from `WebApplication` folder). The followin ``` dotnet ef migrations add InitialMigration -``` \ No newline at end of file +``` From 3cc5f7771b974a629bd7e16cf2ea2aa2b8f647ce Mon Sep 17 00:00:00 2001 From: Polinkiss Date: Fri, 16 Dec 2022 18:29:00 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2611643..8820444 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Tprogramming 2021 -Master branch :) +Polina Fedulova love infa `docker volume create --name=mssqldata` From 169bb40cb1521a4dbd26cd658f584f6abbe41aa1 Mon Sep 17 00:00:00 2001 From: Polinkiss Date: Fri, 13 Jan 2023 11:05:51 +0300 Subject: [PATCH 4/6] saga --- CourseApp/SAGA/Archer.cs | 17 ++++ CourseApp/SAGA/Game.cs | 187 ++++++++++++++++++++++++++++++++++++++ CourseApp/SAGA/Knight.cs | 40 ++++++++ CourseApp/SAGA/Logger.cs | 60 ++++++++++++ CourseApp/SAGA/Mage.cs | 17 ++++ CourseApp/SAGA/Player.cs | 100 ++++++++++++++++++++ CourseApp/SAGA/Program.cs | 10 ++ 7 files changed, 431 insertions(+) create mode 100644 CourseApp/SAGA/Archer.cs create mode 100644 CourseApp/SAGA/Game.cs create mode 100644 CourseApp/SAGA/Knight.cs create mode 100644 CourseApp/SAGA/Logger.cs create mode 100644 CourseApp/SAGA/Mage.cs create mode 100644 CourseApp/SAGA/Player.cs create mode 100644 CourseApp/SAGA/Program.cs diff --git a/CourseApp/SAGA/Archer.cs b/CourseApp/SAGA/Archer.cs new file mode 100644 index 0000000..58827c3 --- /dev/null +++ b/CourseApp/SAGA/Archer.cs @@ -0,0 +1,17 @@ +namespace CourseApp +{ + using System; + + public class Archer : Player + { + public Archer(int health, int strength, string name) + : base(health, strength, name, "Огненная стрела", 1) + { + } + + public override string ToString() + { + return "(Лучник) " + Name; + } + } +} \ No newline at end of file diff --git a/CourseApp/SAGA/Game.cs b/CourseApp/SAGA/Game.cs new file mode 100644 index 0000000..0dddfbb --- /dev/null +++ b/CourseApp/SAGA/Game.cs @@ -0,0 +1,187 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + using System.Linq; + + public class Game + { + public static void Start() + { + int count = GetPlayersCount(); // спрашиваем у пользователя число игроков + List players = GetPlayersList(count); // генерируем лист игроков + Tournament(players); // запускаем турнир + } + + private static void Tournament(List players) + { + // играем до тех пор, пока не останется 1 игрок + for (int i = 1; players.Count != 1; i++) + { + Logger.WriteRound(i); // передаем в логгер номер раунда + RandomList(players); // в начале каждого раунда случайным образом перемешиваем игроков + Round(players); // запускаем раунд + } + + Logger.WriteWinner(players[0]); // передаем в логгер последнего оставщегося игрока + } + + private static void Round(List players) + { + // так как сражения происходят в парах, то обрабатывать будем до половины листа + for (int i = 0; i < players.Count / 2; i++) + { + Player[] opponents = { players[i * 2], players[(i * 2) + 1] }; // записываем в массив пару бойцов + Logger.WriteFight(opponents); // передаем в логгер созданный массив + players[i * 2] = Fight(opponents); // записываем в первое место пары победителя + } + + // увеличиваем i на единицу, так как при удалении элемента массив сокращается и новый победитель оказывается на только что обработанном месте листа + for (int i = 1; i < players.Count; i++) + { + players.RemoveAt(i); // удаляем всех проигравших + } + } + + private static Player Fight(Player[] opponents) + { + // используем for а не while из-за удобства наличия счетчика + for (int i = 0; true; i++) + { + string dbf_status = opponents[i % 2].DebaffStatus(); // проверяем какой дебаф действует на игрока + Logger.WriteAction(opponents[i % 2], dbf_status); // передаем этот дебаф и игрока в логгер + + // если дебаф был с периодическим уроном, то передаем его + if (dbf_status == "Огненная стрела") + { + opponents[i % 2].GetDamage(2); + } + + bool checkDeath = opponents[i % 2].CheckDeath(); // проверяем не умер ли первый игрок от периодического урона + if (checkDeath) + { + Logger.WriteDeath(opponents[i % 2]); // передаем в логер умершего игрока + opponents[(i + 1) % 2].Refresh(); // восстанавливаем второго игрока + return opponents[(i + 1) % 2]; // передаем его как победителя + } + + // если дебаф на пропуск хода, соответсвенно пропускаем его + if (dbf_status == "Заворожение") + { + continue; + } + + string playerAction = GetAction(opponents[i % 2]); // выбираем действие игрока + + // если действие не атакующие, передаем в логер игрока, совершившего действие, игрока, над которым соверешенно действие, и название действия + if ((playerAction != "Атака") && (playerAction != "Удар возмездия")) + { + Logger.WriteAction(opponents[i % 2], opponents[(i + 1) % 2], playerAction); + opponents[(i + 1) % 2].SetDebaff(playerAction); // записываем его в дебаф + } + + // если действие атакующие, получаем значение урона и передаем в логер игрока, совершившего действие, игрока, над которым соверешенно действие, и урон + else + { + float damage = opponents[i % 2].Attack(); + Logger.WriteAction(opponents[i % 2], opponents[(i + 1) % 2], playerAction, damage); + opponents[(i + 1) % 2].GetDamage(damage); // наносим урон + } + + bool death = opponents[(i + 1) % 2].CheckDeath(); // проверяем не умер ли игрок после получения урона + if (checkDeath) + { + Logger.WriteDeath(opponents[(i + 1) % 2]); // передаем умершего игрока + opponents[i % 2].Refresh(); // восстанавливаем победителя и возвращаем его + return opponents[i % 2]; + } + } + } + + private static string GetAction(Player inputP) + { + Random rnd = new Random(); + int chosen = rnd.Next(0, 4); // случайным образом генерируем дейтсвие игрока + switch (chosen) + { + case 0: + // если игрок может совершить специальное действие возвращаем его название, иначе передаем команду об обычной атаке + if (inputP.CheckAbility()) + { + return inputP.Ability(); + } + + return "Атака"; + default: + return "Атака"; + } + } + + private static int GetPlayersCount() + { + // до тех пор, пока не введется корректное число не возвращаем значение + while (true) + { + Console.WriteLine("Введите число игроков:"); + int count = Convert.ToInt32(Console.ReadLine()); + if (count <= 0) + { + Console.WriteLine("Количество игроков должно быть больше 0!"); + } + else if (count % 2 != 0) + { + Console.WriteLine("Количетсво игроков должно быть четным!"); + } + else + { + return count; + } + } + } + + private static void RandomList(List input) + { + // переставляем элементы листа начиная с 0-го + Random rnd = new Random(); + for (int i = 0; i < input.Count; i++) + { + int chosen = rnd.Next(i, input.Count); + (input[i], input[chosen]) = (input[chosen], input[i]); // перестановка элементов местами + } + } + + private static List GetPlayersList(int count) + { + // создаем лист и возрващаем его заполненный вариант + List playerList = new List(); + for (int i = 0; i < count; i++) + { + playerList.Add(GetPlayer()); // добавляем игрока в лист + } + + return playerList; + } + + private static Player GetPlayer() + { + string[] names = { "Rose Winter", "Kael", "Dhamir", "Burk", "Regantum", "Atorin", "Innis", "Urug", "Vambad", "Kazmir", "Ug", "Oddintir", "Arvin", "Vingelrinde", "Dorin", "Abergard" }; + Random random = new Random(); + + // рандомно выбираем здоровье, силу, класс и имя, затем возрващаем полученного игрока + int hlth = (int)random.NextInt64(20, 101); + int str = (int)random.NextInt64(5, 21); + int player_class = (int)random.NextInt64(0, 3); + switch (player_class) + { + case 0: + return new Knight(hlth, str, names[random.Next(names.Length)]); // передаем в конструктор класса здоровье, силу и элемент массива имен со случайного места + case 1: + return new Mage(hlth, str, names[random.Next(names.Length)]); + case 2: + return new Archer(hlth, str, names[random.Next(names.Length)]); + default: + return new Knight(hlth, str, names[random.Next(names.Length)]); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/SAGA/Knight.cs b/CourseApp/SAGA/Knight.cs new file mode 100644 index 0000000..3447b0c --- /dev/null +++ b/CourseApp/SAGA/Knight.cs @@ -0,0 +1,40 @@ +namespace CourseApp +{ + using System; + + public class Knight : Player + { + private bool powerAtack; + + public Knight(int health, int strength, string name) + : base(health, strength, name, "Удар возмездия", 1) + { + powerAtack = false; + } + + public override string ToString() + { + return "(Рыцарь) " + Name; + } + + public override float Attack() // если была применена способность сильного удара, то возвращаем усиленный урон + { + if (powerAtack) + { + powerAtack = false; + return (float)Math.Round(Strength * 1.3); + } + else + { + return Strength; + } + } + + public override string Ability() // если была применена способность возвращаем название способности и устанавливаем флаг в "истина" + { + AbilityLeft--; + powerAtack = true; + return AbilityName; + } + } +} \ No newline at end of file diff --git a/CourseApp/SAGA/Logger.cs b/CourseApp/SAGA/Logger.cs new file mode 100644 index 0000000..e1dde4b --- /dev/null +++ b/CourseApp/SAGA/Logger.cs @@ -0,0 +1,60 @@ +namespace CourseApp +{ + using System; + + public static class Logger + { + public static void WriteWinner(Player winner) + { + Console.WriteLine($"{winner.ToString()} ПОБЕДИЛ!"); + } + + public static void WriteRound(int round) + { + Console.WriteLine($"Раунд {round}."); + } + + public static void WriteFight(Player[] opponents) + { + Console.WriteLine($"{opponents[0].ToString()} VS {opponents[1].ToString()}"); + } + + // у метода следующие перегрузки: применение способности по противнику, применение атакующей способности, действующие на игрока дебафы + public static void WriteAction(Player firstP, Player secondP, string action) + { + Console.WriteLine($"{firstP.ToString()} применяет ({action}) по противнику {secondP.ToString()}"); + } + + public static void WriteAction(Player firstP, Player secondP, string action, float damage) + { + switch (action) + { + case "Атака": + Console.WriteLine($"{firstP.ToString()} наносит урон {damage} противнику {secondP.ToString()}"); + break; + case "Удар возмездия": + Console.WriteLine($"{firstP.ToString()} применяет ({action}) и наносит урон {damage} противнику {secondP.ToString()}"); + break; + } + } + + public static void WriteAction(Player inputP, string action) + { + switch (action) + { + case "Огненная стрела": + Console.WriteLine($"{inputP.ToString()} получает периодический урон {2} от ({action})"); + break; + case "Заворожение": + Console.WriteLine($"{inputP.ToString()} пропускает ход из-за ({action})"); + break; + } + } + + public static void WriteDeath(Player inputP) + { + Console.WriteLine($"{inputP.ToString()} погибает"); + Console.WriteLine(); + } + } +} \ No newline at end of file diff --git a/CourseApp/SAGA/Mage.cs b/CourseApp/SAGA/Mage.cs new file mode 100644 index 0000000..c95ed19 --- /dev/null +++ b/CourseApp/SAGA/Mage.cs @@ -0,0 +1,17 @@ +namespace CourseApp +{ + using System; + + public class Mage : Player + { + public Mage(int health, int strength, string name) + : base(health, strength, name, "Заворожение", 1) + { + } + + public override string ToString() + { + return "(Маг) " + Name; + } + } +} \ No newline at end of file diff --git a/CourseApp/SAGA/Player.cs b/CourseApp/SAGA/Player.cs new file mode 100644 index 0000000..b6a343d --- /dev/null +++ b/CourseApp/SAGA/Player.cs @@ -0,0 +1,100 @@ +namespace CourseApp +{ + using System; + using System.Collections.Generic; + + public abstract class Player + { + private string debaff; + + public Player(int maxHealth, int strength, string name, string abilityName, int maxAbilityUsages) + { + this.MaxHealth = maxHealth; + this.CurrentHealth = maxHealth; + this.Strength = strength; + this.Name = name; + this.AbilityName = abilityName; + this.MaxAbilityUsages = maxAbilityUsages; + this.AbilityLeft = maxAbilityUsages; + } + + public float MaxHealth { get; protected set; } + + public float CurrentHealth { get; protected set; } + + public float Strength { get; protected set; } + + public string Name { get; protected set; } + + public int MaxAbilityUsages { get; protected set; } + + public int AbilityLeft { get; protected set; } + + public string AbilityName { get; protected set; } + + public bool CheckAbility() // проверка на возможность применения способности + { + if (AbilityLeft > 0) + { + return true; + } + else + { + return false; + } + } + + public virtual string Ability() // применение способности + { + AbilityLeft--; + return AbilityName; + } + + public virtual float Attack() // атака + { + return Strength; + } + + public void GetDamage(float damage) // получение урона + { + CurrentHealth -= damage; + } + + public void SetDebaff(string dName) // установка дебаффов + { + debaff = dName; + } + + public string DebaffStatus() // проверка действующих дебаффов + { + string buffer = debaff; + switch (debaff) + { + case "Огненная стрела": + break; + case "Заворожение": + debaff = string.Empty; + break; + } + + return buffer; + } + + public bool CheckDeath() // проверка на смерть + { + if (CurrentHealth <= 0) + { + return true; + } + + return false; + } + + public void Refresh() // востановление показателей + { + AbilityLeft = MaxAbilityUsages; + CurrentHealth = MaxHealth; + debaff = string.Empty; + } + } +} \ No newline at end of file diff --git a/CourseApp/SAGA/Program.cs b/CourseApp/SAGA/Program.cs new file mode 100644 index 0000000..ab6cbb4 --- /dev/null +++ b/CourseApp/SAGA/Program.cs @@ -0,0 +1,10 @@ +namespace CourseApp +{ + public class Program + { + public static void Main(string[] args) + { + Game.Start(); + } + } +} From 600c480efe400f0c9f95d966b8f40e3362b051ff Mon Sep 17 00:00:00 2001 From: Polinkiss Date: Fri, 13 Jan 2023 11:23:39 +0300 Subject: [PATCH 5/6] class --- CourseApp/Class/Dish.cs | 131 ++++++++++++++++++++++++++++++++ CourseApp/Class/ICookingDish.cs | 7 ++ CourseApp/Class/IDeliverDish.cs | 7 ++ CourseApp/Class/Program.cs | 28 +++++++ CourseApp/Class/Salad.cs | 53 +++++++++++++ CourseApp/Class/Sushi.cs | 62 +++++++++++++++ 6 files changed, 288 insertions(+) create mode 100644 CourseApp/Class/Dish.cs create mode 100644 CourseApp/Class/ICookingDish.cs create mode 100644 CourseApp/Class/IDeliverDish.cs create mode 100644 CourseApp/Class/Program.cs create mode 100644 CourseApp/Class/Salad.cs create mode 100644 CourseApp/Class/Sushi.cs diff --git a/CourseApp/Class/Dish.cs b/CourseApp/Class/Dish.cs new file mode 100644 index 0000000..2e8407b --- /dev/null +++ b/CourseApp/Class/Dish.cs @@ -0,0 +1,131 @@ +namespace CourseApp.Class +{ + using System; + + public abstract class Dish + { + private string name; + private double callories; + private double weight; + private double price; + + public Dish() + { + callories = 0; + weight = 0; + name = "No_Name_Null"; + price = 0; + } + + public Dish(string name, double callories, double weight, double price) + { + Callories = callories; + Weight = weight; + Name = name; + Price = price; + } + + public string Name + { + get + { + return name; + } + + set + { + try + { + if ((value == " ") || (value == null)) + { + throw new Exception($"Name is incorrect!"); + } + else + { + name = value; + } + } + catch (Exception e) + { + new ArgumentException($"Error: {e.Message}"); + Console.WriteLine($"Error: {e.Message}"); + } + } + } + + public double Price + { + get + { + return price; + } + + set + { + if (value < 0) + { + price = 0; + } + else + { + price = value; + } + } + } + + public double Callories + { + get + { + return callories; + } + + set + { + if (value < 0) + { + callories = 0; + } + else + { + callories = value; + } + } + } + + public double Weight + { + get + { + return weight; + } + + set + { + if (value < 0) + { + weight = 0; + } + else + { + weight = value; + } + } + } + + public virtual string GetInfo() + { + return @$"Dish: {Name} +Callories: {Callories} +Weight: {Weight} +Price: {Price}"; + } + + public override string ToString() + { + return $"Блюдо: {name} Цена:{Price}"; + } + + public abstract string Eat(); + } +} diff --git a/CourseApp/Class/ICookingDish.cs b/CourseApp/Class/ICookingDish.cs new file mode 100644 index 0000000..01594b1 --- /dev/null +++ b/CourseApp/Class/ICookingDish.cs @@ -0,0 +1,7 @@ +namespace CourseApp.Class +{ + public interface ICookingDish + { + public string CookingDish(string[] ingredients); + } +} diff --git a/CourseApp/Class/IDeliverDish.cs b/CourseApp/Class/IDeliverDish.cs new file mode 100644 index 0000000..b4d1e3f --- /dev/null +++ b/CourseApp/Class/IDeliverDish.cs @@ -0,0 +1,7 @@ +namespace CourseApp.Class +{ + public interface IDeliverDish + { + public void Delivery(); + } +} diff --git a/CourseApp/Class/Program.cs b/CourseApp/Class/Program.cs new file mode 100644 index 0000000..9e96ae7 --- /dev/null +++ b/CourseApp/Class/Program.cs @@ -0,0 +1,28 @@ +namespace CourseApp +{ + using System.Collections.Generic; + using CourseApp.Class; + + public class Program + { + public static void Main(string[] args) + { + Dish sushi = new Sushi("California", 176, 28, 350, "standard", 8); + Dish salad = new Salad("Caesar", 44, 300, new string[] { "chicken", "cherry", "tomatoes", "parmesan", "olive oil", "garlic", "black pepper" }, 400); + List dishs = new List { salad, sushi }; + System.Console.WriteLine(sushi.ToString()); + System.Console.WriteLine(salad.ToString()); + + for (int i = 0; i < dishs.Count; i++) + { + System.Console.WriteLine(dishs[i].Eat()); + } + + Dish dish = new Salad(); + System.Console.WriteLine(dish.GetInfo()); + + Salad salad1 = new Salad("Caesar", 44, 300, new string[] { "chicken", "cherry", "tomatoes", "parmesan", "olive oil", "garlic", "black pepper" }, 400); + salad1.Delivery(); + } + } +} diff --git a/CourseApp/Class/Salad.cs b/CourseApp/Class/Salad.cs new file mode 100644 index 0000000..6672489 --- /dev/null +++ b/CourseApp/Class/Salad.cs @@ -0,0 +1,53 @@ +namespace CourseApp.Class +{ + public class Salad : Dish, IDeliverDish, ICookingDish + { + public Salad(string name, double callories, double weight, string[] composition, double price) + : base(name, callories, weight, price) + { + Composition = composition; + } + + public Salad() + { + } + + public string[] Composition + { + get; set; + } + + public override string GetInfo() + { + return @$"Salad: {Name} +Callories: {Callories} +Weight: {Weight} +Price: {Price}"; + } + + public override string Eat() + { + Weight = 0.8 * Weight; + return "We eat part of the salad"; + } + + public override string ToString() + { + return $"Salad {Name}, {Callories} callories"; + } + + public void Delivery() + { + Price = (int)(Price * 1.3); + System.Console.WriteLine($"Your salad delivered"); + } + + public string CookingDish(string[] ingredients) + { + Composition = ingredients; + + Callories *= 1.2; + return "Salad prepared and dressed"; + } + } +} diff --git a/CourseApp/Class/Sushi.cs b/CourseApp/Class/Sushi.cs new file mode 100644 index 0000000..b1bf933 --- /dev/null +++ b/CourseApp/Class/Sushi.cs @@ -0,0 +1,62 @@ +using CourseApp.Class; + +public class Sushi : Dish +{ + private int number; + + public Sushi(string name, double callories, double weight, double price, string type, int number) + : base(name, callories, weight, price) + { + TypeOfSuchi = type; + this.number = number; + } + + public Sushi() + { + } + + public int Number + { + get + { + return number; + } + + set + { + if (value < 0) + { + number = 0; + } + } + } + + public string TypeOfSuchi { get; set; } + + public override string ToString() + { + return $"Sushi {Name} - {TypeOfSuchi}"; + } + + public override string GetInfo() + { + return @$"Sushi: {Name} +Callories: {Callories} +Weight: {Weight} +Price: {Price} +Type: {TypeOfSuchi}"; + } + + public override string Eat() + { + if (number > 0) + { + number -= 1; + return "We eat one sushi"; + } + else + { + return "We can't eat sushi because there isn't any"; + } + } +} From 98d7a8829dba6ae05a6f3308ded8e35553efb8f9 Mon Sep 17 00:00:00 2001 From: Polinkiss Date: Fri, 13 Jan 2023 11:28:47 +0300 Subject: [PATCH 6/6] test --- CourseApp.Tests/DishTests.cs | 76 ++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 CourseApp.Tests/DishTests.cs diff --git a/CourseApp.Tests/DishTests.cs b/CourseApp.Tests/DishTests.cs new file mode 100644 index 0000000..5de21cc --- /dev/null +++ b/CourseApp.Tests/DishTests.cs @@ -0,0 +1,76 @@ +namespace CourseApp.Tests +{ + using CourseApp.Class; + using Xunit; + + public class DishTests + { + [Fact] + public void SushiConstructorTest() + { + Dish sushi = new Sushi("California", 176, 28, 350, "Standard", 8); + Assert.Equal( + @"Sushi: California +Callories: 176 +Weight: 28 +Price: 350 +Type: Standard", sushi.GetInfo()); + } + + [Fact] + public void SaladConstructorTest() + { + Dish salad = new Salad("Caesar", 44, 300, new string[] { "chicken", "cherry", "tomatoes", "parmesan", "olive oil", "garlic", "black pepper" }, 400); + Assert.Equal( + @"Salad: Caesar +Callories: 44 +Weight: 300 +Price: 400", salad.GetInfo()); + } + + [Fact] + public void EmptyConstructorTest() + { + Dish dish = new Salad(); + Assert.Equal( + @"Salad: No_Name_Null +Callories: 0 +Weight: 0 +Price: 0", dish.GetInfo()); + } + + [Fact] + public void ToStringTest() + { + Dish dish = new Sushi("California", 176, 28, 350, "standard", 8); + Assert.Equal("Sushi California - standard", dish.ToString()); + } + + [Fact] + public void AbstractMethodTest() + { + Dish sushi = new Sushi("California", 176, 28, 350, "standard", 8); + Assert.Equal("We eat one sushi", sushi.Eat()); + } + + [Fact] + public void TestInterfacesDelivery() + { + Salad dish = new Salad("Caesar", 44, 300, new string[] { "chicken", "cherry", "tomatoes", "parmesan", "olive oil", "garlic", "black pepper" }, 400); + int newPrice = (int)(dish.Price * 1.3); + dish.Delivery(); + Assert.Equal( + $@"Salad: Caesar +Callories: 44 +Weight: 300 +Price: {newPrice}", dish.GetInfo()); + } + + [Fact] + public void TestInterfaceCooking() + { + Salad dish = new Salad(); + Assert.Equal("Salad prepared and dressed", dish.CookingDish(new string[] { "ingredients" })); + } + } +}