// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq -0x82b(%rip), %rdi      # 0x3a80
movq 0x5d0e(%rip), %rsi      # 0x9fc0
callq 0x4b08
movq %rax, %rbx
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21a0
movq %rax, %r14
xorl %r15d, %r15d
cmpq $0x3e8, %r15            # imm = 0x3E8
je 0x42e4
movl %r15d, %edi
callq 0x3a71
movq %rax, (%r14,%r15,8)
incq %r15
jmp 0x42ca
movq %r14, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x3b0c
xorl %r15d, %r15d
cmpq $0x3e8, %r15            # imm = 0x3E8
je 0x430e
movq (%r14,%r15,8), %rsi
movq %rbx, %rdi
callq 0x4dc8
incq %r15
jmp 0x42f4
movq %rbx, %rdi
callq 0x4ca2
movq %rax, %r15
pushq $0x1
popq %r12
leaq 0x223a(%rip), %rbp      # 0x655e
testq %r15, %r15
je 0x437f
leal -0x1(%r12), %r13d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5197
xorl %edi, %edi
cmpl (%rax), %r13d
movl %r12d, 0x4(%rsp)
sete %dil
leaq 0x1fca(%rip), %rsi      # 0x6318
movl $0xf1, %edx
leaq 0x2331(%rip), %rcx      # 0x668b
movq %rbp, %r8
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x444b
movq %rbx, %rdi
movq %r15, %rsi
callq 0x50b4
movq %rax, %r15
incl %r12d
jmp 0x4324
leaq 0x4(%rsp), %r15
movl $0x3e7, (%r15)          # imm = 0x3E7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4bb7
movl $0x28, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4bb7
movl $0x3e6, (%r15)          # imm = 0x3E6
movq %rbx, %rdi
callq 0x4cbf
movq %rax, %r12
leaq 0x1f57(%rip), %r15      # 0x6318
leaq 0x22c3(%rip), %r13      # 0x668b
leaq 0x21b7(%rip), %rbp      # 0x6586
testq %r12, %r12
je 0x442c
cmpl $0x28, 0x4(%rsp)
jne 0x43e3
movl $0x27, 0x4(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x5197
movl (%rax), %eax
movl 0x4(%rsp), %ecx
leal -0x1(%rcx), %edx
movl %edx, 0x4(%rsp)
xorl %edi, %edi
cmpl %ecx, %eax
sete %dil
movq %r15, %rsi
movl $0x100, %edx            # imm = 0x100
movq %r13, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x444b
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4fd8
movq %rax, %r12
jmp 0x43cf
movq %rbx, %rdi
callq 0x4ce1
movq %r14, %rdi
callq 0x22a0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2bc0