// File: /workspace/github_c_makefile_star2_O1/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 -0x831(%rip), %rdi      # 0x3dda
movq 0x59ae(%rip), %rsi      # 0x9fc0
callq 0x4ebc
movq %rax, %rbx
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21a0
movq %rax, %r14
xorl %r15d, %r15d
movl $0x4, %edi
callq 0x21a0
movl %r15d, (%rax)
movq %rax, (%r14,%r15,8)
incq %r15
cmpq $0x3e8, %r15            # imm = 0x3E8
jne 0x462a
movq %r14, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x3e6a
xorl %r15d, %r15d
movq (%r14,%r15,8), %rsi
movq %rbx, %rdi
callq 0x51c5
incq %r15
cmpq $0x3e8, %r15            # imm = 0x3E8
jne 0x4657
movl $0x0, 0x4(%rsp)
movq %rbx, %rdi
callq 0x5077
testq %rax, %rax
je 0x46ec
movq %rax, %r15
leaq 0x1c8a(%rip), %r12      # 0x6318
leaq 0x1ff6(%rip), %r13      # 0x668b
leaq 0x1ec2(%rip), %rbp      # 0x655e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5542
movl (%rax), %eax
movl 0x4(%rsp), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x4(%rsp)
xorl %edi, %edi
cmpl %ecx, %eax
sete %dil
movq %r12, %rsi
movl $0xf1, %edx
movq %r13, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x25dc
testl %eax, %eax
je 0x47bb
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5421
movq %rax, %r15
testq %rax, %rax
jne 0x469c
leaq 0x4(%rsp), %r15
movl $0x3e7, (%r15)          # imm = 0x3E7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4f73
movl $0x28, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4f73
movl $0x3e6, (%r15)          # imm = 0x3E6
movq %rbx, %rdi
callq 0x5094
testq %rax, %rax
je 0x479c
movq %rax, %r15
leaq 0x1be5(%rip), %r12      # 0x6318
leaq 0x1f51(%rip), %r13      # 0x668b
leaq 0x1e45(%rip), %rbp      # 0x6586
cmpl $0x28, 0x4(%rsp)
jne 0x4750
movl $0x27, 0x4(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5542
movl (%rax), %eax
movl 0x4(%rsp), %ecx
leal -0x1(%rcx), %edx
movl %edx, 0x4(%rsp)
xorl %edi, %edi
cmpl %ecx, %eax
sete %dil
movq %r12, %rsi
movl $0x100, %edx            # imm = 0x100
movq %r13, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x25dc
testl %eax, %eax
je 0x47bb
movq %rbx, %rdi
movq %r15, %rsi
callq 0x533c
movq %rax, %r15
testq %rax, %rax
jne 0x4741
movq %rbx, %rdi
callq 0x50b6
movq %r14, %rdi
callq 0x22b0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2e23