filter_network_test.cpp 6.56 KB
Newer Older
Pascal Palenda's avatar
Pascal Palenda committed
1
#include <ITA/SimulationScheduler/AudibilityFilter/filter_network.h>
2
3
4
5
6
7
8

#include "mocks.hpp"

// GTest
#include <ostream>

#include "gtest/gtest.h"
Pascal Palenda's avatar
Pascal Palenda committed
9
10
#include "ITA/SimulationScheduler/AudibilityFilter/rotation_filter.h"
#include "ITA/SimulationScheduler/AudibilityFilter/zone_filter.h"
11
12


13
14
using namespace ITA::SimulationScheduler;
using namespace AudibilityFilter;
15
using namespace std;
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

struct FilterNetworkTestParam
{
	bool expectedResult;

	bool filter1audible;
	bool filter2audible;
	bool filter3audible;

	bool conditionFulfilled;

	bool invertCondition;

	bool addFilterThreeInSecondBranch;


32
	friend std::ostream& operator<<( std::ostream& os, const FilterNetworkTestParam& obj )
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	{
		return os
			<< boolalpha
			<< "expectedResult: " << obj.expectedResult
			<< " filter1audible: " << obj.filter1audible
			<< " filter2audible: " << obj.filter2audible
			<< " filter3audible: " << obj.filter3audible
			<< " conditionFulfilled: " << obj.conditionFulfilled
			<< " invertCondition: " << obj.invertCondition
			<< " addFilterThreeInSecondBranch: " << obj.addFilterThreeInSecondBranch;
	}
};

struct FilterNetworkTest : public testing::TestWithParam<FilterNetworkTestParam>
{
	std::unique_ptr<CFilterNetwork> filterNetwork;

	FilterNetworkTest ( )
	{
		const auto param = GetParam ( );

54
		CAudibilityFilterFactory::RegisterObject ( "MockFilter",
Pascal Palenda's avatar
Pascal Palenda committed
55
56
												   MockAudibilityFilter::createFilter,
												   std::make_shared<MockAudibilityFilter::MockFilterConfig> );
57
58

		const auto filter1 = std::make_shared<MockAudibilityFilter::MockFilterConfig> ( );
59
		filter1->behaviour = param.filter1audible ? MockAudibilityFilter::Behaviour::everythingAudible : MockAudibilityFilter::Behaviour::nothingAudible;
60
		const auto filter2 = std::make_shared<MockAudibilityFilter::MockFilterConfig> ( );
61
		filter2->behaviour = param.filter2audible ? MockAudibilityFilter::Behaviour::everythingAudible : MockAudibilityFilter::Behaviour::nothingAudible;
62
		const auto filter3 = std::make_shared<MockAudibilityFilter::MockFilterConfig> ( );
63
		filter3->behaviour = param.filter3audible ? MockAudibilityFilter::Behaviour::everythingAudible : MockAudibilityFilter::Behaviour::nothingAudible;
64
65

		const auto condition = std::make_shared<MockAudibilityFilter::MockFilterConfig> ( );
66
		condition->behaviour = param.conditionFulfilled ? MockAudibilityFilter::Behaviour::everythingAudible : MockAudibilityFilter::Behaviour::nothingAudible;
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

		filter1->sFilterName = "one";
		filter2->sFilterName = "two";
		filter3->sFilterName = "three";

		condition->sFilterName = "con";

		condition->eUsageMode = IAudibilityFilter::UsageMode::condition;
		condition->bInvertCondition = param.invertCondition;

		filter1->sNextFilter = { "con", "two" };

		if ( param.addFilterThreeInSecondBranch )
			filter2->sNextFilter = { "three" };

		condition->sNextFilter = { "three" };

		//
		//      /- con --  three
		// one -
		//      \- two -- (three)
		//

		CFilterNetwork::FilterNetworkConfig config;

		config.sStartFilter = "one";
		config.vpFilterConfigs = { filter1, filter2, filter3, condition };

		filterNetwork = std::make_unique <CFilterNetwork> ( config );
	}
};

