Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/dotnetcore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
dotnet: [ '2.1', '3.1.x', '5.0.x' ]
dotnet: [ '6.0.x' ]

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp5</TargetFramework>
<TargetFramework>netcoreapp6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
22 changes: 22 additions & 0 deletions CourseApp.Tests/UnitTestsClass.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
64 changes: 64 additions & 0 deletions CourseApp.Tests/UnitTestsData.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
namespace CourseApp.Tests
{
using CourseApp.Program.Input;
using Xunit;

public class InputValueUnitTests
public class UnitTestsInputValue
{
[Theory]
[InlineData(0, -1, 2, true)]
Expand Down Expand Up @@ -44,11 +43,11 @@ public void TestInputInt(string item, int minValue, int maxValue, bool expected)
}

[Theory]
[InlineData("2.2", 0, 3, true)]
[InlineData("0", 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, 5, true)]
[InlineData(" ", 4, 4, false)]
public void TestInputDouble(string item, int minValue, int maxValue, bool expected)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
namespace CourseApp.Tests
{
using System.Collections.Generic;
using CourseApp.Program;
using Xunit;
using static System.Math;

public class UnitTests
public class UnitTestsTask
{
[Theory]
[InlineData(3, 2, 0.11, 1.56)]
Expand Down
2 changes: 1 addition & 1 deletion CourseApp/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/netcoreapp5/CourseApp.dll",
"program": "${workspaceFolder}/bin/Debug/netcoreapp6.0/CourseApp.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "externalTerminal",
Expand Down
2 changes: 1 addition & 1 deletion CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp5</TargetFramework>
<TargetFramework>netcoreapp6.0</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
</PropertyGroup>

Expand Down
12 changes: 9 additions & 3 deletions CourseApp/MainFile.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
namespace CourseApp
{
using System;
using CourseApp.Program;

public class MainFile
{
public static void Main(string[] args)
{
var userInterface = new UserInterface();
userInterface.StartPage();
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CourseApp.Program
namespace CourseApp
{
using System.Collections.Generic;
using static System.Math;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
namespace CourseApp.Program
namespace CourseApp
{
using System;
using System.Collections.Generic;
using CourseApp.Program.Input;

public class UserInterface
public class TaskUserInterface
{
public UserInterface()
public TaskUserInterface()
{
Console.WriteLine("Hello!");
}
Expand Down Expand Up @@ -39,8 +38,6 @@ public void StartPage()
break;
}
}

Environment.Exit(0);
}

private void DefaultCalculations(List<double> listValues)
Expand Down
129 changes: 129 additions & 0 deletions CourseApp/Program/2 - ClassTask/ClassUserInterfaceClass.cs
Original file line number Diff line number Diff line change
@@ -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<string> customValues = InputCustomValues();
while (customValues.Count != 4)
{
customValues = InputCustomValues();
}

var file = new FileCreator(customValues);
Console.WriteLine($"Custom file{file.Display()}");
}

private List<string> InputCustomValues()
{
Console.Clear();
var customValues = new List<string>();
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();
}
}
}
21 changes: 21 additions & 0 deletions CourseApp/Program/2 - ClassTask/Enums/EnumExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace CourseApp
{
public enum EnumExtension
{
Txt,
Pdf,
Jpeg,
Cs,
Html,
Png,
Abb,
Mp3,
Mp4,
Apk,
Exe,
Tif,
Gif,
Jpg,
Bak,
}
}
23 changes: 23 additions & 0 deletions CourseApp/Program/2 - ClassTask/Enums/EnumName.cs
Original file line number Diff line number Diff line change
@@ -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,
}
}
Loading