Created
November 10, 2021 02:56
-
-
Save Molin-L/72a08e7f03891807dd43119fb6b4002b to your computer and use it in GitHub Desktop.
TestCase for ADAS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtest/gtest.h> | |
#include "Executor.h" | |
TEST(Executor, Report) | |
{ | |
Initialize(0, 0, Direction::North); | |
EXPECT_EQ("0,0,N", Report()); | |
} | |
TEST(Executor, Initialize) | |
{ | |
Initialize(12, 123, Direction::East); | |
EXPECT_EQ("12,123,E", Report()); | |
} | |
TEST(Executor, should_return_init_place_without_command) | |
{ | |
Initialize(0, 0, Direction::East); | |
EXPECT_EQ("0,0,E", Report()); | |
} | |
TEST(Executor, should_return_x_plus_1_given_command_is_M_and_facing_is_E) | |
{ | |
Initialize(0, 0, Direction::East); | |
Execute({Command::Forward}); | |
EXPECT_EQ("1,0,E", Report()); | |
} | |
TEST(Executor, should_return_x_minus_1_given_command_is_M_and_facing_is_W) | |
{ | |
Initialize(1, 1, Direction::West); | |
Execute({Command::Forward}); | |
EXPECT_EQ("0,1,W", Report()); | |
} | |
TEST(Executor, should_return_y_plus_1_given_command_is_F_and_facing_is_N) | |
{ | |
Initialize(1, 1, Direction::North); | |
Execute({Command::Forward}); | |
EXPECT_EQ("1,2,N", Report()); | |
} | |
TEST(Executor, should_return_y_minus_1_given_command_is_F_and_facing_is_S) | |
{ | |
Initialize(1, 1, Direction::South); | |
Execute({Command::Forward}); | |
EXPECT_EQ("1,0,S", Report()); | |
} | |
TEST(Executor, should_return_facing_N_given_command_is_L_and_facing_is_E) | |
{ | |
Initialize(1, 1, Direction::East); | |
Execute({Command::TurnLeft}); | |
EXPECT_EQ("1,1,N", Report()); | |
} | |
TEST(Executor, should_return_facing_W_given_command_is_L_and_facing_is_N) | |
{ | |
Initialize(1, 1, Direction::North); | |
Execute({Command::TurnLeft}); | |
EXPECT_EQ("1,1,W", Report()); | |
} | |
TEST(Executor, should_return_facing_S_given_command_is_L_and_facing_is_W) | |
{ | |
Initialize(1, 1, Direction::West); | |
Execute({Command::TurnLeft}); | |
EXPECT_EQ("1,1,S", Report()); | |
} | |
TEST(Executor, should_return_facing_E_given_command_is_L_and_facing_is_S) | |
{ | |
Initialize(1, 1, Direction::South); | |
Execute({Command::TurnLeft}); | |
EXPECT_EQ("1,1,E", Report()); | |
} | |
TEST(Executor, should_return_facing_S_given_command_is_R_and_facing_is_E) | |
{ | |
Initialize(1, 1, Direction::East); | |
Execute({Command::TurnRight}); | |
EXPECT_EQ("1,1,S", Report()); | |
} | |
TEST(Executor, should_return_facing_W_given_command_is_R_and_facing_is_S) | |
{ | |
Initialize(1, 1, Direction::South); | |
Execute({Command::TurnRight}); | |
EXPECT_EQ("1,1,W", Report()); | |
} | |
TEST(Executor, should_return_facing_N_given_command_is_R_and_facing_is_W) | |
{ | |
Initialize(1, 1, Direction::West); | |
Execute({Command::TurnRight}); | |
EXPECT_EQ("1,1,N", Report()); | |
} | |
TEST(Executor, should_return_facing_E_given_command_is_R_and_facing_is_N) | |
{ | |
Initialize(1, 1, Direction::North); | |
Execute({Command::TurnRight}); | |
EXPECT_EQ("1,1,E", Report()); | |
} | |
TEST(Executor, back_command_and_the_poition_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Back, | |
Command::Forward, | |
Command::Forward, | |
}); | |
EXPECT_EQ("0,-2,N", Report()); | |
} | |
TEST(Executor, back_and_fast_command_and_the_position_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Back, | |
Command::Fast, | |
Command::Forward, | |
Command::Forward, | |
}); | |
EXPECT_EQ("0,-4,N", Report()); | |
} | |
TEST(Executor, fast_and_back_command_and_the_position_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Fast, | |
Command::Back, | |
Command::Forward, | |
Command::Forward, | |
}); | |
EXPECT_EQ("0,-4,N", Report()); | |
} | |
TEST(Executor, fast_back_fast_command_recover_and_the_position_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Fast, | |
Command::Back, | |
Command::Fast, | |
Command::Forward, | |
Command::Forward, | |
Command::Forward, | |
Command::Forward, | |
}); | |
EXPECT_EQ("0,-4,N", Report()); | |
} | |
TEST(Executor, back_fast_back_command_recover_and_the_position_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Back, | |
Command::Fast, | |
Command::Back, | |
Command::Forward, | |
Command::Forward, | |
Command::Forward, | |
Command::Forward, | |
}); | |
EXPECT_EQ("0,8,N", Report()); | |
} | |
TEST(Executor, fast_command_right_move_and_the_position_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Fast, | |
Command::TurnRight, | |
}); | |
EXPECT_EQ("0,1,E", Report()); | |
} | |
TEST(Executor, fast_command_left_move_and_the_position_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Fast, | |
Command::TurnLeft, | |
}); | |
EXPECT_EQ("0,1,W", Report()); | |
} | |
TEST(Executor, fast_back_command_right_move_and_the_position_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Fast, | |
Command::Back, | |
Command::TurnRight, | |
}); | |
EXPECT_EQ("0,-1,E", Report()); | |
} | |
TEST(Executor, fast_back_command_left_move_and_the_position_info_should_be_correct) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({ | |
Command::Fast, | |
Command::Back, | |
Command::TurnLeft, | |
}); | |
EXPECT_EQ("0,-1,W", Report()); | |
} | |
TEST(Executor, normal_forward_get_hole_in_its_way_and_should_stop) | |
{ | |
Initialize(0, 0, Direction::North); | |
ExecutorConfigHole({0, 1}); | |
Execute({Command::Forward}); | |
EXPECT_EQ("0,0,N", Report()); | |
} | |
TEST(Executor, remove_hole_should_get_to_hole_position) | |
{ | |
Initialize(0, 0, Direction::North); | |
ExecutorConfigHole({0, 1}); | |
ExecutorConfigRemoveHole({0, 1}); | |
Execute({Command::Forward}); | |
EXPECT_EQ("0,1,N", Report()); | |
} | |
TEST(Executor, turn_around_should_get_to_the_right_position) | |
{ | |
Initialize(0, 0, Direction::North); | |
Execute({Command::TurnAround}); | |
EXPECT_EQ("-1,0,S", Report()); | |
} | |
TEST(Executor, turn_around_should_stop_at_hole) | |
{ | |
Initialize(0, 0, Direction::North); | |
ExecutorConfigHole({-1, 0}); | |
Execute({Command::TurnAround}); | |
EXPECT_EQ("0,0,W", Report()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment