diff --git a/src/query.c b/src/query.c index c705912..642474b 100644 --- a/src/query.c +++ b/src/query.c @@ -3,6 +3,5 @@ // #include "query.h" -up_bus_t* up_queries = NULL; -down_bus_t *down_queries = NULL; + diff --git a/src/rail.c b/src/rail.c index 721e09f..bd21bb6 100644 --- a/src/rail.c +++ b/src/rail.c @@ -5,4 +5,38 @@ rail_node_t *rails = NULL; int add(int a, int b) { return a+ b; +} + +rail_node_t *CreateRails(int length, int node_num) +{ + /** + * 表示轨道的头节点 + */ + rail_node_t *head = NULL; + rail_node_t *node = NULL; + + head = (rail_node_t*) malloc(sizeof (rail_node_t)); + head->id = 1; + head->last_node_distance = length; + head->next_node_distance = length; + + node = head; + // 循环创建每一个节点 + for(int i = 2; i <= node_num; i++) + { + rail_node_t *p = (rail_node_t*) malloc(sizeof (rail_node_t)); + + p->id = i; + p->last_node_distance = length; + p->next_node_distance = length; + p->last_node = node; + node->next_node = p; + node = p; + } + + // 循环结束时node就是最后一个节点 + node->next_node = head; + head->last_node = node; + + return head; } \ No newline at end of file diff --git a/test/io_test.cpp b/test/io_test.cpp index 6e44831..fe79dd4 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -9,48 +9,14 @@ extern "C" { #endif #include "rail.h" -#include "bus_io.h" -#include "query.h" -#include "define.h" #ifdef __cplusplus } #endif -using ::testing::Return; -using ::testing::AtLeast; -using ::testing::Exactly; - using namespace testing; TEST(test, test) { int result = add(1, 1); EXPECT_EQ(2, result); -} - -/** - * 测试输入读取函数读取clock时的行为 - */ -TEST(io_test, io_clock) -{ - char input[7] = "clock\n"; - int result = ReadInput(input); - EXPECT_EQ(result, IO_CLOCK); -} - -/** - * 测试顺时针3号站台上车请求 - */ -TEST(io_test, reading) -{ - char input[] = "counterclockwise 3\n"; - int result = ReadInput(input); - EXPECT_EQ(result, IO_READING); -} - -TEST(io_test, end) -{ - char input[] = "end\n"; - int result = ReadInput(input); - EXPECT_EQ(result, IO_END); } \ No newline at end of file diff --git a/test/rail_test.cpp b/test/rail_test.cpp new file mode 100644 index 0000000..d30b3f1 --- /dev/null +++ b/test/rail_test.cpp @@ -0,0 +1,44 @@ +// +// Created by ricardo on 2022/5/17. +// +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#ifdef __cplusplus +extern "C" +{ +#endif +#include "rail.h" +#ifdef __cplusplus +} +#endif + +using namespace testing; + +TEST(rail, CreateRails) +{ + rail_node_t *head = CreateRails(10, 10); + rail_node_t *p = head; + + for(int i = 1; i <= 10; i++) + { + EXPECT_EQ(p->id, i); + EXPECT_EQ(p->next_node_distance, 10); + EXPECT_EQ(p->last_node_distance, 10); + p = p->next_node; + } + + p = head->last_node; + for(int i = 10; i >= 1; i--) + { + EXPECT_EQ(p->id, i); + EXPECT_EQ(p->next_node_distance, 10); + EXPECT_EQ(p->last_node_distance, 10); + p = p->last_node; + } +} + + + + +