Skip to content
Snippets Groups Projects
Commit acc87a3d authored by KOEHLE Nicolas's avatar KOEHLE Nicolas
Browse files

find_empty_machine + test.c

parent 30856b71
No related branches found
No related tags found
No related merge requests found
......@@ -148,7 +148,7 @@ void save_schedule(struct schedule_t * S, char * filename) {
fclose(fp);
}
/*
int find_empty_machine(struct schedule_t * S, unsigned long time) {
// A FAIRE
assert(S);
......@@ -161,6 +161,22 @@ int find_empty_machine(struct schedule_t * S, unsigned long time) {
}
}
return -1;
} */
int find_empty_machine(struct schedule_t * S, unsigned long time) {
assert(S);
for (int i = 0; i < get_num_machines(S); i++) {
struct list_t* machine = get_schedule_of_machine(S, i);
if (list_is_empty(machine)) {
return i;
} else {
struct schedule_node_t* task = (struct schedule_node_t*) get_list_node_data(get_list_tail(machine));
if (time >= get_schedule_node_end_time(task)) {
return i;
}
}
}
return -1;
}
int find_machine_to_interrupt(struct schedule_t * S, unsigned long time, unsigned long processing_time) {
......
......@@ -187,7 +187,52 @@ void test_instance()
delete_instance(I, 1);
}
void test_instance_remove_task() {
Instance I = read_instance("test_tasks.txt");
printf("\nInstance avant suppression:\n");
view_instance(I);
struct list_node_t *node_to_remove = get_list_head(I);
list_remove_node(I, node_to_remove);
printf("\nInstance après suppression:\n");
view_instance(I);
// Libération de la mémoire
delete_instance(I, 1);
}
void test_schedule_creation_view() {
Instance I = new_list(view_task, delete_task);
struct task_t* task1 = new_task("T1", 5, 3);
struct task_t* task2 = new_task("T2", 3, 0);
struct task_t* task3 = new_task("T3", 2, 2);
struct task_t* task4 = new_task("T4", 1, 0);
list_insert_last(I, task1);
list_insert_last(I, task2);
list_insert_last(I, task3);
list_insert_last(I, task4);
printf("\nView instance::\n");
view_instance(I);
printf("Instance viewed \n");
struct schedule_t* S = create_schedule(I, 5, 0, 0);
printf("\nView Schedule:\n");
view_schedule(S);
delete_schedule(S);
printf("debug 1 !\n");
delete_instance(I, 0);
printf("debug 2 !\n");
printf("schedule func finished !\n");
}
int main() {
test_schedule_creation_view();
test_list_insert_last();
test_multiple_list_insert_first();
test_multiple_list_insert_after();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment