view src/parallel_execution/test/stack_test.cbc @ 588:78e10562b210

tweak
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Thu, 16 Jan 2020 14:44:03 +0900
parents ac244346c85d
children
line wrap: on
line source

#include "../../context.h"
#interface "Stack.h"
#include <assert.h>
// use "TaskManager.h"

__code stackTest1(struct Stack* stack) {
    Node* node = new Node();
    node->color = Red;
    goto stack->push(node, stackTest2);
}

__code stackTest1_stub(struct Context* context) {
    Stack* stack = createSingleLinkedStack(context);
    goto stackTest1(context, stack);
}

__code stackTest2(struct Stack* stack) {
    Node* node = new Node();
    node->color = Black;
    goto stack->push(node, stackTest3);
}

__code stackTest2_stub(struct Context* context) {
    SingleLinkedStack* singleLinkedStack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
    assert(singleLinkedStack->top->data->Node.color == Red);
    Stack* stack = (struct Stack*)Gearef(context, Stack)->stack;
    goto stackTest2(context, stack);
}

__code stackTest3(struct Stack* stack) {
    goto stack->pop(assert3);
}

__code stackTest3_stub(struct Context* context) {
    /*
        assert on stack implementation
    */
    SingleLinkedStack* singleLinkedStack = (SingleLinkedStack*)GearImpl(context, Stack, stack);
    assert(singleLinkedStack->top->data->Node.color == Black);
    Stack* stack = (struct Stack*)Gearef(context, Stack)->stack;
    goto stackTest3(context, stack);
} 

__code assert3(struct Node* node, struct Stack* stack) {
    /*
        assert in normal level
    */
    assert(node->color == Red);
    goto exit_code(0);
}

int main(int argc, char const* argv[]) {
    goto stackTest1();
}