refactor(structure): normalize folder names with leading zeros for consistency
- Renamed all folders from format NEx (e.g., 1Ex, 2Ex...) to 0NEx (01Ex, 02Ex, etc.) - Updated subdirectories and files accordingly - Removed old main Makefile and tasks (a01.c–a09.c, solve.c, io_status.h), likely obsolete - Cleaned up deprecated task binaries and configs
This commit is contained in:
parent
2cf18a1ff3
commit
8a7aac7c23
385 changed files with 2 additions and 1468 deletions
19
2025.02.28/07Ex/Makefile
Normal file
19
2025.02.28/07Ex/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
|||
FLAGS = -fstack-protector-all -W -Wall -Wextra -Wunused -Wcast-align -Werror -pedantic -pedantic-errors -Wfloat-equal -Wpointer-arith -Wformat-security -Wmissing-format-attribute -Wformat=1 -Wwrite-strings -Wcast-align -Wno-long-long -std=gnu99 -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wold-style-definition -Wdeclaration-after-statement -Wbad-function-cast -Wnested-externs -O3
|
||||
|
||||
a07.exe: main.o array.o solve.o sort.o
|
||||
gcc main.o solve.o array.o sort.o -o a07.exe -lssp
|
||||
|
||||
main.o: main.c
|
||||
gcc $(CFLAGS) -c main.c
|
||||
|
||||
solve.o: solve.c
|
||||
gcc $(FLAGS) -c solve.c
|
||||
|
||||
array.o: array.c
|
||||
gcc $(CFLAGS) -c array.c
|
||||
|
||||
sort.o: sort.c
|
||||
gcc $(CFLAGS) -c sort.c
|
||||
|
||||
clean:
|
||||
del *.o *.exe
|
8
2025.02.28/07Ex/a.txt
Normal file
8
2025.02.28/07Ex/a.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
zzzzzzzz
|
||||
zzzzzzz
|
||||
zzzzzz
|
||||
zzzzz
|
||||
zzzz
|
||||
zzz
|
||||
zz
|
||||
z
|
73
2025.02.28/07Ex/array.c
Normal file
73
2025.02.28/07Ex/array.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
#include "array.h"
|
||||
|
||||
io_status read_array(char* a[], int n, const char * name)
|
||||
{
|
||||
char buf[LEN] = {0};
|
||||
FILE *fp = 0;
|
||||
int i, j;
|
||||
|
||||
if (!(fp = fopen(name, "r"))) return ERROR_OPEN;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (!fgets(buf, sizeof(buf), fp))
|
||||
{
|
||||
fclose(fp);
|
||||
free_array(a, i);
|
||||
return ERROR_READ;
|
||||
}
|
||||
|
||||
for (j = 0; buf[j]; j++)
|
||||
{
|
||||
if (buf[j] == '\n')
|
||||
{
|
||||
buf[j] = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
a[i] = (char *)malloc((j+1) * sizeof(char));
|
||||
if (!a[i])
|
||||
{
|
||||
fclose(fp);
|
||||
free_array(a, i);
|
||||
return ERROR_MEM;
|
||||
}
|
||||
|
||||
strcpy(a[i], buf);
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void free_array(char ** a, int n)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < n; ++i)
|
||||
{
|
||||
if (a[i])
|
||||
{
|
||||
free(a[i]);
|
||||
a[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void print_array(char ** a, int n, int m)
|
||||
{
|
||||
int l = (n > m ? m : n);
|
||||
int i;
|
||||
for (i = 0; i < l; ++i) printf("%s\n", a[i]);
|
||||
}
|
||||
|
||||
int check(char **a, int n, int (*cmp)(const char *, const char *))
|
||||
{
|
||||
/* Каждый элемент больше следующего */
|
||||
int i; int count = 0;
|
||||
for (i = 1; i < n; i++)
|
||||
{
|
||||
if ((*cmp)(a[i-1], a[i]) > 0)
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
15
2025.02.28/07Ex/array.h
Normal file
15
2025.02.28/07Ex/array.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#include "io_status.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
io_status read_array(char *a[], int n, const char *name);
|
||||
void free_array(char **a, int n);
|
||||
void print_array(char **a, int n, int m);
|
||||
int check(char **a, int n, int (*cmp)(const char *, const char *));
|
||||
|
||||
#endif
|
14
2025.02.28/07Ex/io_status.h
Normal file
14
2025.02.28/07Ex/io_status.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef IO_STATUS_H
|
||||
#define IO_STATUS_H
|
||||
|
||||
#define LEN 1234
|
||||
|
||||
typedef enum _io_status
|
||||
{
|
||||
SUCCESS,
|
||||
ERROR_OPEN,
|
||||
ERROR_READ,
|
||||
ERROR_MEM
|
||||
} io_status;
|
||||
|
||||
#endif
|
68
2025.02.28/07Ex/main.c
Normal file
68
2025.02.28/07Ex/main.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
#include "solve.h"
|
||||
#include "sort.h"
|
||||
#include "array.h"
|
||||
#include "io_status.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
/* ./a07.out c n p filename */
|
||||
int c, n, p, diff, task = 7;
|
||||
io_status ret;
|
||||
char *name, **a;
|
||||
int (*cmp)(const char *, const char *);
|
||||
int (*f[])(const char *, const char *) = {up_strcmp, down_strcmp, up_len, down_len};
|
||||
int len_f = sizeof(f) / sizeof(f[0]);
|
||||
double t;
|
||||
|
||||
if (!(argc == 5 && sscanf(argv[1], "%d", &c) && sscanf(argv[2], "%d", &n) == 1 && sscanf(argv[3], "%d", &p) == 1 && c >= 1 && c <= len_f))
|
||||
{
|
||||
printf("Usage %s c n p name\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
name = argv[4];
|
||||
cmp = f[c-1];
|
||||
|
||||
if (!(a = (char **)malloc(n * sizeof(char *))))
|
||||
{
|
||||
printf("Not enough memory: \n");
|
||||
return 2;
|
||||
}
|
||||
ret = read_array(a, n, name);
|
||||
|
||||
do {
|
||||
switch(ret)
|
||||
{
|
||||
case SUCCESS:
|
||||
continue;
|
||||
case ERROR_OPEN:
|
||||
printf("Cannot open %s\n", name);
|
||||
break;
|
||||
case ERROR_READ:
|
||||
printf("Cannot read %s\n", name);
|
||||
break;
|
||||
case ERROR_MEM:
|
||||
printf("Not enough memory");
|
||||
break;
|
||||
}
|
||||
free(a);
|
||||
return 3;
|
||||
} while (0);
|
||||
|
||||
print_array(a, n, p);
|
||||
t = clock();
|
||||
t7_solve(a, n, cmp);
|
||||
t = (clock() - t) / CLOCKS_PER_SEC;
|
||||
diff = check(a, n, cmp);
|
||||
|
||||
printf("New array:\n");
|
||||
print_array(a, n, p);
|
||||
printf("%s : Task = %d Diff = %d Elapsed = %.2f\n", argv[0], task, diff, t);
|
||||
|
||||
free_array(a, n);
|
||||
free(a);
|
||||
|
||||
return 0;
|
||||
}
|
25
2025.02.28/07Ex/solve.c
Normal file
25
2025.02.28/07Ex/solve.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
#include "solve.h"
|
||||
|
||||
void t7_solve(char **a, int n, int (*cmp)(const char *, const char *))
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < n; ++i) append(a, i+1, a[i], find(a, i, a[i], cmp));
|
||||
}
|
||||
|
||||
int find(char **a, int n, char *x, int (*cmp)(const char *, const char *)) {
|
||||
int avg = (n + (-1)*(n%2)) / 2;
|
||||
int comp;
|
||||
|
||||
if (n == 0) return 0;
|
||||
|
||||
comp = cmp(x, a[avg]);
|
||||
if (comp < 0) return find(a, avg, x, cmp);
|
||||
if (comp > 0) return avg+1 + find(a+(avg+1), n-(avg+1), x, cmp);
|
||||
else return avg;
|
||||
}
|
||||
|
||||
void append(char **arr, int n, char *a, int index)
|
||||
{
|
||||
for (int i = n-1; i > index; --i) arr[i] = arr[i-1];
|
||||
arr[index] = a;
|
||||
}
|
10
2025.02.28/07Ex/solve.h
Normal file
10
2025.02.28/07Ex/solve.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef SOLVE_H
|
||||
#define SOLVE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void t7_solve(char **a, int n, int (*cmp)(const char *, const char *));
|
||||
int find(char **arr, int n, char *a, int (*cmp)(const char *, const char *));
|
||||
void append(char **arr, int n, char *a, int index);
|
||||
|
||||
#endif
|
23
2025.02.28/07Ex/sort.c
Normal file
23
2025.02.28/07Ex/sort.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "sort.h"
|
||||
|
||||
int up_strcmp(const char *a, const char *b)
|
||||
{ return strcmp(a, b); }
|
||||
|
||||
int down_strcmp(const char *a, const char *b)
|
||||
{ return -strcmp(a, b); }
|
||||
|
||||
int up_len(const char *a, const char *b)
|
||||
{
|
||||
int i = 0;
|
||||
while (1)
|
||||
{
|
||||
if (a[i] == '\0' && b[i] == '\0') return strcmp(a, b);
|
||||
else if (a[i] == '\0') return -1;
|
||||
else if (b[i] == '\0') return 1;
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
int down_len(const char *a, const char *b)
|
||||
{ return -up_len(a, b); }
|
||||
|
11
2025.02.28/07Ex/sort.h
Normal file
11
2025.02.28/07Ex/sort.h
Normal file
|
@ -0,0 +1,11 @@
|
|||
#ifndef SORT_H
|
||||
#define SORT_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
int up_strcmp(const char *a, const char *b);
|
||||
int down_strcmp(const char *a, const char *b);
|
||||
int up_len(const char *a, const char *b);
|
||||
int down_len(const char *a, const char *b);
|
||||
|
||||
#endif
|
231
2025.02.28/07Ex/test_cases.json
Normal file
231
2025.02.28/07Ex/test_cases.json
Normal file
|
@ -0,0 +1,231 @@
|
|||
{
|
||||
"exe": "a07.exe",
|
||||
"filename": "input.txt",
|
||||
"tests": [
|
||||
{
|
||||
"c": 1,
|
||||
"text": "1\n3\n2\n4\n5",
|
||||
"expected": "1\n2\n3\n4\n5"
|
||||
},
|
||||
{
|
||||
"c": 2,
|
||||
"text": "apple\nbanana\ncherry\ndate",
|
||||
"expected": "date\ncherry\nbanana\napple"
|
||||
},
|
||||
{
|
||||
"c": 3,
|
||||
"text": "a\nabcde\nabc\nabcd",
|
||||
"expected": "a\nabc\nabcd\nabcde"
|
||||
},
|
||||
{
|
||||
"c": 4,
|
||||
"text": "a\nabcde\nabc\nabcd",
|
||||
"expected": "abcde\nabcd\nabc\na"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "",
|
||||
"expected": ""
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "onlyone",
|
||||
"expected": "onlyone"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "same\nsame\nsame\nsame",
|
||||
"expected": "same\nsame\nsame\nsame"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "apple\nbanana\ncherry\ndate",
|
||||
"expected": "apple\nbanana\ncherry\ndate"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "date\ncherry\nbanana\napple",
|
||||
"expected": "apple\nbanana\ncherry\ndate"
|
||||
},
|
||||
{
|
||||
"c": 3,
|
||||
"text": "a\nbbbbbbbbbbbbbbbbbbbbbbbb\nccc",
|
||||
"expected": "a\nccc\nbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "Apple\nbanana\nCherry\ndate",
|
||||
"expected": "Apple\nCherry\nbanana\ndate"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": " apple\nbanana\n cherry\ndate",
|
||||
"expected": " apple\n cherry\nbanana\ndate"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "10\n2\n1",
|
||||
"expected": "1\n10\n2"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "abc\nabcd\nabcde",
|
||||
"expected": "abc\nabcd\nabcde"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "1\n3\n2\n4\n5",
|
||||
"expected": "1\n2\n3\n4\n5"
|
||||
},
|
||||
{
|
||||
"c": 2,
|
||||
"text": "apple\nbanana\ncherry\ndate",
|
||||
"expected": "date\ncherry\nbanana\napple"
|
||||
},
|
||||
{
|
||||
"c": 3,
|
||||
"text": "a\nabcde\nabc\nabcd",
|
||||
"expected": "a\nabc\nabcd\nabcde"
|
||||
},
|
||||
{
|
||||
"c": 4,
|
||||
"text": "a\nabcde\nabc\nabcd",
|
||||
"expected": "abcde\nabcd\nabc\na"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "",
|
||||
"expected": ""
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "onlyone",
|
||||
"expected": "onlyone"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "same\nsame\nsame\nsame",
|
||||
"expected": "same\nsame\nsame\nsame"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "apple\nbanana\ncherry\ndate",
|
||||
"expected": "apple\nbanana\ncherry\ndate"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "date\ncherry\nbanana\napple",
|
||||
"expected": "apple\nbanana\ncherry\ndate"
|
||||
},
|
||||
{
|
||||
"c": 3,
|
||||
"text": "a\nbbbbbbbbbbbbbbbbbbbbbbbb\nccc",
|
||||
"expected": "a\nccc\nbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "Apple\nbanana\nCherry\ndate",
|
||||
"expected": "Apple\nCherry\nbanana\ndate"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": " apple\nbanana\n cherry\ndate",
|
||||
"expected": " apple\n cherry\nbanana\ndate"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "10\n2\n1",
|
||||
"expected": "1\n10\n2"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "abc\nabcd\nabcde",
|
||||
"expected": "abc\nabcd\nabcde"
|
||||
},
|
||||
{
|
||||
"c": 2,
|
||||
"text": "zoo\napple\nbanana\ncherry",
|
||||
"expected": "zoo\ncherry\nbanana\napple"
|
||||
},
|
||||
{
|
||||
"c": 3,
|
||||
"text": "abcd\na\nabcdef\nabc",
|
||||
"expected": "a\nabc\nabcd\nabcdef"
|
||||
},
|
||||
{
|
||||
"c": 4,
|
||||
"text": "abcd\na\nabcdef\nabc",
|
||||
"expected": "abcdef\nabcd\nabc\na"
|
||||
},
|
||||
{
|
||||
"c": 3,
|
||||
"text": "12345\n1234\n123\n12\n1",
|
||||
"expected": "1\n12\n123\n1234\n12345"
|
||||
},
|
||||
{
|
||||
"c": 4,
|
||||
"text": "12345\n1234\n123\n12\n1",
|
||||
"expected": "12345\n1234\n123\n12\n1"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "hello\nHELLO\nhElLo\nHeLLo",
|
||||
"expected": "HELLO\nHeLLo\nhElLo\nhello"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "A\nB\nC\nD\nE",
|
||||
"expected": "A\nB\nC\nD\nE"
|
||||
},
|
||||
{
|
||||
"c": 2,
|
||||
"text": "A\nB\nC\nD\nE",
|
||||
"expected": "E\nD\nC\nB\nA"
|
||||
},
|
||||
{
|
||||
"c": 3,
|
||||
"text": "aaa\nbb\nc",
|
||||
"expected": "c\nbb\naaa"
|
||||
},
|
||||
{
|
||||
"c": 4,
|
||||
"text": "aaa\nbb\nc",
|
||||
"expected": "aaa\nbb\nc"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "zzzzzzzz\nzzzzzzz\nzzzzzz\nzzzzz\nzzzz\nzzz\nzz\nz",
|
||||
"expected": "z\nzz\nzzz\nzzzz\nzzzzz\nzzzzzz\nzzzzzzz\nzzzzzzzz"
|
||||
},
|
||||
{
|
||||
"c": 4,
|
||||
"text": "zzzzzzzz\nzzzzzzz\nzzzzzz\nzzzzz\nzzzz\nzzz\nzz\nz",
|
||||
"expected": "zzzzzzzz\nzzzzzzz\nzzzzzz\nzzzzz\nzzzz\nzzz\nzz\nz"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "z\nzz\nzzz\nzzzz\nzzzzz\nzzzzzz\nzzzzzzz\nzzzzzzzz",
|
||||
"expected": "z\nzz\nzzz\nzzzz\nzzzzz\nzzzzzz\nzzzzzzz\nzzzzzzzz"
|
||||
},
|
||||
{
|
||||
"c": 2,
|
||||
"text": "z\nzz\nzzz\nzzzz\nzzzzz\nzzzzzz\nzzzzzzz\nzzzzzzzz",
|
||||
"expected": "zzzzzzzz\nzzzzzzz\nzzzzzz\nzzzzz\nzzzz\nzzz\nzz\nz"
|
||||
},
|
||||
{
|
||||
"c": 1,
|
||||
"text": "3\n1\n4\n1\n5\n9\n2\n6\n5\n3",
|
||||
"expected": "1\n1\n2\n3\n3\n4\n5\n5\n6\n9"
|
||||
},
|
||||
{
|
||||
"c": 3,
|
||||
"text": "hello\nworld\nhi\ncode",
|
||||
"expected": "hi\ncode\nhello\nworld"
|
||||
},
|
||||
{
|
||||
"c": 4,
|
||||
"text": "hello\nworld\nhi\ncode",
|
||||
"expected": "world\nhello\ncode\nhi"
|
||||
}
|
||||
]
|
||||
}
|
138
2025.02.28/07Ex/test_runner.py
Normal file
138
2025.02.28/07Ex/test_runner.py
Normal file
|
@ -0,0 +1,138 @@
|
|||
import json
|
||||
import subprocess
|
||||
import os
|
||||
import time
|
||||
import platform
|
||||
from colorama import Fore, Style, init
|
||||
|
||||
# Enable color support in Windows
|
||||
init(autoreset=True)
|
||||
|
||||
def color_text(text, color):
|
||||
"""Returns colored text"""
|
||||
return color + text + Style.RESET_ALL
|
||||
|
||||
class TestCase:
|
||||
"""Represents a single test case"""
|
||||
def __init__(self, c, text, expected, p=None, debug=False):
|
||||
self.c = c
|
||||
self.text = text
|
||||
self.expected = expected
|
||||
self.p = p
|
||||
self.debug = debug
|
||||
|
||||
def get_num_lines(self):
|
||||
"""Returns the number of lines in the input text (n)"""
|
||||
return self.text.count("\n") + 1 # +1, чтобы учесть последнюю строку
|
||||
|
||||
def should_fail(self):
|
||||
"""Checks if the test expects a failure"""
|
||||
return self.expected.lower() == "fall"
|
||||
|
||||
class TestSuite:
|
||||
"""Handles loading and running test cases"""
|
||||
def __init__(self, config_file):
|
||||
self.config = self.load_config(config_file)
|
||||
self.exe = self.config["exe"]
|
||||
self.filename = self.config["filename"]
|
||||
self.tests = [TestCase(**test) for test in self.config["tests"]]
|
||||
|
||||
@staticmethod
|
||||
def load_config(filename):
|
||||
"""Loads test cases from JSON"""
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
def run_command(cmd, exit_on_error=False):
|
||||
"""Runs a shell command and handles errors"""
|
||||
try:
|
||||
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
return result
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(color_text(f"[ERROR] Command failed: {cmd}", Fore.RED))
|
||||
print(e.stderr)
|
||||
if exit_on_error:
|
||||
exit(1)
|
||||
return None
|
||||
|
||||
def wait_for_executable(exe):
|
||||
"""Waits for the executable file to appear after compilation"""
|
||||
print(color_text(f"[WAIT] Waiting for {exe} to be compiled...", Fore.YELLOW))
|
||||
while not os.path.exists(exe):
|
||||
time.sleep(0.1) # Reduce CPU usage
|
||||
print(color_text(f"[READY] {exe} compiled successfully.", Fore.GREEN))
|
||||
|
||||
def parse_sorted_output(output):
|
||||
"""Extracts the second print_array output from program output"""
|
||||
parts = output.split("New array:\n")
|
||||
if len(parts) > 1:
|
||||
sorted_array = parts[1].rstrip().split("\n")
|
||||
sorted_array = sorted_array[:-1] # Убираем последнюю строку (Task = ... Diff = ... Elapsed = ...)
|
||||
return "\n".join(sorted_array)
|
||||
return ""
|
||||
|
||||
def run_test(test_suite, test):
|
||||
"""Runs the program and checks its result"""
|
||||
exe, filename = test_suite.exe, test_suite.filename
|
||||
n = test.get_num_lines() # Auto-count lines in input
|
||||
p = test.p if test.p is not None else n # Default p = n
|
||||
|
||||
# Write input data to a file (Ensure last line has \n)
|
||||
with open(filename, "w", encoding="utf-8") as f:
|
||||
text = test.text.rstrip() + "\n" # Если нет \n в конце, добавляем
|
||||
f.write(text)
|
||||
|
||||
# Windows fix: remove './' for executables
|
||||
cmd = [exe, str(test.c), str(n), str(p), filename]
|
||||
if test.debug:
|
||||
cmd.append("DEBUG")
|
||||
|
||||
# Run the program
|
||||
result = run_command(cmd)
|
||||
|
||||
# Check if test expected failure
|
||||
if test.should_fail():
|
||||
if result and result.returncode != 0:
|
||||
print(color_text(f"[PASS] Test '{test.c}' correctly failed (expected crash).", Fore.GREEN))
|
||||
else:
|
||||
print(color_text(f"[FAIL] Test '{test.c}' should have failed but did not.", Fore.RED))
|
||||
return
|
||||
|
||||
# Extract sorted array output
|
||||
sorted_output = parse_sorted_output(result.stdout) if result else None
|
||||
|
||||
# Check result
|
||||
if sorted_output == test.expected:
|
||||
print(color_text(f"[PASS] Test '{test.c}' passed.", Fore.GREEN))
|
||||
else:
|
||||
print(color_text(f"[FAIL] Test '{test.c}' failed.", Fore.RED))
|
||||
print(f"Expected:\n{test.expected}")
|
||||
print(f"Got:\n{sorted_output}")
|
||||
if test.debug:
|
||||
print(color_text("[DEBUG] Full Program Output:", Fore.YELLOW))
|
||||
print(result.stdout)
|
||||
|
||||
# Cleanup test files
|
||||
try:
|
||||
os.remove(filename)
|
||||
except (FileNotFoundError, PermissionError):
|
||||
print(color_text(f"[WARNING] Could not delete {filename}, Windows may be locking it.", Fore.RED))
|
||||
|
||||
def main():
|
||||
print(color_text("[CLEAN] Cleaning project...", Fore.BLUE))
|
||||
run_command("make clean", exit_on_error=True)
|
||||
|
||||
print(color_text("[BUILD] Compiling project...", Fore.BLUE))
|
||||
run_command("make", exit_on_error=True)
|
||||
|
||||
test_suite = TestSuite("test_cases.json")
|
||||
wait_for_executable(test_suite.exe)
|
||||
|
||||
for test in test_suite.tests:
|
||||
run_test(test_suite, test)
|
||||
|
||||
print(color_text("[CLEAN] Final cleanup...", Fore.BLUE))
|
||||
run_command("make clean")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue