From acc87a3d6cd381200b5350a44c59966d23159a7e Mon Sep 17 00:00:00 2001 From: koehle1u <nicolas.koehle7@etu.univ-lorraine.fr> Date: Sun, 9 Apr 2023 01:11:14 +0200 Subject: [PATCH] find_empty_machine + test.c --- src/schedule.c | 18 +++++++++++++++++- src/test.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/schedule.c b/src/schedule.c index f5a2a81..d80ba69 100644 --- a/src/schedule.c +++ b/src/schedule.c @@ -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) { diff --git a/src/test.c b/src/test.c index ba5c76f..221f061 100644 --- a/src/test.c +++ b/src/test.c @@ -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(); -- GitLab