StudyPlanner/src/test.c

63 lines
1.5 KiB
C
Raw Normal View History

#include "config.h"
#include "db.h"
#include "iCal.h"
#include "llist.h"
#include "planner.h" // for subject and event structs
#include "ui.h"
2024-12-12 16:08:19 +01:00
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
time_t now = time(NULL);
// create new task named LinAlg with priority 3, created now with deadline in
// 5 days sp is currently unused spare var
Task *t1 = newTask("LinAlg", now, now + days(5), 3, 0);
2024-12-12 16:08:19 +01:00
assert(t1 != NULL);
// Stack Allocated vars only for local use!
2024-12-12 16:08:19 +01:00
Task *t2 = newTask("Phys", now, now + days(2), 7, 0);
assert(t2 != NULL);
Task *t3 = newTask("Analysis", now, now + days(10), 5, 0);
assert(t3 != NULL);
Task *t4 = newTask("TM1", now, now + days(1), 9, 0);
assert(t4 != NULL);
printf("%s\n", ctime(&now));
// new llist test
llist *list1 = llistNew(t1, cmpTaskN);
2024-12-12 16:08:19 +01:00
llistAppend(list1, t2);
llistAppend(list1, t3);
llistAppend(list1, t4);
genPlan(list1);
// print test tasks
printTask(t1);
2024-12-12 16:08:19 +01:00
printTask(t2);
// find in list & modify
Task search = {.name = "Phys"}; // key to look for. cmpTask only compares
// names using strcmp(a.name, b.name)
llist *found = llistGet(list1, &search);
if (found != NULL) {
((Task *)found->data)->deadline = time(NULL) + days(10);
((Task *)found->data)->priority = 9;
printTask(found->data);
} else {
printf("%s not in List!\n", search.name);
}
char *t1Str = taskToStr(t1);
printf("%s\n", t1Str);
free(t1Str);
free(t1);
2024-12-12 16:08:19 +01:00
free(t2);
return 0;
}