From 6095d0849bbac49c353a33447c08e2f0c1224715 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Fri, 20 May 2022 08:52:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86ReadInput=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=B8=AD=E7=9A=84=E7=B3=BB=E5=88=97=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20ReadInput=E5=87=BD=E6=95=B0=E6=B5=8B=E8=AF=95=E9=80=9A?= =?UTF-8?q?=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/bus.h | 2 +- include/bus_io.h | 3 +++ src/bus.c | 2 +- src/bus_io.c | 12 ++++++++---- test/io_test.cpp | 25 +++++++++++++++++++++---- test/rail_test.cpp | 6 ------ 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/include/bus.h b/include/bus.h index ac158f0..b4b85f0 100644 --- a/include/bus.h +++ b/include/bus.h @@ -24,7 +24,7 @@ typedef struct bus bus_t; /** * 全局的公交车变量 */ -extern bus_t the_bus; +extern bus_t *the_bus; /** * 每个时刻使公交车前进 diff --git a/include/bus_io.h b/include/bus_io.h index 8ae2cb8..1cf142b 100644 --- a/include/bus_io.h +++ b/include/bus_io.h @@ -6,6 +6,9 @@ #define AUTO_PILOT_BUS_BUS_IO_H #include "rail.h" #include "query.h" +#include "define.h" +#include "string.h" +#include "stdio.h" /** * 读取配置文件,创建轨道链表,同时读取需要使用的策略 diff --git a/src/bus.c b/src/bus.c index 0d08cab..6c2a29d 100644 --- a/src/bus.c +++ b/src/bus.c @@ -1,3 +1,3 @@ #include "bus.h" -bus_t *the_bus; \ No newline at end of file +bus_t *the_bus = NULL; \ No newline at end of file diff --git a/src/bus_io.c b/src/bus_io.c index b79100a..3d623a8 100644 --- a/src/bus_io.c +++ b/src/bus_io.c @@ -2,7 +2,6 @@ // Created by ricardo on 2022/5/6. // #include "bus_io.h" -#include "define.h" int ReadInput(char* inputString) { @@ -16,22 +15,27 @@ int ReadInput(char* inputString) } else if (0 == strcmp("counterclockwise",src)) { - bus_query_t *CreateQuery(BUS_COUNTER_CLOCK_WISE, FindNode(num)); + CreateQuery(BUS_COUNTER_CLOCK_WISE, FindNode(rails ,num)); return IO_READING; } else if (0 == strcmp("clockwise",src)) { - bus_query_t *CreateQuery(BUS_CLOCK_WISE,FindNode(num)); + CreateQuery(BUS_CLOCK_WISE,FindNode(rails, num)); return IO_READING; } else if (0 == strcmp("target",src)) { - bus_query_t *CreateQuery(BUS_TARGET,FindNode(num)); + CreateQuery(BUS_TARGET,FindNode(rails, num)); return IO_READING; } else if (0 == strcmp("end",src)) { return IO_END; } + else + { + // 匹配失败则返回-1 + return -1; + } } diff --git a/test/io_test.cpp b/test/io_test.cpp index fe79dd4..413cc25 100644 --- a/test/io_test.cpp +++ b/test/io_test.cpp @@ -8,15 +8,32 @@ extern "C" { #endif -#include "rail.h" +#include "bus_io.h" +#include "define.h" #ifdef __cplusplus } #endif using namespace testing; -TEST(test, test) +TEST(bus_io, ReadInput_clock) { - int result = add(1, 1); - EXPECT_EQ(2, result); + int result; + char str[10] = "clock\n"; + result = ReadInput(str); + EXPECT_EQ(result, IO_CLOCK); +} + +TEST(bus_io, ReadInput_end) +{ + char str[5] = "end\n"; + int result = ReadInput(str); + EXPECT_EQ(result, IO_END); +} + +TEST(bus_io, ReadInput_reading) +{ + char str[20] = "target 8\n"; + int result = ReadInput(str); + EXPECT_EQ(result, IO_READING); } \ No newline at end of file diff --git a/test/rail_test.cpp b/test/rail_test.cpp index d05bf4b..511b900 100644 --- a/test/rail_test.cpp +++ b/test/rail_test.cpp @@ -50,12 +50,6 @@ TEST(rail, FindNode) EXPECT_EQ(p->id, 9); } -TEST(rail, FreeRails) -{ - rail_node_t *head = CreateRails(10, 10); - FreeRails(head); -} -