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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ dkms.conf

# debug information files
*.dwo

*build/
42 changes: 42 additions & 0 deletions src/test/TestTask2.c
Copy link
Collaborator

Choose a reason for hiding this comment

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

6 баллов.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <stdbool.h>
#include <stdio.h>
#include "task2.h"

bool TestEqual()
{
bool A[] = {0,1,1,0};
bool B[] = {0,1,1,0};
return CompareBin(A, B, 4) == 0;
}

bool TestCompareBin()
{
bool A[] = {0,1,0,1};
bool B[] = {0,1,1,0};
return CompareBin(A, B, 4) == -1;
}

bool TestOneBitbit()
{
bool A[] = {1};
bool B[] = {0};
return CompareBin(A, B, 1) == 1;
}

bool TestAllZero()
{
bool A[] = {0,0,0,0};
bool B[] = {0,0,0,0};
return CompareBin(A, B, 4) == 0;
}


int main()
{
printf("TestEqual: %s\n", TestEqual() ? "PASS" : "FAIL");
printf("TestCompareBin: %s\n", TestCompareBin() ? "PASS" : "FAIL");
printf("TestOneBitbit: %s\n", TestOneBitbit() ? "PASS" : "FAIL");
printf("TestAllZero: %s\n", TestAllZero() ? "PASS" : "FAIL");

return 0;
}
59 changes: 59 additions & 0 deletions src/test/task1.c
Copy link
Collaborator

Choose a reason for hiding this comment

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

4 балла за попытку.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
int value;
struct Node* next;
} Node;


Node* CreateNode(int value, Node* next) {
Node* n = (Node*)malloc(sizeof(Node));
n->value = value;
n->next = next;
return n;
}

Node* reverse(Node* head) {
Node* prev = NULL;
Node* curr = head;
while (curr) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Если я правильно всё посчитал, то после одного шага цикла над списком из трех элементов, ссылка на последний элемент потеряется и всё.

Node* next = curr->next;
curr->next = prev;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Здесь можно записать в нулевой указатель

prev = curr;
curr = next;
}
return prev;
}

void FreeList(Node* head) {
while (head) {
Node* tmp = head;
head = head->next;
free(tmp);
}
}

typedef struct Queue {
Node* f;
Node* r;
} Queue;

Queue* createQueue() {
Queue* q = (Queue*)malloc(sizeof(Queue));
q->f = NULL;
q->r = NULL;
return q;
}

void enqueue(Queue* q, int value) {
q->f = CreateNode(value, q->f);

}


void dequeue(){

}


40 changes: 40 additions & 0 deletions src/test/task2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdbool.h>
#include "task2.h"


int CompareBin(bool A[], bool B[], int n)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Функции по стайлгайду называются в camelCase, переменные тоже.

Также к функциям принято писать комментарии. Здесь он очень нужен, потому что трактовка возвращаемого значения нетривиальна.

{
for (int i = 0; i < n; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

А если у чисел разная длина? Какой тогда контракт?

if (A[i] > B[i])
return 1;
if (A[i] < B[i])
return -1;
}
return 0;
}

int main()
{
int n;
scanf("%d", &n);

bool A[n], B[n];

for (int i = 0; i < n; i++)
scanf("%d", (int*)&A[i]);

for (int i = 0; i < n; i++)
scanf("%d", (int*)&B[i]);

int r = CompareBin(A, B, n);

if (r > 0)
printf("A > B\n");
else if
(r < 0) printf("A < B\n");
else
printf("A = B\n");

return 0;
}
Comment on lines +17 to +40
Copy link
Collaborator

Choose a reason for hiding this comment

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

Зачем Вам в библиотеке интерактивный main? Почему тестов не хватает?

Ещё и с глупыми ошибками типа кривого форматирования и неициализированных переменных.

4 changes: 4 additions & 0 deletions src/test/task2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#include <stdbool.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Если здесь уже есть stdbool.h, то в .c файле он не нужен.


int CompareBin(bool A[], bool B[], int n);