コード例 #1
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_non_empty_stack_peek_shows_correct_value(void) {
  Stack *stack = create_stack(3);
  push(stack, 8);
  int value = peek(stack);

  assert (8 == value && "peeked value should be 8");
  free(stack);
}
コード例 #2
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_empty_stack_peek(void) {
  Stack *stack = create_stack();

  // Note: You can't tell if a stack is empty by simply peeking, you also have
  // to call "is_empty"
  assert (0 == peek(stack) && "peek at empty stack should show 0");
  destroy_stack(stack);
}
コード例 #3
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_empty_stack_fails(void) {
  Stack *stack = create_stack(3);
  BOOL success;
  pop(stack, &success);

  assert (FALSE == success && "pop should fail");
  free(stack);
}
コード例 #4
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_push_onto_non_empty_stack_size_is_correct(void) {
  Stack *stack = create_stack();
  push(stack, 5);
  push(stack, 4);

  assert (2 == size(stack) && "stack size after pushes should be 2");
  destroy_stack(stack);
}
コード例 #5
0
void test3() 
//@ requires true;
//@ ensures true;
{
    struct value* v2, v3;
    struct stack* s = create_stack();
    //@ close foreach(nil, value_helper2(27));
    //@ close stack_allClients3(s, nil, 27);
    //@ close stack_unsep(stack_inv3_unsep)(boxed_int(27), s, stack_inv3(s, 27), stack_inv3_sep, nil);
    //@ produce_lemma_function_pointer_chunk(stack_inv3_sep);
    //@ produce_lemma_function_pointer_chunk(stack_inv3_unsep);    
    //@ share_stack(s);
        
    struct value* v = malloc(sizeof(struct value));
    if(v == 0) abort();
    v->val = 27;
    
    //@ close stack_push_context_pre(allClients3_push)(stack_inv3_unsep, s, v, boxed_int(27));
    //@ produce_lemma_function_pointer_chunk(allClients3_push);
    stack_push(s, v);
    //@ leak is_stack_push_context(allClients3_push);
    //@ open stack_push_context_post(allClients3_push)(boxed_int(27));
    
    //@ close stack_try_pop_context_pre(allClients3_try_pop)(stack_inv3_unsep, s, boxed_int(27));
    //@ produce_lemma_function_pointer_chunk(allClients3_try_pop);
    bool result = stack_try_pop(s, &v2);
    //@ leak is_stack_try_pop_context(allClients3_try_pop);
    //@ open stack_try_pop_context_post(allClients3_try_pop)(_, _, boxed_int(27));
    if(result) { 
        //@ open value(v2, 27);
        free(v2); 
    }

    //@ unshare_stack(s);
    //@ open stack_unsep(stack_inv3_unsep)(boxed_int(27), s, stack_inv3(s, 27), stack_inv3_sep, _);
    //@ leak is_stack_sep(stack_inv3_sep);
    //@ leak is_stack_unsep(stack_inv3_unsep);
    
    
    bool hasMore = true;
    while(hasMore)
    //@ invariant stack(s, ?remElems) &*& stack_allClients3(s, remElems, 27) &*& pointer(&v3, _) &*& (hasMore ? true: remElems == nil);
    {
        hasMore = stack_try_pop_sequential(s, &v3);
        if(hasMore) {
            //@ open stack_allClients3(s, remElems, 27);
            //@ open foreach(remElems, value_helper2(27));
            //@ close stack_allClients3(s, tail(remElems), 27);
            //@ open value_helper2(27)(v3);
            //@ open value(v3, 27);
            free((struct value*)v3); 
        }
    }
    
    //@ open stack_allClients3(s, remElems, 27);
    //@ open foreach(remElems, value_helper2(27));
    dispose_stack(s);
}
コード例 #6
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_empty_stack_size_is_zero(void) {
  Stack *stack = create_stack();
  Node *node = NULL;
  pop(stack, &node);

  assert (0 == size(stack) && "stack size should be 0");
  free(node);
  destroy_stack(stack);
}
コード例 #7
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_non_empty_stack_returns_correct_value(void) {
  Stack *stack = create_stack(3);
  push(stack, 8);
  BOOL success;
  int value = pop(stack, &success);

  assert (8 == value && "popped value should be 8");
  free(stack);
}
コード例 #8
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_stack_with_one_element_sets_head_to_negative(void) {
  Stack *stack = create_stack(3);
  push(stack, 8);
  BOOL success;
  pop(stack, &success);

  assert (0 > stack->head && "pop should set head to negative");
  free(stack);
}
コード例 #9
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_non_empty_stack_succeeds(void) {
  Stack *stack = create_stack(3);
  push(stack, 8);
  BOOL success;
  pop(stack, &success);

  assert (TRUE == success && "pop should succeed");
  free(stack);
}
コード例 #10
0
ファイル: stack.c プロジェクト: Mehyo/Bongo
void push(int val, Stack *s)
{
	Stack new_s = create_stack(val);	
	
	if(s != NULL)
		new_s->next = *s;
	
	*s = new_s;
}
コード例 #11
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_empty_stack_node_is_null(void) {
  Stack *stack = create_stack();
  Node *node = NULL;
  pop(stack, &node);

  assert (NULL == node && "popped node should be NULL");
  free(node);
  destroy_stack(stack);
}
コード例 #12
0
ファイル: rust_task.cpp プロジェクト: Arreth/rust
void
rust_task::new_stack(size_t requested_sz) {
    LOG(this, mem, "creating new stack for task %" PRIxPTR, this);
    if (stk) {
        ::check_stack_canary(stk);
    }

    // The minimum stack size, in bytes, of a Rust stack, excluding red zone
    size_t min_sz = thread->min_stack_size;

    // Try to reuse an existing stack segment
    while (stk != NULL && stk->next != NULL) {
        size_t next_sz = user_stack_size(stk->next);
        if (min_sz <= next_sz && requested_sz <= next_sz) {
            LOG(this, mem, "reusing existing stack");
            stk = stk->next;
            return;
        } else {
            LOG(this, mem, "existing stack is not big enough");
            stk_seg *new_next = stk->next->next;
            free_stack(stk->next);
            stk->next = new_next;
            if (new_next) {
                new_next->prev = stk;
            }
        }
    }

    // The size of the current stack segment, excluding red zone
    size_t current_sz = 0;
    if (stk != NULL) {
        current_sz = user_stack_size(stk);
    }
    // The calculated size of the new stack, excluding red zone
    size_t rust_stk_sz = get_next_stack_size(min_sz,
                                             current_sz, requested_sz);

    if (total_stack_sz + rust_stk_sz > thread->env->max_stack_size) {
        LOG_ERR(this, task, "task %" PRIxPTR " ran out of stack", this);
        fail();
    }

    size_t sz = rust_stk_sz + RED_ZONE_SIZE;
    stk_seg *new_stk = create_stack(&local_region, sz);
    LOGPTR(thread, "new stk", (uintptr_t)new_stk);
    new_stk->task = this;
    new_stk->next = NULL;
    new_stk->prev = stk;
    if (stk) {
        stk->next = new_stk;
    }
    LOGPTR(thread, "stk end", new_stk->end);

    stk = new_stk;
    total_stack_sz += user_stack_size(new_stk);
}
コード例 #13
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_push_onto_full_stack_fails(void) {
  Stack *stack = create_stack(3);
  push(stack, 8);
  push(stack, 7);
  push(stack, 6);
  BOOL pushed = push(stack, 5);

  assert (FALSE == pushed && "push should fail");
  free(stack);
}
コード例 #14
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_stack_with_one_node_value_is_correct(void) {
  Stack *stack = create_stack();
  push(stack, 5);
  Node *node = NULL;
  pop(stack, &node);

  assert (5 == node->value && "popped value should be 5");
  free(node);
  destroy_stack(stack);
}
コード例 #15
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_stack_with_one_node_size_is_correct(void) {
  Stack *stack = create_stack();
  push(stack, 5);
  Node *node = NULL;
  pop(stack, &node);

  assert (0 == size(stack) && "stack size after pop should be 0");
  free(node);
  destroy_stack(stack);
}
コード例 #16
0
void init_tokenizer(tokenizer_t* t, char* source)
{
	t->source = (char*)malloc(strlen(source) + 1);
	strcpy(t->source, source);
	t->source_index = 0;
	t->index_stack = create_stack(sizeof(int));
	t->token_value = NULL;
	t->token_type = TT_NONE;
	t->line_number = 1;
}
コード例 #17
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_stack_peek_after_pop(void) {
  Stack *stack = create_stack();
  push(stack, 4);
  push(stack, 5);
  Node *node;
  pop(stack, &node);

  assert (4 == peek(stack) && "peek at stack should show 4");
  free(node);
  destroy_stack(stack);
}
コード例 #18
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_pop_from_non_empty_stack_value_is_correct(void) {
  Stack *stack = create_stack();
  push(stack, 5);
  push(stack, 4);
  Node *node = NULL;
  pop(stack, &node);

  assert (4 == node->value && "popped value should be 4");
  free(node);
  destroy_stack(stack);
}
コード例 #19
0
ファイル: assert_stack.c プロジェクト: CodeR57/8puzzle-1
void assert_each() {
  int data[] = {456, 370, 316};
  Stack *stack = create_stack();
  stack_push(stack, 316);
  stack_push(stack, 370);
  stack_push(stack, 456);

  int test(Element e, int i) {
    assert(e == data[i]);
    return 0;
  }
コード例 #20
0
ファイル: stack.c プロジェクト: chinspp/42
t_stack	*push(t_stack *top, char *c)
{
	t_stack	*elem;

	elem = NULL;
	elem = create_stack(c);
	if (elem && top)
	{
		elem->next = top;
	}
	return (elem);
}
コード例 #21
0
ファイル: sum.c プロジェクト: amintimany/verifast
int main()
    //@ requires true;
    //@ ensures true;
{
    struct stack *s = create_stack();
    stack_push(s, 10);
    stack_push(s, 20);
    stack_pop(s);
    stack_pop(s);
    stack_dispose(s);
    return 0;
}
コード例 #22
0
ファイル: Master.c プロジェクト: Rubikan/bic1-programmieren
int main(int argc, char* argv[]) {	
	int i;
	/* create empty stack */
	Stack stack = create_stack(15);
	/* push elements onto stack */
	for (i = 0; i <= 20; i++) push(i, &stack);
	/* pop all elements from stack */
	while (stack.count > 0) printf("%d\n", pop(&stack));
	free(stack.data);

	return 0;
}
コード例 #23
0
ファイル: tvm.c プロジェクト: fjrti/tinyvm
tvm_t* tvm_create(char* filename)
{
	tvm_t* vm = (tvm_t*)malloc(sizeof(tvm_t));

	vm->pMemory = create_memory(MIN_MEMORY_SIZE);
	vm->pProgram = create_program();

	create_stack(vm->pMemory, MIN_STACK_SIZE);

	if(!vm || !vm->pMemory || !vm->pProgram) return NULL;

	return vm;
}
コード例 #24
0
ファイル: assert_stack.c プロジェクト: CodeR57/8puzzle-1
void assert_empty() {
  Stack *stack = create_stack();
  assert(stack_empty(stack) == 1);

  stack_push(stack, 778);
  assert(stack_empty(stack) == 0);

  stack_pop(stack);
  assert(stack_empty(stack) == 1);

  free_stack(stack);
  printf("✓ assert_empty\n");
}
コード例 #25
0
ファイル: X11.c プロジェクト: ashishnirmohi/ashishcode
void main(void)
{
int choice,x;
stack_type stack;
void create_stack(stack_type *);
int isempty(stack_type *);
int isfull(stack_type *);
void push(stack_type *,int);
int pop(stack_type *);
create_stack(&stack);
do
{
clrscr();
printf("options availables \n");
printf("++++++++++++++++++++++++++++\n");
printf("  1. Push \n");
printf("2. Pop\n");
printf("3. Exit \n");
printf("Enter your chioice(1-3)");
scanf("%d",&choice);
switch(choice)
{
case 1: clrscr();
if(isfull(&stack))
{
printf("stack is full ,press any key to continue");
getch();
}
 else
 {
 printf("enter value:");
 scanf("%d",&x);
 push(&stack,x);
 }
 break;
 case 2: clrscr();
 if(isempty(&stack))
 {
 printf("stack is empty,press any key to continue");
 getch();
 }
 else
 {
 printf("value poped is%d\n",pop(&stack));
 printf("press any key to continue");
	getch();
 }
 }
 }
 while(choice!=3);
 }
コード例 #26
0
ファイル: stack_1.c プロジェクト: HiYellowC/ACM
int main(){
	int Switch = 1;
	pstack s;
	int flag = 0;
	while(Switch){
		printf("1 - create stack  2 - push stack  3 - pop stack  4 - get the top data  5 - get the len of stack  0 - exit\n");
		scanf("%d", &Switch);
		if(Switch > 1 && flag == 0){
			printf("Error!\n");
			continue;
		}
		switch(Switch){
			case 1:{
						s = create_stack();
						flag = 1;
						break;
				   }
			case 2:{
						int data;
						printf("please input the data\n");
						scanf("%d", &data);
						push_stack(data, s);
						break;
				   }
			case 3:{
					   pop_stack(s);
					   break;
				   }
			case 4:{
					   if(s->Len == 0){
						   printf("Error!\n");
						   break;
					   }
					   int top;
					   top = get_top(s);
					   printf("the top data is %d\n", top);
					   break;
				   }
			case 5:{
					   int Len;
					   Len = get_len(s);
					   printf("the len of stack is %d\n", Len);
					   break;
				   }
			case 0:
				   break;
		}
	}
	return 0;
}
コード例 #27
0
ファイル: test_stack.c プロジェクト: heptat/unix
static void test_sort_stack_with_two_nodes_in_order(void) {
  Stack *stack = create_stack();
  push(stack, 1);
  push(stack, 2);

  sort(stack);

  Node *ptr = stack->next;
  assert (1 == ptr->value && "first stack value should be 1");
  ptr = ptr->next;
  assert (2 == ptr->value && "second stack value should be 2");
  destroy_stack(stack);
  ptr = NULL;
}
コード例 #28
0
ファイル: stack.c プロジェクト: Sammy-iiitb/Data-Structures
int main(){
    struct stack* _stack = create_stack(100);
 
    push(_stack, 10);
    push(_stack, 20);
    push(_stack, 30);
 
    printf("%d popped from stack\n", pop(_stack));
 	printf("%d popped from stack\n", pop(_stack));
 	printf("%d popped from stack\n", pop(_stack));
   // printf("Top item is %d\n", peek(stack));
 
    return 0;
}
コード例 #29
0
ファイル: assert_stack.c プロジェクト: CodeR57/8puzzle-1
void assert_push_pop() {
  Stack *stack = create_stack();

  stack_push(stack, 778);
  assert(stack_pop(stack) == 778);

  stack_push(stack, 945);
  stack_push(stack, 186);
  assert(stack_pop(stack) == 186);
  assert(stack_pop(stack) == 945);

  free_stack(stack);
  printf("✓ assert_push_pop\n");
}
コード例 #30
0
ファイル: stack_example.c プロジェクト: amintimany/verifast
int main()
    //@ requires true;
    //@ ensures true;
{
    struct stack *s = create_stack();
    stack_push(s, 10);
    stack_push(s, 20);
    int x = stack_pop(s);
    assert(x == 20);
    int y = stack_pop(s);
    assert(y == 10);
    stack_dispose(s);
    return 0;
}