forked from gamekeepers/snake-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsnake_test.cpp
More file actions
49 lines (35 loc) · 1.59 KB
/
snake_test.cpp
File metadata and controls
49 lines (35 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <gtest/gtest.h>
#include "snake.h"
TEST(SnakeBehaviour, NextHeadRight) {
pair<int, int> current = make_pair(rand() % 10, rand() % 10);
EXPECT_EQ(get_next_head(current, 'r'),make_pair(current.first,current.second+1));
}
TEST(SnakeBehaviour, NextHeadLeft) {
pair<int, int> current = make_pair(rand() % 10, rand() % 10);
EXPECT_EQ(get_next_head(current, 'l'),make_pair(current.first,current.second-1));
}
TEST(SnakeBehaviour, NextHeadUp) {
pair<int, int> current = make_pair(rand() % 10, rand() % 10);
EXPECT_EQ(get_next_head(current, 'u'),make_pair(current.first-1,current.second));
}
TEST(SnakeBehaviour, NextHeadDown) {
pair<int, int> current = make_pair(rand() % 10, rand() % 10);
EXPECT_EQ(get_next_head(current, 'd'),make_pair(current.first+1,current.second));
}
/**
* g++ -o my_tests snake_test.cpp -lgtest -lgtest_main -pthread;
* This command is a two-part shell command. Let's break it down.
The first part is the compilation:
g++ -o my_tests hello_gtest.cpp -lgtest -lgtest_main -pthread
* g++: This invokes the GNU C++ compiler.
* -o my_tests: This tells the compiler to create an executable file named
my_tests.
* hello_gtest.cpp: This is the C++ source file containing your tests.
* -lgtest: This links the Google Test library, which provides the core testing
framework.
* -lgtest_main: This links a pre-compiled main function provided by Google
Test, which saves you from writing your own main() to run the tests.
* -pthread: This links the POSIX threads library, which is required by Google
Test for its operation.
*
*/