// File: /workspace/github_c_makefile_star2_O1/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 -0x708(%rip), %rdi      # 0x3dd1
movq 0x5ae0(%rip), %rdx      # 0x9fc0
movq %rdx, %rsi
callq 0x4f24
leaq 0xcaf(%rip), %rsi       # 0x519e
movq %rax, 0x8(%rsp)
movq %rax, %rdi
callq 0x51a4
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21b0
movq %rax, %r14
movl $0x1f40, %edi           # imm = 0x1F40
callq 0x21b0
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
movl $0x4, %edi
callq 0x21b0
movq %rax, %r15
movl %ebx, (%rax)
movq %rax, (%r14,%rbx,8)
movl $0x4, %edi
callq 0x21b0
movq %rax, %rbp
movl %ebx, (%rax)
movq 0x10(%rsp), %rax
movq %rbp, (%rax,%rbx,8)
movq %r14, %r12
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x501b
movq %r12, %r15
movq (%r12,%rbx,8), %rsi
movq %r14, %rdi
callq 0x511f
movq %rax, %r13
movq %r14, %rdi
movq %rax, %rsi
callq 0x5192
movq %rax, %r12
movq %r14, %rdi
movq %r13, %rsi
callq 0x5196
movq %rax, 0x20(%rsp)
xorl %edi, %edi
testq %r13, %r13
setne %dil
leaq 0x1d7d(%rip), %rsi      # 0x6318
movl $0xcd, %edx
leaq 0x2065(%rip), %r13      # 0x660c
movq %r13, %rcx
leaq 0x1e7f(%rip), %r8       # 0x6430
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x47ac
xorl %edi, %edi
movq %r15, %r14
cmpq (%r15,%rbx,8), %r12
sete %dil
leaq 0x1d44(%rip), %r15      # 0x6318
movq %r15, %rsi
movl $0xce, %edx
movq %r13, %rcx
leaq 0x1e5b(%rip), %r8       # 0x6441
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x47ac
xorl %edi, %edi
cmpq %rbp, 0x20(%rsp)
sete %dil
movq %r15, %rsi
movl $0xcf, %edx
movq %r13, %rcx
leaq 0x1e49(%rip), %r8       # 0x645b
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x47ac
incq %rbx
cmpq $0x3e8, %rbx            # imm = 0x3E8
jne 0x451a
leaq 0x1c(%rsp), %rsi
movl $0x7d0, (%rsi)          # imm = 0x7D0
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x511f
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1cbf(%rip), %rsi      # 0x6318
leaq 0x1fac(%rip), %rcx      # 0x660c
leaq 0x1e10(%rip), %r8       # 0x6477
movl $0xd4, %edx
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x47ac
leaq 0x1c(%rsp), %rsi
movq %rbx, %rdi
callq 0x4fe8
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1c80(%rip), %rsi      # 0x6318
leaq 0x1f6d(%rip), %rcx      # 0x660c
leaq 0x1dfc(%rip), %r8       # 0x64a2
movl $0xd5, %edx
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x47ac
leaq -0x8f0(%rip), %rdi      # 0x3dd1
xorl %esi, %esi
xorl %edx, %edx
callq 0x4f24
movq %rax, %r12
leaq 0xaca(%rip), %rsi       # 0x519e
movq %rax, %rdi
callq 0x51a4
leaq 0x1c35(%rip), %r13      # 0x6318
leaq 0x1f22(%rip), %rbp      # 0x660c
leaq 0x1dd4(%rip), %r15      # 0x64c5
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rsi
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdx
movq %r12, %rdi
callq 0x501b
movq (%r14,%rbx,8), %rsi
movq %r12, %rdi
callq 0x50b0
movzbl %al, %edi
movq %r13, %rsi
movl $0xde, %edx
movq %rbp, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x47ac
incq %rbx
cmpq $0x35, %rbx
jne 0x46f3
movq %r14, %rsi
addq $0x1a8, %rsi            # imm = 0x1A8
movq %r12, %rdi
callq 0x4fe8
xorl %edi, %edi
testq %rax, %rax
sete %dil
leaq 0x1bbd(%rip), %rsi      # 0x6318
leaq 0x1eaa(%rip), %rcx      # 0x660c
leaq 0x1d7b(%rip), %r8       # 0x64e4
movl $0xe0, %edx
xorl %eax, %eax
callq 0x25ec
testl %eax, %eax
je 0x47ac
movq 0x8(%rsp), %rdi
callq 0x510a
movq %r12, %rdi
callq 0x510a
movq %r14, %rdi
callq 0x22c0
movq 0x10(%rsp), %rdi
callq 0x22c0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2e33