Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request for first task #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions FirstLesson/FormAnalyzer/FormAnalyzer.sln
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions FirstLesson/FormAnalyzer/FormAnalyzer/Form.cs
Original file line number Diff line number Diff line change
@@ -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];
}
}
}
8 changes: 8 additions & 0 deletions FirstLesson/FormAnalyzer/FormAnalyzer/FormAnalyzer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

</Project>
56 changes: 56 additions & 0 deletions FirstLesson/FormAnalyzer/FormAnalyzer/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Form> GetTable(string path)
{
string[] text = File.ReadAllLines(path);

var table = new List<Form>();

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<Form> table)
{
return table.Count();
}

public static int GetDormPeople(List<Form> table)
{
return table.FindAll(form => form.dorm == "Да").Count();
}

public static string GetCourseStatistics(List<Form> 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();
}
}
}
3 changes: 3 additions & 0 deletions FirstLesson/FormAnalyzer/FormAnalyzer/table-test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Отметка времени;Имя и фамилия;Курс;Институт;Ты проживаешь в общежитии?;;;;;;
time;name;1 course;institute;Нет;;;;;;
time-2;name-2;2 course;institute-2;Да;;;;;;
16 changes: 16 additions & 0 deletions FirstLesson/FormAnalyzer/FormAnalyzer/table.csv
Original file line number Diff line number Diff line change
@@ -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 бакалавриат;Институт информационных технологий и автоматизированных систем управления (ИТАСУ);Да;;;;;;
19 changes: 19 additions & 0 deletions FirstLesson/FormAnalyzer/TestProject/TestProject.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\FormAnalyzer\FormAnalyzer.csproj" />
</ItemGroup>

</Project>
87 changes: 87 additions & 0 deletions FirstLesson/FormAnalyzer/TestProject/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -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<Form>() {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<Form>() {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<Form>() {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<Form>() {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 "});
}
}
}