// File: /workspace/github_c_makefile_star2_O3/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      # 0x3cc5
movq 0x5ac3(%rip), %rsi      # 0x9fc0
callq 0x4d90
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 0x4515
movq %r14, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x3d55
xorl %r15d, %r15d
movq (%r14,%r15,8), %rsi
movq %rbx, %rdi
callq 0x5088
incq %r15
cmpq $0x3e8, %r15            # imm = 0x3E8
jne 0x4542
movq %rbx, %rdi
callq 0x4f53
testq %rax, %rax
je 0x45c6
movq %rax, %r15
leaq 0x211a(%rip), %r13      # 0x668b
leaq 0x1fe6(%rip), %rbp      # 0x655e
xorl %r12d, %r12d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x55e4
xorl %edi, %edi
cmpl (%rax), %r12d
sete %dil
leaq 0x1d82(%rip), %rsi      # 0x6318
movl $0xf1, %edx
movq %r13, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x25dc
testl %eax, %eax
je 0x4695
incl %r12d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x54ab
movq %rax, %r15
testq %rax, %rax
jne 0x457b
leaq 0x4(%rsp), %r15
movl $0x3e7, (%r15)          # imm = 0x3E7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4e47
movl $0x28, (%r15)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4e47
movl $0x3e6, (%r15)          # imm = 0x3E6
movq %rbx, %rdi
callq 0x4f6e
testq %rax, %rax
je 0x4676
movq %rax, %r15
leaq 0x1d0b(%rip), %r12      # 0x6318
leaq 0x2077(%rip), %r13      # 0x668b
leaq 0x1f6b(%rip), %rbp      # 0x6586
cmpl $0x28, 0x4(%rsp)
jne 0x462a
movl $0x27, 0x4(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x55e4
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 0x4695
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5373
movq %rax, %r15
testq %rax, %rax
jne 0x461b
movq %rbx, %rdi
callq 0x4f8e
movq %r14, %rdi
callq 0x22b0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2e3b