整体测试框架设计完成

This commit is contained in:
jackfiled 2022-05-21 17:31:27 +08:00
parent a9200ede29
commit 8a70c8255d
7 changed files with 377 additions and 0 deletions

View File

@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.10) # cmakecmake
add_subdirectory(test)
add_subdirectory(all_test)
project(auto_pilot_bus) #

10
all_test/CMakeLists.txt Normal file
View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.0)
project(bus_all_test)
include_directories(../include)
include_directories(include)
aux_source_directory("../src/" SRCS)
aux_source_directory("${CMAKE_CURRENT_SOURCE_DIR}/src" ALL_TEST_SRCS)
add_executable(bus_all_test ${SRCS} ${ALL_TEST_SRCS} main.c)

18
all_test/include/tools.h Normal file
View File

@ -0,0 +1,18 @@
//
// Created by ricardo on 2022/5/20.
//
#ifndef AUTO_PILOT_BUS_TOOLS_H
#define AUTO_PILOT_BUS_TOOLS_H
#include "stdio.h"
#include "string.h"
#include "define.h"
void ChooseTestCaseInput(char *path, int index);
void ChooseTestCaseOutput(char *path, int index);
void ReadOutputFile(char *result, FILE *f);
int CheckOutput(char *program_output, char *read_output);
#endif //AUTO_PILOT_BUS_TOOLS_H

133
all_test/main.c Normal file
View File

@ -0,0 +1,133 @@
//
// Created by ricardo on 2022/5/20.
//
#include "bus_io.h"
#include "tools.h"
int main()
{
/**
*
*/
char input[30];
/**
*
*/
char output[150];
/**
* the_bus指针的本体
*/
bus_t main_bus;
/**
*
*/
int direction;
/**
*
*/
bus_query_t *finished_query;
int index;
char path[50];
char read_output[150];
FILE *input_file = NULL;
FILE *output_file = NULL;
printf("Please choose which test case to use:");
scanf("%d\n", &index);
ChooseTestCaseInput(path, index);
input_file = fopen(path, "r");
ChooseTestCaseOutput(path, index);
output_file = fopen(path, "r");
// 读取配置文件
rails = ReadConfigFile();
// 制造公交车
the_bus = &main_bus;
the_bus->distance = 0;
the_bus->rail_node_pos = FindNode(rails, 1);
// 开始时公交车应该是停下的
direction = BUS_STOP;
PrintState(output);
ReadOutputFile(read_output, output_file);
if(CheckOutput(output, read_output) == BUS_FAlSE)
{
printf("%s\n", output);
}
else
{
printf("%d Ok\n", bus_time);
}
for(;;)
{
fgets(input, sizeof input, input_file);
int result = ReadInput(input);
if(result == IO_CLOCK)
{
// 时间流动
AddTime();
switch (chosen_strategy)
{
case BUS_FCFS:
// 如果到站,处理请求和
if(JudgeOnStation() == BUS_TRUE)
{
direction = FCFSDirection();
finished_query = FCFSQuery();
if(finished_query != NULL) // 有请求就处理请求
{
// 循环处理所有可以处理的请求,总共消耗一秒
while (finished_query != NULL)
{
DeleteQuery(finished_query);
finished_query = FCFSQuery();
}
}
else //如果没有请求就继续前进
{
RunBus(direction);
}
}
else
{
RunBus(direction);
}
break;
case BUS_SSTF:
break;
case BUS_SCAN:
break;
default:
break;
}
PrintState(output);
ReadOutputFile(read_output, output_file);
if(CheckOutput(output, read_output) == BUS_FAlSE)
{
printf("%s\n", output);
}
else
{
printf("%d Ok\n", bus_time);
}
}
else if(result == IO_END)
{
printf("end\n");
break;
}
else
{
//在读取到创建请求的情况下,不做任何事
}
}
}

60
all_test/src/tools.c Normal file
View File

@ -0,0 +1,60 @@
//
// Created by ricardo on 2022/5/20.
//
#include "tools.h"
void ChooseTestCaseInput(char *path, int index)
{
memset(path, 0, 50);
char root_path[] = "./test_cases/";
char input_file[] = "/input.txt";
char case_path[3];
sprintf(case_path, "%d", index);
strcat(path, root_path);
strcat(path, case_path);
strcat(path, input_file);
}
void ChooseTestCaseOutput(char *path, int index)
{
memset(path, 0, 50);
char root_path[] = "./test_cases/";
char output_file[] = "/output.txt";
char case_path[3];
sprintf(case_path, "%d", index);
strcat(path, root_path);
strcat(path, case_path);
strcat(path, output_file);
}
void ReadOutputFile(char *result, FILE *f)
{
memset(result, 0, 150);
for(size_t i = 0; i < 7; i++)
{
char temp[50];
fgets(temp, 50, f);
strcat(result, temp);
}
}
int CheckOutput(char *program_output, char *read_output)
{
int result = strcmp(program_output, read_output);
if(result == 0)
{
return BUS_TRUE;
}
else
{
return BUS_FAlSE;
}
}

View File

@ -0,0 +1,21 @@
clock
counterclockwise 3
clock
clock
clock
clock
clock
clock
target 10
clock
clock
clock
clock
clock
clock
clock
clock
clock
clock
clock
end

View File

@ -0,0 +1,134 @@
TIME:0
BUS:
position:0
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:1
BUS:
position:0
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:2
BUS:
position:1
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0010000000
TIME:3
BUS:
position:2
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0010000000
TIME:4
BUS:
position:3
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0010000000
TIME:5
BUS:
position:4
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0010000000
TIME:6
BUS:
position:5
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0010000000
TIME:7
BUS:
position:6
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0010000000
TIME:8
BUS:
position:6
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:9
BUS:
position:5
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:10
BUS:
position:4
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:11
BUS:
position:3
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:12
BUS:
position:2
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:13
BUS:
position:1
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:14
BUS:
position:0
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:15
BUS:
position:29
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:16
BUS:
position:28
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:17
BUS:
position:27
target:0000000001
STATION:
clockwise:0000000000
counterclockwise:0000000000
TIME:18
BUS:
position:27
target:0000000000
STATION:
clockwise:0000000000
counterclockwise:0000000000
end