完成了创建轨道函数

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

View File

@ -3,6 +3,5 @@
//
#include "query.h"
up_bus_t* up_queries = NULL;
down_bus_t *down_queries = NULL;

View File

@ -6,3 +6,37 @@ 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;
}

View File

@ -9,17 +9,10 @@ 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)
@ -27,30 +20,3 @@ 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;
}
}