From 36d04d768d087020a707fe4e29761835eb7b2e72 Mon Sep 17 00:00:00 2001 From: whiled0s Date: Fri, 5 Oct 2018 21:42:53 +0300 Subject: [PATCH] initial commit --- FirstLesson/FormAnalyzer/FormAnalyzer.sln | 22 +++++ FirstLesson/FormAnalyzer/FormAnalyzer/Form.cs | 20 +++++ .../FormAnalyzer/FormAnalyzer.csproj | 8 ++ .../FormAnalyzer/FormAnalyzer/Program.cs | 56 ++++++++++++ .../FormAnalyzer/FormAnalyzer/table-test.csv | 3 + .../FormAnalyzer/FormAnalyzer/table.csv | 16 ++++ .../TestProject/TestProject.csproj | 19 ++++ .../FormAnalyzer/TestProject/UnitTest1.cs | 87 +++++++++++++++++++ 8 files changed, 231 insertions(+) create mode 100644 FirstLesson/FormAnalyzer/FormAnalyzer.sln create mode 100644 FirstLesson/FormAnalyzer/FormAnalyzer/Form.cs create mode 100644 FirstLesson/FormAnalyzer/FormAnalyzer/FormAnalyzer.csproj create mode 100644 FirstLesson/FormAnalyzer/FormAnalyzer/Program.cs create mode 100644 FirstLesson/FormAnalyzer/FormAnalyzer/table-test.csv create mode 100644 FirstLesson/FormAnalyzer/FormAnalyzer/table.csv create mode 100644 FirstLesson/FormAnalyzer/TestProject/TestProject.csproj create mode 100644 FirstLesson/FormAnalyzer/TestProject/UnitTest1.cs diff --git a/FirstLesson/FormAnalyzer/FormAnalyzer.sln b/FirstLesson/FormAnalyzer/FormAnalyzer.sln new file mode 100644 index 0000000..c41ced3 --- /dev/null +++ b/FirstLesson/FormAnalyzer/FormAnalyzer.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormAnalyzer", "FormAnalyzer\FormAnalyzer.csproj", "{382F2E4B-3626-4392-957C-1F5B40FD2E65}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject", "TestProject\TestProject.csproj", "{5F29CD25-118C-4C92-BFCB-BE6C40649DD2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {382F2E4B-3626-4392-957C-1F5B40FD2E65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {382F2E4B-3626-4392-957C-1F5B40FD2E65}.Debug|Any CPU.Build.0 = Debug|Any CPU + {382F2E4B-3626-4392-957C-1F5B40FD2E65}.Release|Any CPU.ActiveCfg = Release|Any CPU + {382F2E4B-3626-4392-957C-1F5B40FD2E65}.Release|Any CPU.Build.0 = Release|Any CPU + {5F29CD25-118C-4C92-BFCB-BE6C40649DD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F29CD25-118C-4C92-BFCB-BE6C40649DD2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F29CD25-118C-4C92-BFCB-BE6C40649DD2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F29CD25-118C-4C92-BFCB-BE6C40649DD2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/FirstLesson/FormAnalyzer/FormAnalyzer/Form.cs b/FirstLesson/FormAnalyzer/FormAnalyzer/Form.cs new file mode 100644 index 0000000..717c30b --- /dev/null +++ b/FirstLesson/FormAnalyzer/FormAnalyzer/Form.cs @@ -0,0 +1,20 @@ +namespace FormAnalyzer +{ + public class Form + { + public string time; + public string name; + public string course; + public string institute; + public string dorm; + + public Form(string[] data) + { + time = data[0]; + name = data[1]; + course = data[2]; + institute = data[3]; + dorm = data[4]; + } + } +} \ No newline at end of file diff --git a/FirstLesson/FormAnalyzer/FormAnalyzer/FormAnalyzer.csproj b/FirstLesson/FormAnalyzer/FormAnalyzer/FormAnalyzer.csproj new file mode 100644 index 0000000..51b7f6c --- /dev/null +++ b/FirstLesson/FormAnalyzer/FormAnalyzer/FormAnalyzer.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + diff --git a/FirstLesson/FormAnalyzer/FormAnalyzer/Program.cs b/FirstLesson/FormAnalyzer/FormAnalyzer/Program.cs new file mode 100644 index 0000000..67bc740 --- /dev/null +++ b/FirstLesson/FormAnalyzer/FormAnalyzer/Program.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace FormAnalyzer +{ + public class Program + { + public static string path = @"/Users/whiled0s/Documents/Projects/C#/FormAnalyzer/FormAnalyzer/table.csv"; + + static void Main(string[] args) + { + var table = GetTable(path); + + Console.WriteLine(GetLineData("a;b;c;d")[0]); + } + + public static List
GetTable(string path) + { + string[] text = File.ReadAllLines(path); + + var table = new List(); + + for (var i = 1; i < text.Length; i++) + { + table.Add(new Form(GetLineData(text[i]))); + } + + return table; + } + + public static string[] GetLineData(string line) + { + return line.Trim().Trim(';').Split(';'); + } + + public static int GetFormsAmount(List table) + { + return table.Count(); + } + + public static int GetDormPeople(List table) + { + return table.FindAll(form => form.dorm == "Да").Count(); + } + + public static string GetCourseStatistics(List table) + { + return "first:\t" + table.FindAll(form => form.course.Substring(0, 1) == "1").Count().ToString() + + "\nsecond:\t" + table.FindAll(form => form.course.Substring(0, 1) == "2").Count().ToString() + + "\nthird:\t" + table.FindAll(form => form.course.Substring(0, 1) == "3").Count().ToString() + + "\nfourth:\t" + table.FindAll(form => form.course.Substring(0, 1) == "4").Count().ToString(); + } + } +} \ No newline at end of file diff --git a/FirstLesson/FormAnalyzer/FormAnalyzer/table-test.csv b/FirstLesson/FormAnalyzer/FormAnalyzer/table-test.csv new file mode 100644 index 0000000..468b24d --- /dev/null +++ b/FirstLesson/FormAnalyzer/FormAnalyzer/table-test.csv @@ -0,0 +1,3 @@ +Отметка времени;Имя и фамилия;Курс;Институт;Ты проживаешь в общежитии?;;;;;; +time;name;1 course;institute;Нет;;;;;; +time-2;name-2;2 course;institute-2;Да;;;;;; \ No newline at end of file diff --git a/FirstLesson/FormAnalyzer/FormAnalyzer/table.csv b/FirstLesson/FormAnalyzer/FormAnalyzer/table.csv new file mode 100644 index 0000000..98a3acb --- /dev/null +++ b/FirstLesson/FormAnalyzer/FormAnalyzer/table.csv @@ -0,0 +1,16 @@ +Отметка времени;Имя и фамилия;Курс;Институт;Ты проживаешь в общежитии?;;;;;; +9.14.2018 15:33:12;Dani Danyel Aristizabal ;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.14.2018 8:39:25;Татьяна Кузнецова;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.12.2018 0:19:01;Давид Хуриев;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.4.2018 22:05:19;Леон Минасян;1 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Нет;;;;;; +9.9.2018 23:53:10;Николай Ундалов;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.11.2018 0:21:51;Вишневский Марк;1 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.8.2018 21:28:33;Марат Идрисов ;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.13.2018 21:24:29;Юлия Гридунова;1 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Нет;;;;;; +9.2.2018 1:50:06;Игорь Спиридонов;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.3.2018 22:23:23;Николаев Павел Кириллович;3 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Нет;;;;;; +9.2.2018 21:55:42;Михаил Власов;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.12.2018 0:11:02;Виктор Григорьев;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.3.2018 0:02:47;Белов Артём;3 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.2.2018 16:42:22;Дарья Фадеева;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; +9.5.2018 20:01:41;Теселкина Валерия;2 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;; diff --git a/FirstLesson/FormAnalyzer/TestProject/TestProject.csproj b/FirstLesson/FormAnalyzer/TestProject/TestProject.csproj new file mode 100644 index 0000000..4cc0e32 --- /dev/null +++ b/FirstLesson/FormAnalyzer/TestProject/TestProject.csproj @@ -0,0 +1,19 @@ + + + + netcoreapp2.1 + + false + + + + + + + + + + + + + diff --git a/FirstLesson/FormAnalyzer/TestProject/UnitTest1.cs b/FirstLesson/FormAnalyzer/TestProject/UnitTest1.cs new file mode 100644 index 0000000..a47bfce --- /dev/null +++ b/FirstLesson/FormAnalyzer/TestProject/UnitTest1.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using FormAnalyzer; +using Xunit; +using Xunit.Sdk; + +namespace TestProject +{ + public class UnitTest1 + { + [Fact] + public void CallGetTable_Table() + { + var formOne = new Form(new string[] {"time", "name", "1 course", "institute", "Нет"}); + var formTwo = new Form(new string[] {"time-2", "name-2", "2 course", "institute-2", "Да"}); + + var path = @"/Users/whiled0s/Documents/Projects/C#/FormAnalyzer/FormAnalyzer/table-test.csv"; + + var tableOne = new List() {formOne, formTwo}; + + var tableTwo = Program.GetTable(path); + + Assert.Equal(tableOne.Count, tableTwo.Count); + + Assert.True(tableOne[0].time == tableTwo[0].time); + Assert.True(tableOne[0].name == tableTwo[0].name); + Assert.True(tableOne[0].course == tableTwo[0].course); + Assert.True(tableOne[0].institute == tableTwo[0].institute); + Assert.True(tableOne[0].dorm == tableTwo[0].dorm); + + Assert.True(tableOne[1].time == tableTwo[1].time); + Assert.True(tableOne[1].name == tableTwo[1].name); + Assert.True(tableOne[1].course == tableTwo[1].course); + Assert.True(tableOne[1].institute == tableTwo[1].institute); + Assert.True(tableOne[1].dorm == tableTwo[1].dorm); + } + + [Fact] + public void CallGetFormsAmount_Amount() + { + var formOne = new Form(new string[] {"time", "name", "1 course", "institute", "Нет"}); + var formTwo = new Form(new string[] {"time-2", "name-2", "2 course", "institute-2", "Да"}); + + var tableOne = new List() {formOne, formTwo}; + + Assert.Equal(Program.GetFormsAmount(tableOne), 2); + } + + [Fact] + public void CallGetDormPeople_Amount() + { + var formOne = new Form(new string[] {"time", "name", "1 course", "institute", "Нет"}); + var formTwo = new Form(new string[] {"time-2", "name-2", "2 course", "institute-2", "Да"}); + + var tableOne = new List() {formOne, formTwo}; + + Assert.Equal(Program.GetDormPeople(tableOne), 1); + } + + [Fact] + public void CallGetCourseStatistics_StatisticsString() + { + var formOne = new Form(new string[] {"time", "name", "1 course", "institute", "Нет"}); + var formTwo = new Form(new string[] {"time-2", "name-2", "2 course", "institute-2", "Да"}); + + var tableOne = new List() {formOne, formTwo}; + + Assert.Equal(Program.GetCourseStatistics(tableOne), "first:\t1\nsecond:\t1\nthird:\t0\nfourth:\t0"); + } + + [Fact] + public void CallGetLineData_StringArrData() + { + var str1 = "a;b;c;d"; + var str2 = "abcd"; + var str3 = ";;; ab;c;d;e ; "; + + var res1 = new [] {"a", "b", "c", "d"}; + + Assert.Equal(Program.GetLineData(str1).Length, 4); + + Assert.Equal(Program.GetLineData(str1), new []{"a", "b", "c", "d"}); + Assert.Equal(Program.GetLineData(str2), new []{"abcd"}); + Assert.Equal(Program.GetLineData(str3), new []{" ab", "c", "d", "e "}); + } + } +} \ No newline at end of file