Exemple #1
0
//list_add
static void add_twoValue_countTwo(void **state)
{
    list_t * list = list_new();
    list_add(list, 5, 0);
    assert_int_equal(list_getCount(list), 1);
    list_add(list, 5, 1);
    assert_int_equal(list_getCount(list), 2);
    list_free(list);
}
Exemple #2
0
//list_add
static void add_oneValue_countOne(void **state)
{
    list_t * list = list_new();
    list_add(list, 5, -3);
    assert_int_equal(list_getCount(list), 0);
    list_add(list, 5, 4);
    assert_int_equal(list_getCount(list), 0);
    list_add(list, 5, 0);
    assert_int_equal(list_getCount(list), 1);
    list_free(list);
}
Exemple #3
0
//list_delete
static void delete_oneValue_zeroCount(void **state)
{
    list_t * list = list_new();
    list_add(list, 5, 0);
    list_delete(list, 3);
    assert_int_equal(list_getCount(list), 1);
    list_delete(list, -5);
    assert_int_equal(list_getCount(list), 1);
    list_delete(list, 0);
    assert_int_equal(list_getCount(list), 0);
    list_free(list);
}
Exemple #4
0
void text_free(text_t * self) {
    int count = list_getCount(self->event_notification);
    for (int i = 0; i < count; i++) {
        event_t * ev = list_pop_back(self->event_notification);
        free(ev);
    }
    list_free(self->event_notification);
    free(self);
}
Exemple #5
0
static void getCount_void_countIsOk(void **state)
{
    list_t *list = list_new();
    town tw, tw1, tw2;
    list_put(list, tw, 0);
    list_put(list, tw1, 0);
    list_put(list, tw2, 0);
    assert_int_equal(list_getCount(list), 2);
    list_delete(list);
}
Exemple #6
0
void
webpage_sendMessage(webpage_t * self, const char * message, const char * hyperlink) {
    int count = list_getCount(self->event_notification);
    for (int i = 0; i < count; i++) {
        event_t * ev = list_getEl(self->event_notification, i);
        if (NULL != ev->callback) {
            webpage_notification_fn fn = ev->callback;
            fn(ev->receiver, self, message, hyperlink);
        }
    }
}
Exemple #7
0
void
webpage_free(webpage_t * self) {
    int count = list_getCount(self->event_notification);
    for (int i = 0; i < count; i++) {
        event_t * ev = list_pop_back(self->event_notification);
        free(ev);
    }
    list_free(self->event_notification);
    free(self->event_linkclick);
    free(self);
}
Exemple #8
0
static void add_town_townAdded(void **state)
{
    list_t *list = list_new();
    town tw, tw1;
    tw.place.x = 5;
    tw.place.y = 5;
    list_put(list, tw, 0);
    list_put(list, tw1, 0);
    assert_int_equal(list_getCount(list), 1);
    list_delete(list);
}
Exemple #9
0
//adding the event to list and checking count
static void add_EventToList_Onecount(void ** state)
{
    list_t * list = list_new();
    event_t * ev = malloc(sizeof(event_t));
    ev->receiver = NULL;
    ev->callback = NULL;
    list_push_back(list, ev);
    assert_int_equal(list_getCount(list), 1);
    free(ev);
    free(list);
}
Exemple #10
0
static void text_check(text_t * self) {
    int count = list_getCount(self->event_notification);
    for (int i = 0; i < count; i++) {
        event_t * ev = list_getEl(self->event_notification, i);
        if (NULL != ev->callback) {
            cb fn = ev->callback;
            if(fn(text_getEl(self, self->size - 1)) == 1) {
                text_pop(self);
            }
        }
    }
}
Exemple #11
0
//deleting event from list, checking count
static void pop_EventFromList_Zerocount(void ** state)
{
    list_t * list = list_new();
    event_t * ev = malloc(sizeof(event_t));
    ev->receiver = NULL;
    ev->callback = NULL;
    list_push_back(list, ev);
    list_pop_back(list);
    assert_int_equal(list_getCount(list), 0);
    free(ev);
    free(list);
}
Exemple #12
0
static void remove_position_townRemoved(void **state)
{
    list_t *list = list_new();
    town tw, tw1;
    list_status_t *status;
    tw1.place.x = 5;
    tw1.place.y = 5;
    list_put(list, tw, 0);
    list_put(list, tw1, 1);
    list_pop(list, 0, status);
    assert_int_equal(list_getCount(list), 0);
    list_delete(list);
}
Exemple #13
0
void stack_onEvent(void * sub, stack_t * sender, enum event_type type, int last_val)
{
    int count;
    char message[80];
    stack_t * stmp;

    stmp = (stack_t *)sub;
    if(type == OVER)
    {
        if(stmp->top < STACK_MAX_SIZE - 1)
        {
            sprintf(message, "Event OVER: Stack %i is FULL.\n", sender->num);
            printf(message);
            stack_push(stmp, last_val);
        }
        else
        {
            //Sub stack1
            count = list_getCount(stmp->dual);
            for(int i = 0; i < count; i++)
            {
                event_t * ev = list_getElem(stmp->dual, i);
                if(ev->callback != NULL)
                {
                    cb_fn fn = (cb_fn)ev->callback;

                    sprintf(message, "%s", (char *)ev->receiver);
					fn(ev->receiver, stmp, DUAL, 1);
                }
            }

            //Sub stack 2
            count = list_getCount(sender->dual);
            for(int i = 0; i < count; i++)
            {
                event_t * ev = list_getElem(sender->dual, i);
                if(ev->callback != NULL)
                {
                    cb_fn fn1 = (cb_fn)ev->callback;

                    sprintf(message, "%s", (char *)ev->receiver);
					fn1(ev->receiver, sender, DUAL, 1);
                }
            }
        }
    }

    if(type == EMPTY)
    {
        if(stmp->top >= STACK_MAX_SIZE)
        {
            sprintf(message, "Event EMPTY: Stack %i is EMPTY\n", sender->num);
            printf(message);
            stack_push(sender, stack_pop(stmp));
        }
        else
        {
            //Sub stack1
            count = list_getCount(stmp->dual);
            for(int i = 0; i < count; i++)
            {
                event_t * ev = list_getElem(stmp->dual, i);
                if(ev->callback != NULL)
                {
                    cb_fn fn = (cb_fn)ev->callback;

                    sprintf(message, "%s", (char *)ev->receiver);
					fn(ev->receiver, stmp, DUAL, 0);
                }
            }

            //Sub stack 2
            count = list_getCount(sender->dual);
            for(int i = 0; i < count; i++)
            {
                event_t * ev = list_getElem(sender->dual, i);
                if(ev->callback != NULL)
                {
                    cb_fn fn1 = (cb_fn)ev->callback;

                    sprintf(message, "%s", (char *)ev->receiver);
					fn1(ev->receiver, sender, DUAL, 0);
                }
            }
        }
    }
    if(type == DUAL)
    {
        user_t * user = (user_t *)sub;
        if(last_val)
            sprintf(message, "Event DUAL: User %s. Stack %i is FULL.\n", user->name, sender->num);
        else
            sprintf(message, "Event DUAL: User %s. Stack %i is EMPTY.\n", user->name, sender->num);
        printf(message);
    }

}
Exemple #14
0
int text_listGetSize(text_t * self) {
    return list_getCount(self->event_notification);
}
Exemple #15
0
//list_new
static void new_void_zeroCount(void **state)
{
    list_t * list = list_new();
    assert_int_equal(list_getCount(list), 0);
    list_free(list);
}
Exemple #16
0
int main()
{
    town tw, tw1, tw2, peeked;
    list_status_t *popStatus, *peekStatus;
    list_status_t putStatus;
    strcmp(tw.name, "city 0");
    strcmp(tw1.name, "city 1");
    strcmp(tw2.name, "city 2");
    tw.place.x = 5;
    tw.place.y = 5;
    tw1.place.x = 10;
    tw1.place.y = 10;
    tw2.place.x = 11;
    tw2.place.y = 11;
    list_t *ls;
    ls = list_new();
    putStatus = list_put(ls, tw, 5);
    if(putStatus == LIST_FULL)
        printf("List is full");
    if (putStatus == ERROR)
    {
        printf("Invalid index");
        return EXIT_FAILURE;
    }
    putStatus = list_put(ls, tw1, 0);
    if(putStatus == LIST_FULL)
        printf("List is full");
    if (putStatus == ERROR)
    {
        printf("Invalid index");
        return EXIT_FAILURE;
    }
    putStatus = list_put(ls, tw1, 4);
    if(putStatus == LIST_FULL)
        printf("List is full");
    if (putStatus == ERROR)
    {
        printf("Invalid index");
        return EXIT_FAILURE;
    }
    putStatus = list_put(ls, tw2, 4);
    if(putStatus == LIST_FULL)
        printf("List is full");
    if (putStatus == ERROR)
    {
        printf("Invalid index");
        return EXIT_FAILURE;
    }
    list_pop(ls, 2, popStatus);
    if (*popStatus == LIST_EMPTY)
    {
        printf("List is empty");
    }
    if(*popStatus == ERROR)
    {
        printf("Invalid index");
        return EXIT_FAILURE;
    }
    list_print(ls);
    peeked = list_peek(ls, 1, peekStatus);
    if(*peekStatus == LIST_EMPTY)
        printf("List is empty");
    if (*peekStatus == ERROR)
    {
        printf("Invalid index");
        return EXIT_FAILURE;
    }
    printf("\nPeeked %d %d", peeked.place.x, peeked.place.y);
    int c1 = 1, c2 = 2;
    double dis = distacnce(ls, c1, c2);
    if(!dis)
        printf("\nInvalid index");
    else
    printf("\nDistance between %d and %d is %f", c1, c2, dis);
    printf("\nCount %d", (list_getCount(ls)+1));
    list_delete(ls);
    return 0;
}