// File: /workspace/github_c_makefile_star2_O0/chatziko-k08[P]lecture-code/tests/ADTSet_test.c
// Function: test_iterate
void test_iterate(void) {
	Set set = set_create(compare_ints, free);

	int N = 1000;
	int** value_array = malloc(N * sizeof(*value_array));

	for (int i = 0; i < N; i++)
		value_array[i] = create_int(i);

	// εισαγωγή τιμών σε τυχαία σειρά
	shuffle(value_array, N);

	for (int i = 0; i < N; i++)
		set_insert(set, value_array[i]);

	// iterate, τα στοιχεία πρέπει να τα βρούμε στη σειρά διάταξης
	int i = 0;
	for (SetNode node = set_first(set); node != SET_EOF; node = set_next(set, node)) {
		TEST_ASSERT(*(int*)set_node_value(set, node) == i++);
	}

	// Κάποια removes
	i = N - 1;
	set_remove(set, &i);
	i = 40;
	set_remove(set, &i);

	// iterate, αντίστροφη σειρά, τα στοιχεία πρέπει να τα βρούμε στη σειρά διάταξης
	i = N - 2;
	for (SetNode node = set_last(set); node != SET_EOF; node = set_previous(set, node)) {
		if(i == 40)
			i--;					// το 40 το έχουμε αφαιρέσει

		TEST_ASSERT(*(int*)set_node_value(set, node) == i--);
	}

	set_destroy(set);
	free(value_array);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
leaq -0xacf(%rip), %rdi      # 0x43d0
movq 0x711a(%rip), %rsi      # 0xbfc0
callq 0x5d80
movq %rax, -0x8(%rbp)
movl $0x3e8, -0xc(%rbp)      # imm = 0x3E8
movslq -0xc(%rbp), %rdi
shlq $0x3, %rdi
callq 0x2180
movq %rax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4ef8
movl -0x1c(%rbp), %edi
callq 0x43a0
movq %rax, %rdx
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4ece
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x44a0
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4f33
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x63f0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x4f0b
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6110
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4fb6
jmp 0x4f50
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x69b0
movl (%rax), %eax
movl -0x24(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x24(%rbp)
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x3366(%rip), %rsi      # 0x82e1
movl $0xf1, %edx
leaq 0x36cf(%rip), %rcx      # 0x8656
leaq 0x3599(%rip), %r8       # 0x8527
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x4f9f
callq 0x2e50
jmp 0x4fa1
jmp 0x4fa3
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x67c0
movq %rax, -0x30(%rbp)
jmp 0x4f47
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x5ee0
movl $0x28, -0x24(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x5ee0
movl -0xc(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
callq 0x6190
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5074
cmpl $0x28, -0x24(%rbp)
jne 0x500c
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x500e
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x69b0
movl (%rax), %eax
movl -0x24(%rbp), %ecx
movl %ecx, %edx
addl $-0x1, %edx
movl %edx, -0x24(%rbp)
cmpl %ecx, %eax
sete %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x32a8(%rip), %rsi      # 0x82e1
movl $0x100, %edx            # imm = 0x100
leaq 0x3611(%rip), %rcx      # 0x8656
leaq 0x3503(%rip), %r8       # 0x854f
movb $0x0, %al
callq 0x2370
cmpl $0x0, %eax
jne 0x505d
callq 0x2e50
jmp 0x505f
jmp 0x5061
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x65f0
movq %rax, -0x38(%rbp)
jmp 0x4ff6
movq -0x8(%rbp), %rdi
callq 0x6230
movq -0x18(%rbp), %rdi
callq 0x2270
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)