You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Check that the allocated entry was initialized with expected values
37
+
mu_assert(check_strings(ce->path, path) ==0, "Your alloc_entry function did not allocate the path field to the expected string");
38
+
mu_assert(check_strings(ce->content_type, content_type) ==0, "Your alloc_entry function did not allocate the content_type field to the expected string");
39
+
mu_assert(check_strings(ce->content, content) ==0, "Your alloc_entry function did not allocate the content field to the expected string");
40
+
mu_assert(ce->content_length==strlen(content), "Your alloc_entry function did not allocate the content_length field to the expected length")
// Check that the cache is handling a single entry as expected
60
+
mu_assert(cache->cur_size==1, "Your cache_put function did not correctly increment the cur_size field when adding a new cache entry");
61
+
mu_assert(cache->head->prev==NULL&&cache->tail->next==NULL, "The head and tail of your cache should have NULL prev and next pointers when a new entry is put in an empty cache");
62
+
mu_assert(check_cache_entries(cache->head, test_entry_1) ==0, "Your cache_put function did not put an entry into the head of the empty cache with the expected form");
63
+
mu_assert(check_cache_entries(cache->tail, test_entry_1) ==0, "Your cache_put function did not put an entry into the tail of the empty cache with the expected form")
64
+
mu_assert(check_cache_entries(hashtable_get(cache->index, "/1"), test_entry_1) ==0, "Your cache_put function did not put the expected entry into the hashtable");
// Check that the cache is handling both entries as expected
69
+
mu_assert(cache->cur_size==2, "Your cache_put function did not correctly increment the cur_size field when adding a new cache entry");
70
+
mu_assert(check_cache_entries(cache->head, test_entry_2) ==0, "Your cache_put function did not put an entry into the head of the cache with the expected form");
71
+
mu_assert(check_cache_entries(cache->tail, test_entry_1) ==0, "Your cache_put function did not move the oldest entry in the cache to the tail of the cache");
72
+
mu_assert(check_cache_entries(cache->head->next, test_entry_1) ==0, "Your cache_put function did not correctly set the head->next pointer of the cache");
73
+
mu_assert(check_cache_entries(hashtable_get(cache->index, "/2"), test_entry_2) ==0, "Your cache_put function did not put the expected entry into the hashtable");
// Check that the cache is handling all three entries as expected
78
+
mu_assert(cache->cur_size==3, "Your cache_put function did not correctly increment the cur_size field when adding a new cache entry");
79
+
mu_assert(check_cache_entries(cache->head, test_entry_3) ==0, "Your cache_put function did not correctly update the head pointer of the cache");
80
+
mu_assert(check_cache_entries(cache->head->next, test_entry_2) ==0, "Your cache_put function did not update the head->next pointer to point to the old head");
81
+
mu_assert(check_cache_entries(cache->head->next->prev, test_entry_3) ==0, "Your cache_put function did not update the head->next->prev pointer to point to the new head entry");
82
+
mu_assert(check_cache_entries(cache->head->next->next, test_entry_1) ==0, "Your cache_put function did not update the head->next->next pointer to point to the tail entry");
83
+
mu_assert(check_cache_entries(cache->tail->prev, test_entry_2) ==0, "Your cache_put function did not update the tail->prev pointer to poin to the second-to-last entry");
84
+
mu_assert(check_cache_entries(cache->tail, test_entry_1) ==0, "Your cache_put function did not correctly update the tail pointer of the cache");
// Check that the cache removed the oldest entry and is handling the three most-recent entries correctly
89
+
mu_assert(cache->cur_size==3, "Your cache_put function did not correctly handle the cur_size field when adding a new cache entry to a full cache");
90
+
mu_assert(check_cache_entries(cache->head, test_entry_4) ==0, "Your cache_put function did not correctly handle adding a new entry to an already-full cache");
91
+
mu_assert(check_cache_entries(cache->head->next, test_entry_3) ==0, "Your cache_put function did not update the head->next pointer to point to the old head");
92
+
mu_assert(check_cache_entries(cache->head->next->prev, test_entry_4) ==0, "Your cache_put function did not update the head->next->prev pointer to point to the new head entry");
93
+
mu_assert(check_cache_entries(cache->head->next->next, test_entry_2) ==0, "Your cache_put function did not update the head->next->next pointer to point to the tail entry");
94
+
mu_assert(check_cache_entries(cache->tail->prev, test_entry_3) ==0, "Your cache_put function did not update the tail->prev pointer to poin to the second-to-last entry");
95
+
mu_assert(check_cache_entries(cache->tail, test_entry_2) ==0, "Your cache_put function did not correctly handle the tail of an already-full cache");
// Check that the retrieved entry's values match the values of the inserted entry
117
+
mu_assert(check_cache_entries(entry, test_entry_1) ==0, "Your cache_get function did not retrieve the newly-added cache entry when there was 1 entry in the cache");
118
+
119
+
// Insert another entry into the cache, then retrieve it
// Check the retrieved entry's values and also check that the entries are ordered correctly in the cache
123
+
mu_assert(check_cache_entries(entry, test_entry_2) ==0, "Your cache_get function did not retrieve the newly-added cache entry when there were 2 entries in the cache");
124
+
mu_assert(check_cache_entries(cache->head, test_entry_2) ==0, "Your cache_get function did not update the head pointer to point to the newly-added entry when there are 2 entries");
125
+
mu_assert(check_cache_entries(cache->tail, test_entry_1) ==0, "Your cache_get function did not move the oldest entry to the tail of the cache");
126
+
127
+
// Insert a third entry into the cache, then retrieve it
// Check the retrieved entry's values and also check that the entries are ordered correctly in the cache
131
+
mu_assert(check_cache_entries(entry, test_entry_3) ==0, "Your cache_get function did not retrieve the newly-added cache entry when there were 3 entries in the cache");
132
+
mu_assert(check_cache_entries(cache->head, test_entry_3) ==0, "Your cache_get function did not update the head pointer to point to the newly-added entry when there are 3 entries");
133
+
mu_assert(check_cache_entries(cache->tail, test_entry_2) ==0, "Your cache_get function did not move the oldest entry to the tail of the cache when there are 3 entries");
134
+
// Check that the oldest cache entry cannot be retrieved
135
+
mu_assert(cache_get(cache, test_entry_1->path) ==NULL, "Your cache_get function did not remove the oldest entry from the cache");
136
+
137
+
// Retrieve the oldest entry in the cache
138
+
entry=cache_get(cache, test_entry_2->path);
139
+
// Check that the most-recently accessed entry has been moved to the head of the cache
140
+
mu_assert(check_cache_entries(cache->head, test_entry_2) ==0, "Your cache_get function did not move the most-recently retrieved entry to the head of the cache");
141
+
mu_assert(check_cache_entries(cache->tail, test_entry_3) ==0, "Your cache_get function did not move the oldest entry to the tail of the cache");
0 commit comments