boot.dev lesson answers for the course: Learn Memory Management in C
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

30 lines
751 B

#include <stdio.h>
#include <stdlib.h>
// #include "bootlib.h"
#include "munit.h"
#include "snekobject.h"
munit_case(RUN, test_int_has_refcount, {
snek_object_t *obj = new_snek_integer(10);
assert_int(obj->refcount, ==, 1, "Refcount should be 1 on creation");
free(obj);
});
munit_case(SUBMIT, test_float_has_refcount, {
snek_object_t *obj = new_snek_float(42.0);
assert_int(obj->refcount, ==, 1, "Refcount should be 1 on creation");
free(obj);
});
int main() {
MunitTest tests[] = {
munit_test("test_int_has_refcount", test_int_has_refcount),
munit_test("test_float_has_refcount", test_float_has_refcount),
munit_null_test,
};
MunitSuite suite = munit_suite("refcount", tests);
return munit_suite_main(&suite, NULL, 0, NULL);
}