diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj index 91aa12f..76f7dc6 100644 --- a/CourseApp.Tests/CourseApp.Tests.csproj +++ b/CourseApp.Tests/CourseApp.Tests.csproj @@ -1,8 +1,9 @@  - netcoreapp2.1 - + netcoreapp2.0 + True + 1573,1591,1701;1702;1705 false @@ -10,9 +11,20 @@ + - + + + ../stylecop/stylecop.ruleset + true + + + + + + + \ No newline at end of file diff --git a/CourseApp.Tests/DemoTest.cs b/CourseApp.Tests/DemoTest.cs new file mode 100644 index 0000000..09e415e --- /dev/null +++ b/CourseApp.Tests/DemoTest.cs @@ -0,0 +1,14 @@ +using System; +using Xunit; + +namespace CourseApp.Tests +{ + public class DemoTest + { + [Fact] + public void Test1() + { + Assert.True(true); + } + } +} diff --git a/CourseApp.Tests/TestofDate.cs b/CourseApp.Tests/TestofDate.cs new file mode 100644 index 0000000..8036ef9 --- /dev/null +++ b/CourseApp.Tests/TestofDate.cs @@ -0,0 +1,30 @@ +using System; +using Xunit; +using CourseApp; + +namespace CourseApp.Tests +{ + public class TestofDate + { + [Fact] + public void EqualDates() + { + string schetvozrasta = Date.SchetVozrasta(new DateTime(1999, 9, 30), new DateTime(1999, 9, 30)); + Assert.Equal(" : 0 , 0 , 0 ", schetvozrasta); + } + + [Fact] + public void BirthdayBeforeToday() + { + string schetvozrasta = Date.SchetVozrasta(new DateTime(1999, 9, 30), new DateTime(2019, 4, 14)); + Assert.Equal(" : 19 , 6 , 14 ", schetvozrasta); + } + + [Fact] + public void BirthdayAfterToday() + { + string schetvozrasta = Date.SchetVozrasta(new DateTime(2029, 9, 30), new DateTime(2019, 4, 14)); + Assert.Equal(" !", schetvozrasta); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/UnitTest1.cs b/CourseApp.Tests/TestofFunction.cs similarity index 89% rename from CourseApp.Tests/UnitTest1.cs rename to CourseApp.Tests/TestofFunction.cs index cc24ccb..de395e1 100644 --- a/CourseApp.Tests/UnitTest1.cs +++ b/CourseApp.Tests/TestofFunction.cs @@ -1,14 +1,10 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using Xunit; using CourseApp; -namespace CourseApp.Test +namespace CourseApp.Tests { - public class UnitTest1 + public class TestofFunction { [Fact] public void Test1() @@ -16,42 +12,49 @@ public void Test1() var res = Program.Func(0.0, 0.8, 0.4); Assert.Equal(0.283, res, 3); } + [Fact] public void Test2() { var res = Program.Func(0.0, 1.1, 0.1); Assert.Equal(0.639, res, 3); } + [Fact] public void Test3() { var res = Program.Func(0.1, 0.4, 0.3); Assert.Equal(0.063, res, 3); } + [Fact] public void Test4() { var res = Program.Func(2.2, 1.8, 3.4); Assert.Equal(203.09, res, 3); } + [Fact] public void Test5() { var res = Program.Func(0.09, 0.71, 0.2); Assert.Equal(0.224, res, 3); } + [Fact] public void Test6() { var res = Program.Func(0.0, 0.01, 0.33); Assert.Equal(0.0, res, 3); } + [Fact] public void Test7() { var res = Program.Func(0.9, 0.8, 0.7); Assert.Equal(1.266, res, 3); } + [Fact] public void Test8() { diff --git a/CourseApp.Tests/TestofIComparable.cs b/CourseApp.Tests/TestofIComparable.cs new file mode 100644 index 0000000..fda59f5 --- /dev/null +++ b/CourseApp.Tests/TestofIComparable.cs @@ -0,0 +1,25 @@ +using System; +using Xunit; +using CourseApp; + +namespace CourseApp.Tests +{ + public class TestofIComparable + { + [Fact] + public void Testcomparable() + { + string icomparable = @"Admiral - 200 - 100 +Duty - 75 - 300 +Lucky - 90 - 100"; + Ship admiral = new Ship(); + Ship lucky = new Ship(90); + Ship duty = new Ship("Duty", 75, 300); + Ship[] araryOfShip = new Ship[] { admiral, lucky, duty }; + Assert.Equal( + @"Admiral - 200 - 100 +Duty - 75 - 300 +Lucky - 90 - 100", icomparable); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/TestofKater.cs b/CourseApp.Tests/TestofKater.cs new file mode 100644 index 0000000..0768e54 --- /dev/null +++ b/CourseApp.Tests/TestofKater.cs @@ -0,0 +1,51 @@ +using System; +using Xunit; +using CourseApp; + +namespace CourseApp.Tests +{ + public class TestofKater + { + [Fact] + public void TestofPicture() + { + Kater carter = new Kater(); + Assert.Equal( + @" + +░░░░░░░░░░░░░█▀▀▀█████████▄▄▄░░░░░░░░░░░ +░░░░░░░░░░░▄█▀░░░░░█▀░░░░░█▀░░░░░░░░░░░░ +███████▄▄▄██▄▄▄▄░░░█░░░░░░█░░▀████▄▄▄▄▄▄ +░▄░░░▀▀▀▀▀▀▀▀███████████████▄▄▄█▄▄▄█░░██ +░▀█████████▄▄▄▄▄▄▄▄▄░░▀▀▀▀▀▀▀▀▀████████░ +░░░▀█████████████████████████▄▄▄▄▄▄▄▄▄░░ +░░░░░▀▀███████████████████████████████░░ +░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀░░░ +", carter.Picture()); + } + + [Fact] + public void Testofznacheniya() + { + Kater carter = new Kater(); + Assert.Equal("Carter", carter.Name); + Assert.Equal(10, carter.Dlina); + Assert.Equal(50, carter.Maxspeed); + } + + [Fact] + public void Testofpredlojeniya() + { + Kater carter = new Kater(); + Assert.Equal($"Катер {carter.Name} поплыл вдоль реки", carter.Predlojenie()); + } + + [Fact] + public void CarterISwim() + { + Kater carter = new Kater(); + string iswim = carter.Swim(carter); + Assert.Equal($"{carter.Name} плывет по течению", iswim); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/TestofShip.cs b/CourseApp.Tests/TestofShip.cs new file mode 100644 index 0000000..a9bde7f --- /dev/null +++ b/CourseApp.Tests/TestofShip.cs @@ -0,0 +1,88 @@ +using System; +using Xunit; +using CourseApp; + +namespace CourseApp.Tests +{ + public class TestofShip + { + [Fact] + public void TestofRis() + { + Ship admiral = new Ship(); + Assert.Equal( + @"_ +_____________________ +_____________________ +___________________________ +___________________________ +__________________________ +__________________________ +__________________________ +______________________________ +_____________ +________________________ +__________________________ +___________________________ +___________________________ +____________________________ +_________________ +___________________ +__________________________________ +______________________ +__________________________ +____________________________________ +_______________________________________ +_____________________________________ +______________________________________ +____________________________________ +___________________________ +_______________________________ +_______________________ +________________________ +______________________ +____________________ +_____________________________________ +____________________________ +_____________________________ +______________________________ +____________________________________ +___________________________________ +_________________________________ +___________ +", admiral.Ris()); + } + + [Fact] + public void Testofznacheniya() + { + Ship admiral = new Ship(); + Assert.Equal("Admiral", admiral.Name); + Assert.Equal(55, admiral.Dlina); + Assert.Equal(100, admiral.Vodoizmeschenie); + } + + [Fact] + public void Testofpredlojenia() + { + Ship admiral = new Ship(); + Assert.Equal($" {admiral.Name} ", admiral.Predlojenie()); + } + + [Fact] + public void AdmiralISwim() + { + Ship admiral = new Ship(); + string iswim = admiral.Swim(admiral); + Assert.Equal($" Admiral ", iswim); + } + + [Fact] + public void LuckyISwim() + { + Ship lucky = new Ship(90); + string iswim = lucky.Swim(lucky); + Assert.Equal($" Lucky ", iswim); + } + } +} \ No newline at end of file diff --git a/CourseApp/CourseApp.csproj b/CourseApp/CourseApp.csproj index ce1697a..23b45ed 100644 --- a/CourseApp/CourseApp.csproj +++ b/CourseApp/CourseApp.csproj @@ -3,6 +3,22 @@ Exe netcoreapp2.0 + True + 1573,1591,1701;1702;1705 - + + + + + + ../stylecop/stylecop.ruleset + true + + + + + + + + diff --git a/CourseApp/Date.cs b/CourseApp/Date.cs new file mode 100644 index 0000000..95c54b0 --- /dev/null +++ b/CourseApp/Date.cs @@ -0,0 +1,26 @@ +using System; + +namespace CourseApp +{ + public class Date + { + public static string SchetVozrasta(DateTime bornday, DateTime today) + { + DateTime todaydate = today; + if (today.Day == bornday.Day) + { + return "Ваш возраст: 0 лет, 0 месяцев, 0 дней"; + } + + if (today < bornday) + { + return $"Еще не родился!"; + } + + todaydate = todaydate.AddYears(-bornday.Year); + todaydate = todaydate.AddMonths(-bornday.Month); + todaydate = todaydate.AddDays(-bornday.Day); + return $"Ваш возраст: {todaydate.Year} лет, {todaydate.Month} месяцев, {todaydate.Day} дней"; + } + } +} diff --git a/CourseApp/ISwim.cs b/CourseApp/ISwim.cs new file mode 100644 index 0000000..359f0e7 --- /dev/null +++ b/CourseApp/ISwim.cs @@ -0,0 +1,9 @@ +using System; + +namespace CourseApp +{ + public interface ISwim + { + string Swim(object o); + } +} diff --git a/CourseApp/Kater.cs b/CourseApp/Kater.cs new file mode 100644 index 0000000..32d5776 --- /dev/null +++ b/CourseApp/Kater.cs @@ -0,0 +1,76 @@ +using System; + +namespace CourseApp +{ + public class Kater : Transport, ISwim + { + private int maxspeed; + + public Kater() + : base() + { + Name = "Carter"; + Dlina = 10; + Maxspeed = 50; + } + + public int Maxspeed + { + get + { + return maxspeed; + } + + set + { + if (value > 400 || value < 1) + { + Console.WriteLine("Невозможное водоизмещение корабля(min:10 max:2000)"); + throw new Exception(); + } + else + { + maxspeed = value; + } + } + } + + public string Swim(object o) + { + Kater c = o as Kater; + return $"{Name} плывет по течению"; + } + + public override void Info() + { + Console.WriteLine($"Катер: Имя:{Name} длина:{Dlina}, максимальная скорость:{Maxspeed}"); + Console.WriteLine(Predlojenie()); + Console.WriteLine(Picture()); + } + + public override string ToString() + { + return $"У катера с длиной {Dlina} громко ревет мотор"; + } + + public override string Predlojenie() + { + return $"Катер {Name} поплыл вдоль реки"; + } + + public string Picture() + { + return @" + +░░░░░░░░░░░░░█▀▀▀█████████▄▄▄░░░░░░░░░░░ +░░░░░░░░░░░▄█▀░░░░░█▀░░░░░█▀░░░░░░░░░░░░ +███████▄▄▄██▄▄▄▄░░░█░░░░░░█░░▀████▄▄▄▄▄▄ +░▄░░░▀▀▀▀▀▀▀▀███████████████▄▄▄█▄▄▄█░░██ +░▀█████████▄▄▄▄▄▄▄▄▄░░▀▀▀▀▀▀▀▀▀████████░ +░░░▀█████████████████████████▄▄▄▄▄▄▄▄▄░░ +░░░░░▀▀███████████████████████████████░░ +░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀░░░ +"; + } + } +} diff --git a/CourseApp/Laba2.cs b/CourseApp/Laba2.cs deleted file mode 100644 index b44b739..0000000 --- a/CourseApp/Laba2.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CourseApp -{ - - public class Program - { - static void Main(string[] args) - { - double a = 2.5; - double b = 4.6; - - // ЗАДАНИЕ А - - Console.WriteLine("ЗАДАНИЕ А"); - for (double x = 1.1; x <= 3.6; x += 0.5) - { - Console.WriteLine($"y({x})={Func(x, a, b)}"); - } - - // ЗАДАНИЕ В - - Console.WriteLine("ЗАДАНИЕ В"); - double[] mas = new double[] { 1.2, 1.28, 1.36, 1.46, 2.35 }; - foreach (double x in mas) - { - Console.WriteLine($"y({x})={Func(x, a, b)}"); - } - Console.ReadKey(); - } - public static double Func(double x, double a, double b) - { - return ((a + b * x) * (a + b * x) * ((a + b * x) / 2)) / (1 + Math.Log10(a + b * x)); - } - } -} diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs new file mode 100644 index 0000000..c7e221b --- /dev/null +++ b/CourseApp/Program.cs @@ -0,0 +1,78 @@ +using System; +using CourseApp; + +namespace CourseApp +{ + public class Program + { + public static double Func(double x, double a, double b) + { + return ((a + (b * x)) * (a + (b * x)) * ((a + (b * x)) / 2)) / (1 + Math.Log10(a + (b * x))); + } + + private static void Main(string[] args) + { + double a = 2.5; + double b = 4.6; + + Console.WriteLine("ЗАДАНИЕ А"); + for (double x = 1.1; x <= 3.6; x += 0.5) + { + Console.WriteLine($"y({x})={Func(x, a, b)}"); + } + + Console.WriteLine("ЗАДАНИЕ В"); + double[] mas = new double[] { 1.2, 1.28, 1.36, 1.46, 2.35 }; + foreach (double x in mas) + { + Console.WriteLine($"y({x})={Func(x, a, b)}"); + } + + Ship admiral = new Ship(); + Ship lucky = new Ship(90); + Ship duty = new Ship("Duty", 75, 300); + + admiral.Info(); + lucky.Info(); + duty.Info(); + + admiral.Dlina = 200; + Console.WriteLine($"Длина Адмирала - {admiral.Dlina} метров"); + Console.WriteLine(admiral); + admiral.Info(); + + Kater carter = new Kater(); + carter.Info(); + Console.WriteLine(carter); + + Transport[] transports = new Transport[2]; + transports[0] = new Ship(); + transports[1] = new Kater(); + + Console.WriteLine("\nинфо в массиве\n"); + foreach (Transport i in transports) + { + i.Info(); + } + + Console.WriteLine(admiral.Swim(admiral)); + Console.WriteLine(lucky.Swim(lucky)); + Console.WriteLine(carter.Swim(carter)); + + Ship[] arrayOfShip = new Ship[] {admiral, lucky, duty }; + + Array.Sort(arrayOfShip); + foreach (Ship o in arrayOfShip) + { + Console.WriteLine("{0} - {1} - {2}", o.Name, o.Dlina, o.Vodoizmeschenie); + } + + Console.WriteLine("\nЗадача на возраст \n"); + DateTime bornday = new DateTime(1999, 9, 30); + DateTime today = new DateTime(2019, 4, 14); + Console.WriteLine(Date.SchetVozrasta(bornday, today)); + + Console.ReadLine(); + } + } +} diff --git a/CourseApp/Ship.cs b/CourseApp/Ship.cs new file mode 100644 index 0000000..a3a16cb --- /dev/null +++ b/CourseApp/Ship.cs @@ -0,0 +1,136 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CourseApp +{ + public class Ship : Transport, ISwim, IComparable + { + private int vodoizmeschenie; + + public Ship() + : base() + { + Name = "Admiral"; + Dlina = 55; + Vodoizmeschenie = 100; + } + + public Ship(int dlina) + { + Name = "Lucky"; + Dlina = dlina; + Vodoizmeschenie = 100; + } + + public Ship(string name, int dlina, int vodoizmeschenie) + { + Name = name; + Dlina = dlina; + Vodoizmeschenie = vodoizmeschenie; + } + + public int Vodoizmeschenie + { + get + { + return vodoizmeschenie; + } + + set + { + if (value > 2000 || value < 10) + { + Console.WriteLine("Невозможное водоизмещение корабля(min:10 max:2000)"); + throw new Exception(); + } + else + { + vodoizmeschenie = value; + } + } + } + + public string Swim(object o) + { + Ship c = o as Ship; + return $"Корабль {c.Name} остановился у причала"; + } + + public int CompareTo(object o) + { + Ship p = o as Ship; + if (p != null) + { + return this.Name.CompareTo(p.Name); + } + else + { + throw new Exception("Невозможно сравнить"); + } + } + + public override void Info() + { + Console.WriteLine($"Корабль: Имя:{Name} длина:{Dlina} водоизмещение:{Vodoizmeschenie}"); + Console.WriteLine(Predlojenie()); + Console.WriteLine(Ris()); + } + + public override string ToString() + { + return $"Корабль с длиной {Dlina} громко гудит"; + } + + public override string Predlojenie() + { + return $"Корабль {Name} вышел в открытое море"; + } + + public string Ris() + { + return @"_¶¶¶ +_____________________¶ +_____________________¶¶¶¶¶¶¶¶¶¶¶¶¶ +_____________________¶¶¶___¶__¶_¶¶¶¶ +_____________________¶¶¶___¶¶¶¶___¶¶ +_____________________¶¶¶__¶¶¶¶¶___¶¶ +_____________________¶¶¶__¶¶¶¶¶___¶ +_____________________¶¶¶¶¶¶__¶¶___¶ +_____________________¶_________¶¶¶¶ +_____________¶¶¶¶¶¶¶¶¶¶¶¶¶ +_____________¶¶___________¶¶ +______________¶____________¶ +______________¶_____________¶ +_______________¶____________¶ +_______________¶____________¶_¶¶ +_______________¶__¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶ +_____¶¶¶¶¶¶¶¶¶¶¶¶¶¶______________¶ +_____¶____________¶¶_____________¶¶____¶ +_____¶¶____________¶_____¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶ +______¶______¶¶¶¶¶¶¶¶¶¶¶¶¶¶______________¶ +______¶¶_____¶¶___________¶______________¶¶ +_______¶______¶____________¶______________¶ +_______¶______¶¶___________¶_____________¶¶ +_______¶_______¶___________¶_____________¶¶ +______¶¶_______¶___________¶¶____________¶ +______¶¶¶¶¶¶¶¶¶¶¶__________¶¶___________¶¶ +___________¶_¶_¶¶________¶¶¶_____¶¶¶¶¶¶¶¶_____¶¶¶ +___________¶_¶_¶¶¶¶¶¶¶¶¶¶¶_¶¶¶¶¶¶¶_______¶¶¶¶¶__¶¶ +¶¶¶¶¶¶_____¶_¶______¶¶_¶_______¶_¶¶¶¶¶¶¶¶¶___¶¶¶¶¶ +¶¶___¶¶¶¶¶¶¶¶¶______¶¶_¶____¶¶¶¶¶¶¶________¶¶ +__¶¶________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶____¶¶______¶ +____¶____________________________¶¶_¶____¶ +_____¶_____¶¶¶_____¶¶_____¶¶¶_____¶¶¶___¶¶ +______¶___¶¶_¶¶___¶¶_¶____¶_¶¶__________¶ +______¶¶____¶¶_____¶¶¶_____¶¶__________¶¶ +_______¶¶_____________________________¶¶ +________¶¶___________________________¶¶ +_________¶¶________________________¶¶¶ +___________¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶ +"; + } + } +} diff --git a/CourseApp/Transport.cs b/CourseApp/Transport.cs new file mode 100644 index 0000000..e528b1b --- /dev/null +++ b/CourseApp/Transport.cs @@ -0,0 +1,51 @@ +using System; + +namespace CourseApp +{ + public abstract class Transport + { + private string name; + private int dlina; + + public string Name + { + get + { + return name; + } + + set + { + if (value != null) + { + this.name = value; + } + } + } + + public int Dlina + { + get + { + return dlina; + } + + set + { + if (value > 1000 || value < 5) + { + Console.WriteLine("Невозможная длина корабля(min:5 max:1000)"); + throw new Exception(); + } + else + { + dlina = value; + } + } + } + + public abstract void Info(); + + public abstract string Predlojenie(); + } +} diff --git a/SQL/SQL.txt b/SQL/SQL.txt new file mode 100644 index 0000000..3901fc1 --- /dev/null +++ b/SQL/SQL.txt @@ -0,0 +1,17 @@ +1)select title from Movie where director ="Steven Spielberg"; + +2)select distinct year from Rating, Movie where stars >= 4 and Movie.mID=Rating.mID order by year; + +3)select title from Movie where Movie.mID not in (select Rating.mID from Rating); + +4)select name from Reviewer, Rating where Reviewer.rID=Rating.rID and Rating.ratingDate is null; + +5)select distinct Reviewer.name, Movie.title, Rating.stars, Rating.ratingDate from (Movie join Rating) join Reviewer on Rating.mID=Movie.mID and Rating.rID=Reviewer.rID order by Reviewer.name, Movie.title, Rating.stars; + +6)select distinct Reviewer.name, Movie.title from Movie, Reviewer, Rating R1,Rating R2 where R1.rID=Reviewer.rID and Movie.mID=R1.mID and R1.stars>R2.stars and R1.ratingDate > R2.ratingDate and (R1.rID=R2.rId and R1.ratingDate <> R2.ratingDate) and R1.ratingDate is not null and R2.ratingDate is not null and (R1.mID = R2.mId and R1.ratingDate <>R2.ratingDate); + +7)select title, max(stars) from Rating, Movie where Rating.mID = Movie.mID group by Rating.mID; + +8)select distinct title, avg(stars) from Movie, Rating where Movie.mID = Rating.mID group by title order by avg(stars) desc; + +9)select distinct name from Rating, Reviewer where Rating.rID = Reviewer.rID and stars >= 3; \ No newline at end of file diff --git a/stylecop/stylecop.json b/stylecop/stylecop.json new file mode 100644 index 0000000..643b8c1 --- /dev/null +++ b/stylecop/stylecop.json @@ -0,0 +1,15 @@ +{ + "$schema": + "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", + "settings": { + "documentationRules": { + "documentExposedElements": false, + "documentInterfaces": false, + "companyName": "Test Company", + "copyrightText": + "This source code is Copyright © {companyName} and MAY NOT be copied, reproduced,\npublished, distributed or transmitted to or stored in any manner without prior\nwritten consent from {companyName} (www.yourcompany.com).", + "xmlHeader": false + } + }, + "additionalArguments": ["./stylecop.ruleset", "./stylecop.json"] +} diff --git a/stylecop/stylecop.ruleset b/stylecop/stylecop.ruleset new file mode 100644 index 0000000..3350d0e --- /dev/null +++ b/stylecop/stylecop.ruleset @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file