// File: /workspace/github_c_makefile_star2_O3/chatziko-k08[P]lecture-code/tests/ADTMap_test.c
// Function: test_iterate
void test_iterate(void) {
	Map map = map_create(compare_ints, free, free);
	map_set_hash_function(map, hash_int);
	// first σε κενό map
	TEST_ASSERT(map_first(map) == MAP_EOF);
	// Προσθέτουμε Ν ακεραίους, το value κάθε ακεραίου i είναι 2*i
	int N = 1000;
	for (int i = 0; i < N; i++)
		map_insert(map, create_int(i), create_int(2*i));

	// Ελέγχουμε ότι διατρέχοντας το map βρίσκουμε όλους τους ακεραίους από μία φορά τον καθένα
	// Στον πίνακα seen κρατάμε αν έχουμε ήδη δει τον κάθε αριθμό
	bool seen[N];
	for (int i = 0; i < N; i++)
		seen[i] = false;

	int count = 0;
	for (MapNode node = map_first(map); node != MAP_EOF; node = map_next(map, node)) {
		int* key = map_node_key(map, node);
		int* value = map_node_value(map, node);

		TEST_ASSERT(*key >= 0 && *key < N && !seen[*key]);
		TEST_ASSERT(*value == 2 * *key);

		seen[*key] = true;
		count++;
	}

	// Αν κάναμε N επαναλήψεις, τότε σίγουρα βρήκαμε όλους τους αριθμούς
	TEST_ASSERT(count == N);

	map_destroy(map);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq -0xa08(%rip), %rdi      # 0x3cc4
movq 0x58ed(%rip), %rdx      # 0x9fc0
movq %rdx, %rsi
callq 0x4e20
movq %rax, %r13
leaq 0x9b5(%rip), %rsi       # 0x509a
movq %rax, %rdi
callq 0x50a0
movq %r13, %rdi
callq 0x5041
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1c13(%rip), %rsi      # 0x6318
leaq 0x1efd(%rip), %rcx      # 0x6609
leaq 0x1df7(%rip), %r8       # 0x650a
xorl %r15d, %r15d
movl $0xed, %edx
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x48af
xorl %r12d, %r12d
movl $0x4, %edi
callq 0x21b0
movq %rax, %r14
movl %r12d, (%rax)
movl $0x4, %edi
callq 0x21b0
movl %r15d, (%rax)
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x4f17
incl %r12d
addl $0x2, %r15d
cmpl $0x3e8, %r12d           # imm = 0x3E8
jne 0x472d
movq %rsp, %rdi
addq $-0x3f0, %rdi           # imm = 0xFC10
movq %rdi, %rsp
xorl %r12d, %r12d
movl $0x3e8, %edx            # imm = 0x3E8
movq %rdi, -0x30(%rbp)
xorl %esi, %esi
callq 0x2120
movq %r13, %rdi
callq 0x5041
testq %rax, %rax
je 0x4871
movq %rax, %r15
movl $0x3e8, %r14d           # imm = 0x3E8
leaq 0x1b6f(%rip), %rbx      # 0x6318
movq %r13, -0x38(%rbp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x508e
movq %rax, %r12
movq %r13, %rdi
movq %r15, %rsi
callq 0x5092
movq %rax, -0x40(%rbp)
movl (%r12), %eax
movl $0x0, %edi
cmpq $0x3e7, %rax            # imm = 0x3E7
ja 0x47e6
movq -0x30(%rbp), %rcx
movzbl (%rcx,%rax), %edi
xorl $0x1, %edi
movq %rbx, %rsi
movl $0xfe, %edx
leaq 0x1e14(%rip), %r13      # 0x6609
movq %r13, %rcx
leaq 0x1d25(%rip), %r8       # 0x6524
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x48af
movl (%r12), %eax
addl %eax, %eax
xorl %edi, %edi
movq -0x40(%rbp), %rcx
cmpl %eax, (%rcx)
sete %dil
movq %rbx, %rsi
movl $0xff, %edx
movq %r13, %rcx
leaq 0x1d17(%rip), %r8       # 0x6549
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x48af
movslq (%r12), %rax
movq -0x30(%rbp), %rcx
movb $0x1, (%rcx,%rax)
movq -0x38(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x5062
movq %rax, %r15
decl %r14d
testq %rax, %rax
jne 0x47ad
xorl %r12d, %r12d
testl %r14d, %r14d
sete %r12b
leaq 0x1aa0(%rip), %rsi      # 0x6318
leaq 0x1d8a(%rip), %rcx      # 0x6609
leaq 0x1cd6(%rip), %r8       # 0x655c
movl %r12d, %edi
movl $0x106, %edx            # imm = 0x106
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x48af
movq %r13, %rdi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5006
callq 0x2e4b