TEST_P ( FilterNetworkTest, correctResult )
{
	const auto param = GetParam ( );

	const CUpdateScene update1 ( 0 );
	const CUpdateScene update2 ( 0 );

106
	EXPECT_EQ ( param.expectedResult, filterNetwork->EvaluateNetwork ( update1, update2 ) );
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
}

//                                                                                                       
//                                                                                                             /- con --  three
//                                                                                                        one -
//                                                                                                             \- two -- (three)
//                                                                                                       

//                                                                                                        result, f1   , f2   , f3   , con  , !con?, add f3
INSTANTIATE_TEST_CASE_P ( FilterNetworkTest, FilterNetworkTest, testing::Values ( FilterNetworkTestParam { false, false, false, false, true , false, false }, // 0
																				  FilterNetworkTestParam { true , true , false, false, true , false, false }, // 1
																				  FilterNetworkTestParam { true , false, true , false, true , false, false }, // 2
																				  FilterNetworkTestParam { true , false, false, true , true , false, false }, // 3
																				  FilterNetworkTestParam { false, false, false, true , false, false, false }, // 4
																				  FilterNetworkTestParam { false, false, false, true , true , true , false }, // 5
																				  FilterNetworkTestParam { true , false, false, true , false, true , false }, // 6
																				  FilterNetworkTestParam { true , false, false, true , false, false, true },  // 7
																				  FilterNetworkTestParam { true , false, false, true , true , false, true }   // 8
125
126
127
128
129
130
131
132
133
134
135
) );

TEST ( FilterNetworkTest, configCorrect )
{
	auto config = std::make_shared<CRotationFilter::RotationFilterConfig> ( );
	auto config1 = std::make_shared<CZoneFilter::ZoneFilterConfig> ( );

	config->sNextFilter = { "One", "Two" };

	config1->vpZones = { {VistaVector3D ( 1,2,3 ), VistaVector3D ( 4,5,6 )},{VistaVector3D ( 1,2,3 ), VistaVector3D ( 4,5,6 )} };

136
	AudibilityFilter::CFilterNetwork::FilterNetworkConfig networkConfig;
137
138
139
140
141

	networkConfig.vpFilterConfigs = { config, config1 };

	networkConfig.sStartFilter = "start";

142
	const auto configProperties = networkConfig.Store ( );
143
144
145

	CFilterNetwork::FilterNetworkConfig networkConfig1;

146
	networkConfig1.Load ( configProperties );
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

	EXPECT_EQ ( networkConfig.sStartFilter, networkConfig1.sStartFilter );
	EXPECT_EQ ( networkConfig.vpFilterConfigs.size ( ), networkConfig1.vpFilterConfigs.size ( ) );

	const auto newConfig = dynamic_pointer_cast< CRotationFilter::RotationFilterConfig >( networkConfig1.vpFilterConfigs [0] );
	const auto newConfig1 = dynamic_pointer_cast< CZoneFilter::ZoneFilterConfig >( networkConfig1.vpFilterConfigs [1] );

	EXPECT_NE ( nullptr, newConfig );
	EXPECT_NE ( nullptr, newConfig1 );

	EXPECT_EQ ( config->sNextFilter.size ( ), newConfig->sNextFilter.size ( ) );
	EXPECT_EQ ( config1->vpZones.size ( ), newConfig1->vpZones.size ( ) );

	for ( auto i = 0; i < config->sNextFilter.size ( ); ++i )
	{
		EXPECT_EQ ( config->sNextFilter.at ( i ), newConfig->sNextFilter.at ( i ) );
	}

	for ( auto i = 0; i < config1->vpZones.size ( ); ++i )
	{
		EXPECT_EQ ( config1->vpZones.at ( i ), newConfig1->vpZones.at ( i ) );
	}

	

}