// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
leaq -0x9c7(%rip), %rdi      # 0x3a71
movq 0x5b81(%rip), %rdx      # 0x9fc0
movq %rdx, %rsi
callq 0x4b4c
movq %rax, %r13
leaq 0x963(%rip), %rsi       # 0x4db4
movq %rax, %rdi
callq 0x4dba
movq %r13, %rdi
callq 0x4d5b
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1ea7(%rip), %rsi      # 0x6318
leaq 0x2191(%rip), %rcx      # 0x6609
leaq 0x208b(%rip), %r8       # 0x650a
xorl %r14d, %r14d
movl $0xed, %edx
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x4612
xorl %r15d, %r15d
cmpl $0x3e8, %r15d           # imm = 0x3E8
je 0x44cc
movl %r15d, %edi
callq 0x3b1a
movq %rax, %r12
movl %r14d, %edi
callq 0x3b1a
movq %r13, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x4c3c
incl %r15d
addl $0x2, %r14d
jmp 0x4499
movq %rsp, %rax
addq $-0x3f0, %rax           # imm = 0xFC10
movq %rax, -0x30(%rbp)
movq %rax, %rsp
xorl %eax, %eax
movq -0x30(%rbp), %rcx
cmpq $0x3e8, %rax            # imm = 0x3E8
je 0x44f3
movb $0x0, (%rcx,%rax)
incq %rax
jmp 0x44e2
movq %r13, %rdi
callq 0x4d5b
movq %rax, %r14
movl $0x3e8, %ebx            # imm = 0x3E8
leaq 0x1e0e(%rip), %r12      # 0x6318
leaq 0x20f8(%rip), %r15      # 0x6609
movq %r13, -0x40(%rbp)
testq %r14, %r14
je 0x45cf
movl %ebx, -0x34(%rbp)
movq %r13, %rdi
movq %r14, %rsi
callq 0x4da8
movq %r13, %rdi
movq %rax, %r13
movq %r14, %rsi
callq 0x4dac
movq %rax, -0x48(%rbp)
movl (%r13), %eax
xorl %edi, %edi
cmpq $0x3e7, %rax            # imm = 0x3E7
ja 0x4557
movq -0x30(%rbp), %rcx
movzbl (%rcx,%rax), %edi
xorl $0x1, %edi
movq %r12, %rsi
movl $0xfe, %edx
movq %r15, %rcx
leaq 0x1fbb(%rip), %r8       # 0x6524
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x4612
movl (%r13), %eax
addl %eax, %eax
xorl %edi, %edi
movq -0x48(%rbp), %rcx
cmpl %eax, (%rcx)
sete %dil
movq %r12, %rsi
movl $0xff, %edx
movq %r15, %rcx
leaq 0x1fad(%rip), %r8       # 0x6549
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x4612
movslq (%r13), %rax
movq -0x30(%rbp), %rcx
movb $0x1, (%rcx,%rax)
movq -0x40(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x4d7c
movq %rax, %r14
movl -0x34(%rbp), %ebx
decl %ebx
jmp 0x4515
xorl %edi, %edi
testl %ebx, %ebx
sete %dil
leaq 0x1d3a(%rip), %rsi      # 0x6318
leaq 0x2024(%rip), %rcx      # 0x6609
leaq 0x1f70(%rip), %r8       # 0x655c
movl $0x106, %edx            # imm = 0x106
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x4612
movq %r13, %rdi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4d23
callq 0x2bc0