// File: /workspace/github_c_makefile_star2_O1/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 -0x9f8(%rip), %rdi      # 0x3dd1
movq 0x57f0(%rip), %rdx      # 0x9fc0
movq %rdx, %rsi
callq 0x4f24
movq %rax, %r13
leaq 0x9bc(%rip), %rsi       # 0x519e
movq %rax, %rdi
callq 0x51a4
movq %r13, %rdi
callq 0x5145
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1b16(%rip), %rsi      # 0x6318
leaq 0x1e03(%rip), %rcx      # 0x660c
leaq 0x1cfa(%rip), %r8       # 0x650a
xorl %r15d, %r15d
movl $0xed, %edx
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x49ac
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 0x501b
incl %r12d
addl $0x2, %r15d
cmpl $0x3e8, %r12d           # imm = 0x3E8
jne 0x482a
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 0x5145
testq %rax, %rax
je 0x496e
movq %rax, %r15
movl $0x3e8, %r14d           # imm = 0x3E8
leaq 0x1a72(%rip), %rbx      # 0x6318
movq %r13, -0x38(%rbp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x5192
movq %rax, %r12
movq %r13, %rdi
movq %r15, %rsi
callq 0x5196
movq %rax, -0x40(%rbp)
movl (%r12), %eax
movl $0x0, %edi
cmpq $0x3e7, %rax            # imm = 0x3E7
ja 0x48e3
movq -0x30(%rbp), %rcx
movzbl (%rcx,%rax), %edi
xorl $0x1, %edi
movq %rbx, %rsi
movl $0xfe, %edx
leaq 0x1d1a(%rip), %r13      # 0x660c
movq %r13, %rcx
leaq 0x1c28(%rip), %r8       # 0x6524
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x49ac
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 0x1c1a(%rip), %r8       # 0x6549
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x49ac
movslq (%r12), %rax
movq -0x30(%rbp), %rcx
movb $0x1, (%rcx,%rax)
movq -0x38(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x5166
movq %rax, %r15
decl %r14d
testq %rax, %rax
jne 0x48aa
xorl %r12d, %r12d
testl %r14d, %r14d
sete %r12b
leaq 0x19a3(%rip), %rsi      # 0x6318
leaq 0x1c90(%rip), %rcx      # 0x660c
leaq 0x1bd9(%rip), %r8       # 0x655c
movl %r12d, %edi
movl $0x106, %edx            # imm = 0x106
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x49ac
movq %r13, %rdi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x510a
callq 0x2e33