完成了创建轨道函数

修复了query.c中错误的定义
添加了创建轨道的测试
This commit is contained in:
2022-05-17 21:15:19 +08:00
parent 7a35acda0c
commit 9902af7548
4 changed files with 79 additions and 36 deletions

View File

@@ -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);
}

44
test/rail_test.cpp Normal file
View File

@@ -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;
}
}