Merge branch 'release-2.1.0'
[purplehaze.git] / test / unit / test_time.cpp
blobc6069c34cc80ea07637f4ac1fd306e5cb9b62ae6
1 #include "../../src/time.h"
2 #include "gtest/gtest.h"
4 TEST(TimeTest, Constructor)
6 // Default constructor
7 Time t1;
8 const int moves = 40;
9 const int time = 5 * 60 * 100; // 5 minutes in centiseconds
10 EXPECT_EQ(time / moves, t1.allocated());
12 // Explicit constructor
13 Time t2(moves, time);
14 EXPECT_EQ(time / moves, t2.allocated());
17 TEST(TimeTest, Thinking)
19 const int level_moves = 40;
20 const int level_time = 5 * 60 * 100; // 5 minutes in centiseconds
21 const int time_per_move = level_time / level_moves;
22 Time t(level_moves, level_time);
24 int time = level_time;
25 for (int ply = 0; ply < 200; ++ply) {
26 t.set_remaining(time);
27 t.start_thinking(ply);
28 EXPECT_EQ(time_per_move, t.allocated());
30 if (ply % 2 != 0) {
31 if (((ply / 2) + 1) % level_moves == 0) {
32 time = level_time;
33 } else {
34 time -= time_per_move;
40 // TODO: Add polling and abort tests