// File: /workspace/github_c_makefile_star2_O2/chatziko-k08[P]lecture-code/tests/ADTMap_test.c
// Function: test_find
void test_find(void) {

	Map map = map_create(compare_ints, free, free);
	map_set_hash_function(map, hash_int);

	int N = 1000;
	int** key_array = malloc(N * sizeof(*key_array));
	int** value_array = malloc(N * sizeof(*value_array));

	for (int i = 0; i < N; i++) {
		key_array[i] = create_int(i);
		value_array[i] = create_int(i);

		map_insert(map, key_array[i], value_array[i]);
		MapNode found = map_find_node(map, key_array[i]);
		Pointer found_key = map_node_key(map, found);
		Pointer found_val = map_node_value(map, found);

		// Δοκιμάζουμε ότι ο κόμβος που μόλις κάναμε insert έχει το ίδιο Key και Value 
		TEST_ASSERT(found != MAP_EOF); 
		TEST_ASSERT(found_key == key_array[i]);
		TEST_ASSERT(found_val == value_array[i]);
	}	

	// Αναζήτηση στοιχείου που δεν υπάρχει στο map
	int not_exists = 2000;
	TEST_ASSERT(map_find_node(map, &not_exists) == MAP_EOF);
	TEST_ASSERT(map_find(map, &not_exists) == NULL);

	// Δοκιμή αναζήτησης μετά από διαδοχικά inserts/deletes (στην υλοποίηση με hashtable αυτό θα γεμίσει τον πίνακα με DELETED τιμές)
	Map map2 = map_create(compare_ints, NULL, NULL);
	map_set_hash_function(map2, hash_int);

	int M = 53;							// αρχικό μέγεθος στην υλοποίηση με hashtable
	for (int i = 0; i < M; i++) {
		map_insert(map2, key_array[i], value_array[i]);
		TEST_ASSERT(map_remove(map2, key_array[i]));
	}
	TEST_ASSERT(map_find(map2, &key_array[M]) == NULL);

	map_destroy(map);		// frees keys/values
	map_destroy(map2);

	free(key_array);
	free(value_array);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq -0x6db(%rip), %rdi      # 0x3a71
movq 0x5e6d(%rip), %rdx      # 0x9fc0
movq %rdx, %rsi
callq 0x4b4c
movq %rax, %r13
leaq 0xc4f(%rip), %rsi       # 0x4db4
movq %rax, %rdi
callq 0x4dba
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21a0
movq %rax, %rbx
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21a0
movq %rax, (%rsp)
leaq 0x247a(%rip), %r12      # 0x6609
xorl %ebp, %ebp
movq %rbx, 0x8(%rsp)
movq %r13, 0x18(%rsp)
cmpq $0x3e8, %rbp            # imm = 0x3E8
je 0x429b
movl %ebp, %edi
callq 0x3b1a
movq %rax, %r14
movq %rax, (%rbx,%rbp,8)
movl %ebp, %edi
callq 0x3b1a
movq %rax, %r15
movq (%rsp), %rax
movq %r15, (%rax,%rbp,8)
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4c3c
movq %r13, %rdi
movq %r14, %rsi
callq 0x4d38
movq %rax, %rbx
movq %r13, %rdi
movq %rax, %rsi
callq 0x4da8
movq %r13, %rdi
movq %rax, %r13
movq %rbx, %rsi
callq 0x4dac
movq %rax, 0x20(%rsp)
xorl %edi, %edi
testq %rbx, %rbx
setne %dil
leaq 0x2106(%rip), %rbx      # 0x6318
movq %rbx, %rsi
movl $0xcd, %edx
movq %r12, %rcx
leaq 0x220c(%rip), %r8       # 0x6430
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x43a9
xorl %edi, %edi
cmpq %r14, %r13
sete %dil
movq %rbx, %rsi
movl $0xce, %edx
movq %r12, %rcx
leaq 0x21f3(%rip), %r8       # 0x6441
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x43a9
xorl %edi, %edi
cmpq %r15, 0x20(%rsp)
sete %dil
movq %rbx, %rsi
movl $0xcf, %edx
movq %r12, %rcx
leaq 0x21e1(%rip), %r8       # 0x645b
xorl %eax, %eax
callq 0x239c
incq %rbp
testl %eax, %eax
movq 0x18(%rsp), %r13
movq 0x8(%rsp), %rbx
jne 0x419b
jmp 0x43a9
leaq 0x14(%rsp), %rsi
movl $0x7d0, (%rsi)          # imm = 0x7D0
movq %r13, %rdi
callq 0x4d38
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x205a(%rip), %rsi      # 0x6318
leaq 0x2344(%rip), %rcx      # 0x6609
leaq 0x21ab(%rip), %r8       # 0x6477
movl $0xd4, %edx
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x43a9
leaq 0x14(%rsp), %rsi
movq %r13, %rdi
callq 0x4c0c
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x201b(%rip), %rsi      # 0x6318
leaq 0x2305(%rip), %rcx      # 0x6609
leaq 0x2197(%rip), %r8       # 0x64a2
movl $0xd5, %edx
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x43a9
leaq -0x8b5(%rip), %rdi      # 0x3a71
xorl %esi, %esi
xorl %edx, %edx
callq 0x4b4c
movq %rax, %r12
leaq 0xa7b(%rip), %rsi       # 0x4db4
movq %rax, %rdi
callq 0x4dba
leaq 0x1fd0(%rip), %r14      # 0x6318
leaq 0x22ba(%rip), %r15      # 0x6609
leaq 0x216f(%rip), %r13      # 0x64c5
xorl %ebp, %ebp
cmpq $0x35, %rbp
je 0x43ae
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rbx
movq (%rsp), %rax
movq (%rax,%rbp,8), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x4c3c
movq %r12, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rbx
callq 0x4ccc
movzbl %al, %edi
movq %r14, %rsi
movl $0xde, %edx
movq %r15, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x239c
incq %rbp
testl %eax, %eax
jne 0x4358
callq 0x2bc0
movq %rbx, %rsi
addq $0x1a8, %rsi            # imm = 0x1A8
movq %r12, %rdi
callq 0x4c0c
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1f48(%rip), %rsi      # 0x6318
leaq 0x2232(%rip), %rcx      # 0x6609
leaq 0x2106(%rip), %r8       # 0x64e4
movl $0xe0, %edx
xorl %eax, %eax
callq 0x239c
testl %eax, %eax
je 0x43a9
movq 0x18(%rsp), %rdi
callq 0x4d23
movq %r12, %rdi
callq 0x4d23
movq %rbx, %rdi
callq 0x22a0
movq (%rsp), %rdi
callq 0x22a0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq