removing AI and am going to start learning how to write my own unit tests
This commit is contained in:
+27
-42
@@ -7,12 +7,8 @@
|
||||
|
||||
/*
|
||||
* All functions needed
|
||||
* assign() Fills a vector with multiple values
|
||||
* data() Returns a pointer to the block of memory where a vector's elements are
|
||||
* stored
|
||||
* erase() Removes a number of elements from a vector
|
||||
* assign() Fills a vector with multiple values stored
|
||||
* insert() Inserts a number of elements into a vector
|
||||
* max_size() Returns the maximum number of elements that a
|
||||
* vector can have pop_back() Removes the last element of a vector rbegin()
|
||||
* Returns a reverse iterator pointing to the last element of a vector rend()
|
||||
* Returns a reverse iterator pointing to a position right before the first
|
||||
@@ -31,16 +27,6 @@
|
||||
* String
|
||||
*/
|
||||
|
||||
/* Absolutely no AI is permitted when writing code.
|
||||
* AI is and can be used to generate tests for code; however, the test results
|
||||
* and the AI can not give code as to how to fix the source aside from psuedo
|
||||
* code that has no clear relation to the source aside from a recreation of the
|
||||
* problem in a different way entirely
|
||||
*
|
||||
* Any code comments below are just used for my purposes with short term memory.
|
||||
* It also serves as a way to remember what needs to be changed to be readable
|
||||
* and not need comments in the first place.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -68,6 +54,26 @@ create(const Vec8_t* input)
|
||||
return vec;
|
||||
}
|
||||
|
||||
Vec8_t*
|
||||
shrink_to_fit(const Vec8_t* ptr) {
|
||||
/* Create a new empty heap
|
||||
* copy current ptr values
|
||||
* realloc heap to current size
|
||||
*
|
||||
* */
|
||||
}
|
||||
|
||||
char*
|
||||
data(const Vec8_t* ptr) {
|
||||
if(ptr == nullptr || ptr->arr == nullptr) return nullptr;
|
||||
return &ptr->arr[0];
|
||||
}
|
||||
|
||||
size_t
|
||||
max_size(const Vec8_t* ptr) {
|
||||
return ptr->capacity;
|
||||
}
|
||||
|
||||
void
|
||||
delete(Vec8_t* vec)
|
||||
{
|
||||
@@ -114,17 +120,6 @@ at(const Vec8_t* vec, const int idx)
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 1. Single erase (line 117-126):
|
||||
// - size-- before memmove → wrong copy size
|
||||
// - arr[iter] = 0 after memmove → zeros shifted element
|
||||
// - Result: a b \0 e f g h i j (after erasing index 2 from a b c d e f g h i j)
|
||||
// 2. Range erase (line 128-140):
|
||||
// - Bounds check uses && (should be ||)
|
||||
// - diff = iter_end - iter_start (off-by-one for inclusive range)
|
||||
// - memmove uses iter_end not iter_end+1
|
||||
// - Zeroing loop zeros wrong positions
|
||||
// - Result: a b \0 \0 g h i j (size=8, should be 7)
|
||||
|
||||
__attribute__((overloadable)) Vec8_t*
|
||||
erase(Vec8_t* vec, const size_t iter) {
|
||||
if(vec == nullptr) return nullptr;
|
||||
@@ -140,7 +135,7 @@ __attribute__((overloadable)) Vec8_t*
|
||||
erase(Vec8_t* vec, const size_t iter_start, const size_t iter_end) {
|
||||
if(vec == nullptr) return nullptr;
|
||||
if(vec->arr == nullptr) return nullptr;
|
||||
if(iter_start < 0 || iter_end >= vec->size) return nullptr;
|
||||
if(iter_start < 0 || iter_end > vec->size) return nullptr;
|
||||
if(iter_start >= iter_end) return nullptr;
|
||||
size_t diff = iter_end - iter_start;
|
||||
memmove(&vec->arr[iter_start], &vec->arr[iter_end], (vec->size - iter_end) * sizeof(char));
|
||||
@@ -239,21 +234,11 @@ main()
|
||||
vec = add_back(&vec, '6');
|
||||
|
||||
size_t size = vec.size;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if(vec.arr[i] == 0) printf("0");
|
||||
printf("%c ", vec.arr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
// print_vec(&vec);
|
||||
vec = *erase(&vec, begin(&vec) + 2);
|
||||
// vec = *erase(&vec, begin(&vec) + 2, begin(&vec) + 4);
|
||||
for (int i = 0; i < size; i++) {
|
||||
if(vec.arr[i] == 0) printf("0");
|
||||
printf("%c ", vec.arr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
// print_vec(&vec);
|
||||
// printf("%c", at(nullptr, 0));
|
||||
print_vec(&vec);
|
||||
// vec = *erase(&vec, begin(&vec) + 2);
|
||||
vec = *erase(&vec, begin(&vec) + 2, begin(&vec) + 4);
|
||||
print_vec(&vec);
|
||||
printf("%p", data(&vec));
|
||||
|
||||
delete(&vec);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user