Skip to content

Commit

Permalink
мердж тестс
Browse files Browse the repository at this point in the history
changed the access modificators and wrote the tests for my case
  • Loading branch information
flovnes authored Apr 30, 2024
2 parents 73f556a + 2c1852a commit da617be
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
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"));
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++;
}
}
}
}
}

0 comments on commit da617be

Please sign in to comment.