修复了ReadInput函数中的系列错误
ReadInput函数测试通过
This commit is contained in:
		@@ -24,7 +24,7 @@ typedef struct bus bus_t;
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * 全局的公交车变量
 | 
					 * 全局的公交车变量
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
extern bus_t the_bus;
 | 
					extern bus_t *the_bus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 每个时刻使公交车前进
 | 
					 * 每个时刻使公交车前进
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,9 @@
 | 
				
			|||||||
#define AUTO_PILOT_BUS_BUS_IO_H
 | 
					#define AUTO_PILOT_BUS_BUS_IO_H
 | 
				
			||||||
#include "rail.h"
 | 
					#include "rail.h"
 | 
				
			||||||
#include "query.h"
 | 
					#include "query.h"
 | 
				
			||||||
 | 
					#include "define.h"
 | 
				
			||||||
 | 
					#include "string.h"
 | 
				
			||||||
 | 
					#include "stdio.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 读取配置文件,创建轨道链表,同时读取需要使用的策略
 | 
					 * 读取配置文件,创建轨道链表,同时读取需要使用的策略
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,3 +1,3 @@
 | 
				
			|||||||
#include "bus.h"
 | 
					#include "bus.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bus_t *the_bus;
 | 
					bus_t *the_bus = NULL;
 | 
				
			||||||
							
								
								
									
										12
									
								
								src/bus_io.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/bus_io.c
									
									
									
									
									
								
							@@ -2,7 +2,6 @@
 | 
				
			|||||||
// Created by ricardo on 2022/5/6.
 | 
					// Created by ricardo on 2022/5/6.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
#include "bus_io.h"
 | 
					#include "bus_io.h"
 | 
				
			||||||
#include "define.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
int ReadInput(char* inputString)
 | 
					int ReadInput(char* inputString)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -16,22 +15,27 @@ int ReadInput(char* inputString)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (0 == strcmp("counterclockwise",src))
 | 
					    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;
 | 
					        return IO_READING;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (0 == strcmp("clockwise",src))
 | 
					    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;
 | 
					        return IO_READING;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (0 == strcmp("target",src))
 | 
					    else if (0 == strcmp("target",src))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        bus_query_t *CreateQuery(BUS_TARGET,FindNode(num));
 | 
					        CreateQuery(BUS_TARGET,FindNode(rails, num));
 | 
				
			||||||
        return IO_READING;
 | 
					        return IO_READING;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if (0 == strcmp("end",src))
 | 
					    else if (0 == strcmp("end",src))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return IO_END;
 | 
					        return IO_END;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // 匹配失败则返回-1
 | 
				
			||||||
 | 
					        return -1;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,15 +8,32 @@
 | 
				
			|||||||
extern "C"
 | 
					extern "C"
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#include "rail.h"
 | 
					#include "bus_io.h"
 | 
				
			||||||
 | 
					#include "define.h"
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using namespace testing;
 | 
					using namespace testing;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(test, test)
 | 
					TEST(bus_io, ReadInput_clock)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int result = add(1, 1);
 | 
					    int result;
 | 
				
			||||||
    EXPECT_EQ(2, 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);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -50,12 +50,6 @@ TEST(rail, FindNode)
 | 
				
			|||||||
    EXPECT_EQ(p->id, 9);
 | 
					    EXPECT_EQ(p->id, 9);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST(rail, FreeRails)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    rail_node_t *head = CreateRails(10, 10);
 | 
					 | 
				
			||||||
    FreeRails(head);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user