Scheduler
stateSpaceTest.cpp
Go to the documentation of this file.
1 
10 #include "stateSpaceTest.h"
11 #include <iostream>
12 class StateSpaceTest : public ::testing::Test
13 {
14 public:
15  std::shared_ptr<Mdp::StateSpace> stateSpace{nullptr};
16  /*some stuff cannot be done in SetUp()*/
17  void generateStateSpace();
18  void SetUp() override;
19  void TearDown() override;
20 };
21 
23 {
24  dim1 = new Dimension;
25  dim2 = new Dimension;
26  dim3 = new Dimension;
27  prio1 = new Prio;
28  prio2 = new Prio;
29  std::cout << "DONE\n";
30  std::cerr << "Done";
31 }
32 
34 {
35  /*dimensions are freed elsewere*/
36 }
37 
38 
40 {
41  Mdp::StateSpaceBuilder builder;
42  builder.setDomainModel(std::make_shared<TestDomainModel>());
43  builder.addPriorityState(prio1);
44  builder.addPriorityState(prio2);
45  builder.addDimension(dim1);
46  builder.addDimension(dim2);
47  builder.addDimension(dim3);
48  stateSpace = builder.getStateSpace();
49 }
50 
51 
52 
54 {
55  dim1->nbOfPositions = 3;
56  dim2->nbOfPositions = 7;
57  dim3->nbOfPositions = 1;
59  /* 23 = 3*7*1 + 2 priority states*/
60  EXPECT_EQ(23u, stateSpace->size());
61 }
62 
63 
64 TEST_F(StateSpaceTest, testCurrentState)
65 {
66  dim1->nbOfPositions = 3;
67  dim1->position = 0;
68  dim2->nbOfPositions = 7;
69  dim2->position = 0;
70  dim3->nbOfPositions = 1;
72  stateSpace->updateCurrentState();
73  EXPECT_EQ((Mdp::state_t) 0, stateSpace->getState());
74 
75  dim1->nbOfPositions = 3;
76  dim1->position = 2;
77  dim2->nbOfPositions = 7;
78  dim2->position = 4;
79  dim3->nbOfPositions = 1;
80  stateSpace->updateCurrentState();
81  /* 2*1 + 4*(3) + 0*(3*7) = 14 */
82  EXPECT_EQ((Mdp::state_t) 14, stateSpace->getState());
83 
84  dim1->nbOfPositions = 3;
85  dim1->position = 0;
86  dim2->nbOfPositions = 7;
87  dim2->position = 5;
88  dim3->nbOfPositions = 3;
89  dim3->position = 1;
90  stateSpace->updateCurrentState();
91  /* 0*1 + 5*(3) + 1*(3*7)= 19 */
92  EXPECT_EQ((Mdp::state_t) 36, stateSpace->getState());
93 }
94 
95 
96 TEST_F(StateSpaceTest, testCurrentPriorityState)
97 {
98  dim1->nbOfPositions = 3;
99  dim1->position = 0;
100  dim2->nbOfPositions = 7;
101  dim2->position = 5;
102  dim3->nbOfPositions = 3;
103  dim3->position = 1;
104  prio1->inState = true;
106  stateSpace->updateCurrentState();
107  EXPECT_EQ((Mdp::state_t) 63, stateSpace->getState());
108 
109  prio1->inState = false;
110  prio2->inState = true;
111  stateSpace->updateCurrentState();
112  EXPECT_EQ((Mdp::state_t) 64, stateSpace->getState());
113 
114  prio1->inState = true;
115  prio1->inState = true;
116  stateSpace->updateCurrentState();
117  /*The first priority state added has priority over other priority states*/
118  EXPECT_EQ((Mdp::state_t) 63, stateSpace->getState());
119 }
120 
121 
122 TEST_F(StateSpaceTest, testGetReward)
123 {
125  double reward = stateSpace->getReward();
126  EXPECT_DOUBLE_EQ(expectedReward, reward);
127 }
128 
129 
130 
131 
132 
133 
134 
135 
void setDomainModel(std::shared_ptr< DomainModel > model)
sets the domain model used by the state space to determine current state
Dimension * dim2
std::shared_ptr< StateSpace > getStateSpace()
call this function last!
TEST_F(StateSpaceTest, testSize)
Prio * prio2
void addDimension(StateSpaceDimension *dimension)
adds a dimension to the state space
size_t nbOfPositions
bool inState
Mdp::statePosition_t position
Prio * prio1
double expectedReward
void addPriorityState(PriorityState *)
adds single states to the state space
Dimension * dim3
void TearDown() override
void SetUp() override
size_t state_t
Definition: state.h:19
Definition: reward.py:1
std::shared_ptr< Mdp::StateSpace > stateSpace
Dimension * dim1
void generateStateSpace()
builds a domain specific state space