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

changed the access modificators and wrote the tests for my case #9

Merged
merged 7 commits into from
Apr 30, 2024
Merged
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
27 changes: 15 additions & 12 deletions src/methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@ namespace struct_lab_student
{
public partial class Program
{
static void Var9(List<Student> students)
public static void Var9(List<Student> students)
{
WriteData(ProcessData(students), "../data_new.txt");
Console.WriteLine("\nДані збережено у data_new.txt");
}

static void Var10(List<Student> students)
public static void Var10(List<Student> students)
{
Console.WriteLine("\nСписок студентів з відмінними оцінками з фізики:");
foreach (var student in Filter(students, IsTalentedPhysician))
Console.WriteLine($"{student.surName} {student.firstName} {student.patronymic} {EvalAverage(student):0.0} {student.scholarship}");
}

static void Var24(List<Student> students)

public static void Var24(List<Student> students)
{
Console.WriteLine("\nСписок студентів, які народились влітку:");
var summer_kids = Filter(students, IsSummer);
foreach (var dude in summer_kids)
Console.WriteLine($"{dude.surName} {dude.firstName} {EvalAverage(dude):0.0}");

Console.WriteLine($"\r{dude.surName} {dude.firstName} {EvalAverage(dude):0.0}");
}

static List<Student> ProcessData(List<Student> students)
private static List<Student> ProcessData(List<Student> students)
{
List<Student> processedStudents = [];

foreach (var student in students)
{
var newStudent = student;
Expand All @@ -37,13 +39,14 @@ static List<Student> ProcessData(List<Student> students)
return processedStudents;
}

static void WriteData(List<Student> students, string filename)
private static void WriteData(List<Student> students, string filename)
{
var max_len = students.Max(s=>s.surName.Length);
using (StreamWriter writer = new(filename)) {
var max_len = students.Max(s => s.surName.Length);
using (StreamWriter writer = new(filename))
{
foreach (var student in students)
{
writer.WriteLine($"{student.surName.PadRight(max_len+2)} {student.firstName.PadRight(max_len+2)} {student.patronymic.PadRight(max_len+2)} " +
writer.WriteLine($"{student.surName.PadRight(max_len + 2)} {student.firstName.PadRight(max_len + 2)} {student.patronymic.PadRight(max_len + 2)} " +
$"{student.sex,-3} {student.dateOfBirth,-12} {student.Marks[0],-3} {student.Marks[1],-3} {student.Marks[2],-3} " +
$"{student.scholarship}");
}
Expand All @@ -55,13 +58,13 @@ public static IEnumerable<Student> Filter(List<Student> students, Func<Student,
return students.Where(Condition);
}

private static bool IsSummer(Student student)
public static bool IsSummer(Student student)
{
int month = int.Parse(student.dateOfBirth[3..5]);
return month >= 6 && month <= 8;
}

private static bool IsTalentedPhysician(Student student)
public static bool IsTalentedPhysician(Student student)
{
return student.Marks[1] == '5';
}
Expand Down
1 change: 1 addition & 0 deletions tests/runTest.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet build ./src/src.sln && dotnet build ./tests/ && dotnet test --no-build --verbosity normal ./tests
37 changes: 33 additions & 4 deletions tests/tests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
using Xunit;
using struct_lab_student;

namespace student_tests {
public partial class Tests {
namespace student_tests
{
public partial class Tests
{
[Fact]
public static void Student_Constructor_ReturnStudentList() {
public static void Student_Constructor_ReturnStudentList()
{
List<Student> students = [];
students.Add(new("Прізвище1 Ім'я1 По-батькові1 M 02.02.2000 3 4 5 1234"));
students.Add(new("surname FIRST_NAME 🔥 F 02.02.2000 4 - 2 1234"));
students.Add(new("1 2 3 4 5 - - - 6"));
Comment on lines 12 to 14
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

чого андрущенка в тест кейсах нема

Console.WriteLine(students.Count < 3 ? "this is a test, stupid" : "no way!");
}

[Fact]
public static void TestVar10()
{
List<Student> students = [];
students.Add(new("Андрущенко Вадим Миколайович M 23.06.2004 2 1 - 1285"));
students.Add(new("Стакан Єгор Олександрович Ч 04.01.2006 4 5 3 4319"));
students.Add(new("Кірпіч Влад Шварцович Ч 12.06.1998 4 4 5 3538"));
students.Add(new("Муха Саня Респектович F 12.11.1999 3 5 4 3392"));

int count = 0;
foreach (Student student in students)
{
if (Program.IsTalentedPhysician(student))
count++;
}
Assert.Equal(2, count);

double[] expectedAverages = { 1.7, 4.0, 4.3, 4.0 };
int counter = 0;
foreach (var student in students)
{
Assert.Equal(Program.EvalAverage(student), expectedAverages[counter]);
counter++;
}
}
}
}
}