Skip to content

Hw10: Тесты к Сортированному списку#7

Open
DolzhenkoAlexa wants to merge 3 commits intomainfrom
HW10_Dolzhenko_tests
Open

Hw10: Тесты к Сортированному списку#7
DolzhenkoAlexa wants to merge 3 commits intomainfrom
HW10_Dolzhenko_tests

Conversation

@DolzhenkoAlexa
Copy link
Owner

Файлы: основной sortListForTests.c и заголовочный sortListForTests.h с функционалом сортированного списка и 2 файла для тестов tests.c и заголовочный tests.h

Также есть интсрукция README.md с тем, как запускать тесты

Выполнено: Долженко Александра
(Дата и время: 19.11.2025 23:45)

Choose a reason for hiding this comment

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

Если я правильно понимаю, все домашки, начиная с этой, должны использовать CMake.

Choose a reason for hiding this comment

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

Нужно использовать сортированный список из домашки про него, а не писать заново.

Comment on lines +80 to +84
if (checkList(list, expected, count)) {
printf("Результат: пройден!\n");
} else {
printf("Результат: НЕ пройден\n");
}

Choose a reason for hiding this comment

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

Вам не надоело каждый раз писать этот if? Лучше каждый тест сделать отдельной функцией, а в runTests оставить только их запуск и вывод результата.
Если знаете, что такое указатель на функцию, то вообще можно сделать очень красиво.

Comment on lines +38 to +67
// Вставка в лист и изменение expected, в конце - сортировка массива
void insertElem(struct List* list, int value, int expected[], int* count)
{
insertElement(list, findPosition(list, value), value);
expected[*count] = value;
(*count)++;
bubbleSort(expected, *count);
}

// Удаление элемента из списка и из expected
void deleteElem(struct List* list, int value, int expected[], int* count)
{
int pos = checkElement(list, value);
if (pos != -1) {
deleteElement(list, pos);
}
int found = -1;
for (int i = 0; i < *count; i++) {
if (expected[i] == value) {
found = i;
break;
}
}
if (found != -1) {
for (int i = found; i < *count - 1; i++) {
expected[i] = expected[i + 1];
}
(*count)--;
}
}

Choose a reason for hiding this comment

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

Мне кажется, проще было бы реализовать создание списка из массива и дальше делать тесты такого формата:

int testInsert() {
    int initial[] = {1, 3, 4, 7};
    List* lst = createListFromArr(initial, 4);
    insertElem(lst, 5);
    int expected[] = {1, 3, 4, 5, 7};
    return checkList(lst, exepected, 5);
}

По крайней мере, в таком случае не нужно вручную проделывать всю цепочку вставок и удалений, чтобы понять, что происходит в последнем тесте.

Comment on lines +186 to +188
list = NULL;
count = 0;
if (list == NULL && count == 0) {

Choose a reason for hiding this comment

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

В каком случае этот тест может не пройти?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants