From 41301ece28603a15451b1e087449dd488840fe7f Mon Sep 17 00:00:00 2001 From: John Breaux Date: Sun, 3 Apr 2022 11:48:24 -0500 Subject: [PATCH] Move tests to test.cpp; build: `make test.out` --- main.cpp | 14 +------------- test.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 test.cpp diff --git a/main.cpp b/main.cpp index 33f5773..43dc336 100644 --- a/main.cpp +++ b/main.cpp @@ -12,18 +12,6 @@ list freelist = {0}, list1 = {0}, list2 = {0}; int main (int argc, char* argv[]) { // initialize the freelist list_init(&freelist, memory, N); - - // print the list + // print the freelist list_print(&freelist); - list_print(&list1); - - // move a block - block* b; - while (b = list_unlink(&freelist)) { - list_link(&list1, b); - // print the list - std::printf("\n"); - list_print(&freelist); - list_print(&list1); - } } diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..917695e --- /dev/null +++ b/test.cpp @@ -0,0 +1,38 @@ +#include +#include +#include "list.hpp" + +#define N 0x8 + +int movement_test (); + +int main(int argc, char *argv[]) { + movement_test(); +} + +int movement_test () { + + // Create all of memory + block memory[N] = {0}; + // create the three lists + list freelist = {0}, list1 = {0}; + // initialize the freelist + list_init(&freelist, memory, N); + + // print the lists + std::printf("Lists:\n"); + list_print(&freelist); + list_print(&list1); + + // move a block + block *b; + while (b = list_unlink(&freelist)) + { + list_link(&list1, b); + } + // print the lists again (should be reversed order) + std::printf("Lists, again:\n"); + list_print(&freelist); + list_print(&list1); + return 1; +}