Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int test_1()
- {
- int *data = (int *)mm_malloc(sizeof(int));
- if (data == NULL)
- return 0;
- data[0] = 9999;
- if (data[0] != 9999)
- return 0;
- return 1;
- }
- int test_2()
- {
- int *data_1 = (int *)mm_malloc(sizeof(int));
- data_1[0] = 1;
- int *data_2 = (int *)mm_malloc(sizeof(int));
- data_2[0] = 2;
- int *data_3 = (int *)mm_malloc(sizeof(int));
- data_3[0] = 3;
- if (data_1[0] != 1 || data_2[0] != 2 || data_3[0] != 3)
- return 0;
- return 1;
- }
- int test_3()
- {
- int *data = (int *)mm_malloc(sizeof(int) * 2);
- data[0] = 123456;
- mm_free(data);
- int *new_data = (int *)mm_malloc(sizeof(int));
- if (new_data != data)
- return 0;
- for (int i = 0; i < 10; i++)
- {
- mm_free(new_data);
- new_data = (int *)mm_malloc(sizeof(int));
- if (new_data != data)
- return 0;
- }
- return 1;
- }
- int test_4()
- {
- int *data1 = mm_malloc(sizeof(int));
- *data1 = 1;
- int *data2 = mm_malloc(sizeof(int));
- *data2 = 2;
- int *data3 = mm_malloc(sizeof(int));
- *data3 = 3;
- int *data4 = mm_malloc(sizeof(int));
- *data4 = 4;
- int *data5 = mm_malloc(sizeof(int));
- *data5 = 5;
- int *data6 = mm_malloc(sizeof(int));
- *data6 = 6;
- return 1;
- }
- int test_5()
- {
- int *data1 = mm_malloc(sizeof(int));
- *data1 = 1;
- mm_free(data1);
- int *data2 = mm_malloc(sizeof(int));
- *data2 = 2;
- mm_free(data2);
- int *data3 = mm_malloc(sizeof(int));
- *data3 = 3;
- mm_free(data3);
- int *data4 = mm_malloc(sizeof(int));
- *data4 = 4;
- mm_free(data4);
- int *data5 = mm_malloc(sizeof(int));
- *data5 = 5;
- mm_free(data5);
- int *data6 = mm_malloc(sizeof(int));
- *data6 = 6;
- mm_free(data6);
- return 1;
- }
- int test_6()
- {
- int alloc_len = 10;
- int *arr = mm_malloc(sizeof(int) * alloc_len);
- for (int i = 0; i < alloc_len; i++)
- arr[i] = i;
- int new_alloc_len = 2 * sizeof(int) * alloc_len;
- int *new_arr = mm_realloc(arr, new_alloc_len);
- if (new_arr != arr)
- return 0;
- for (int i = 0; i < alloc_len; i++)
- if (new_arr[i] != i)
- return 0;
- return 1;
- }
- // Merging Free Blocks
- int test_7()
- {
- int alloc_len = 10;
- int *arr1 = mm_malloc(sizeof(int) * alloc_len);
- int *arr2 = mm_malloc(sizeof(int) * 2 * alloc_len);
- int *arr3 = mm_malloc(sizeof(int) * 4 * alloc_len);
- int *arr4 = mm_malloc(sizeof(int) * 8 * alloc_len);
- int *arr5 = mm_malloc(sizeof(int) * 16 * alloc_len);
- int *arr6 = mm_malloc(sizeof(int) * 32 * alloc_len);
- int *arr7 = mm_malloc(sizeof(int) * 64 * alloc_len);
- mm_free(arr7);
- mm_free(arr3);
- mm_free(arr1);
- mm_free(arr6);
- mm_free(arr5);
- mm_free(arr4);
- mm_free(arr2);
- return 1;
- }
- int test_8()
- {
- int alloc_len = 10;
- int *arr1 = mm_malloc(sizeof(int) * alloc_len);
- int *arr2 = mm_malloc(sizeof(int) * alloc_len);
- int *arr3 = mm_malloc(sizeof(int) * alloc_len);
- for (int i = 0; i < alloc_len; i++)
- arr2[i] = 1 << i;
- mm_free(arr1);
- mm_free(arr3);
- int new_alloc_len = 2 * alloc_len;
- int *new_arr = mm_realloc(arr2, sizeof(int) * new_alloc_len);
- for (int i = 0; i < alloc_len; i++)
- printf("%d ", new_arr[i]);
- return 1;
- }
- int test_9()
- {
- int alloc_len = 10;
- int *arr1 = mm_malloc(sizeof(int) * alloc_len);
- int *arr2 = mm_malloc(sizeof(int) * alloc_len);
- int *arr3 = mm_malloc(sizeof(int) * alloc_len);
- for (int i = 0; i < alloc_len; i++)
- arr2[i] = i;
- mm_free(arr1);
- mm_free(arr3);
- int new_alloc_len = alloc_len / 2;
- int *new_arr = mm_realloc(arr2, sizeof(int) * new_alloc_len);
- for (int i = 0; i < alloc_len / 2; i++)
- printf("%d ", new_arr[i]);
- return 1;
- }
- int test_10()
- {
- int alloc_len = 10;
- int *arr1 = mm_malloc(sizeof(int) * alloc_len);
- int *arr2 = mm_malloc(sizeof(int) * 2 * alloc_len);
- int *arr3 = mm_malloc(sizeof(int) * 4 * alloc_len);
- int *arr4 = mm_malloc(sizeof(int) * 8 * alloc_len);
- int *arr5 = mm_malloc(sizeof(int) * 16 * alloc_len);
- int *arr6 = mm_malloc(sizeof(int) * 32 * alloc_len);
- int *arr7 = mm_malloc(sizeof(int) * 64 * alloc_len);
- mm_free(arr7);
- mm_free(arr3);
- mm_free(arr1);
- mm_free(arr6);
- mm_free(arr5);
- mm_free(arr4);
- mm_free(arr2);
- arr1 = mm_malloc(sizeof(int) * alloc_len);
- arr2 = mm_malloc(sizeof(int) * 2 * alloc_len);
- arr3 = mm_malloc(sizeof(int) * 4 * alloc_len);
- arr4 = mm_malloc(sizeof(int) * 8 * alloc_len);
- arr5 = mm_malloc(sizeof(int) * 16 * alloc_len);
- arr6 = mm_malloc(sizeof(int) * 32 * alloc_len);
- arr7 = mm_malloc(sizeof(int) * 64 * alloc_len);
- return 1;
- }
- int test_11()
- {
- int alloc_len = 10;
- int *arr1 = mm_malloc(sizeof(int) * alloc_len);
- int *arr2 = mm_malloc(sizeof(int) * alloc_len);
- mm_free(arr1);
- mm_free(arr2);
- return 1;
- }
- int test_12()
- {
- int alloc_len = 10;
- int *arr1 = mm_malloc(sizeof(int) * alloc_len);
- int *arr2 = mm_malloc(sizeof(int) * 2 * alloc_len);
- int *arr3 = mm_malloc(sizeof(int) * 4 * alloc_len);
- int *arr4 = mm_malloc(sizeof(int) * 8 * alloc_len);
- int *arr5 = mm_malloc(sizeof(int) * 16 * alloc_len);
- int *arr6 = mm_malloc(sizeof(int) * 32 * alloc_len);
- int *arr7 = mm_malloc(sizeof(int) * 64 * alloc_len);
- // mm_free(arr1);
- mm_free(arr2);
- mm_free(arr3);
- mm_free(arr4);
- mm_free(arr5);
- mm_free(arr6);
- // mm_free(arr7);
- // arr1 = mm_malloc(sizeof(int) * alloc_len);
- arr2 = mm_malloc(sizeof(int) * 2 * alloc_len);
- arr3 = mm_malloc(sizeof(int) * 4 * alloc_len);
- arr4 = mm_malloc(sizeof(int) * 8 * alloc_len);
- arr5 = mm_malloc(sizeof(int) * 16 * alloc_len);
- arr6 = mm_malloc(sizeof(int) * 32 * alloc_len);
- // arr7 = mm_malloc(sizeof(int) * 64 * alloc_len);
- return 1;
- }
- int test_13()
- {
- int arr_size = 20;
- int alloc_len = sizeof(int);
- int *arr[arr_size];
- for (int i = 0; i < arr_size; i++)
- arr[i] = mm_malloc(alloc_len);
- mm_free(arr[0]);
- arr[0] = mm_malloc(alloc_len);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement