@@ -109,17 +109,31 @@ class UnitTestHelper
109
109
}
110
110
111
111
template <typename T>
112
- vector<T> NormalizeCycle ( vector<T> data )
112
+ bool NormalizeCyclesAnCompare ( vector<T> data1, vector<T> data2 )
113
113
{
114
- if (data. empty ())
114
+ if (data1. size () != data2. size ())
115
115
{
116
- return {} ;
116
+ return false ;
117
117
}
118
- auto minimumElementIterator = min_element (data.begin (), data.end ());
119
- long long startIndex = distance (data.begin (), minimumElementIterator);
120
- vector<T> normalizedCycle;
121
- normalizedCycle.insert (normalizedCycle.end (), data.begin () + startIndex, data.end ());
122
- normalizedCycle.insert (normalizedCycle.end (), data.begin (), data.begin () + startIndex);
123
- return normalizedCycle;
118
+
119
+ // Normalized rotation of cycle 1
120
+ vector<T> normalizedCycle1 (data1);
121
+ auto minIterator1 = min_element (normalizedCycle1.begin (), normalizedCycle1.end ());
122
+ rotate (normalizedCycle1.begin (), minIterator1, normalizedCycle1.end ());
123
+
124
+ // Normalized rotation of cycle 2
125
+ vector<T> normalizedCycle2 (data2);
126
+ auto minIterator2 = min_element (normalizedCycle2.begin (), normalizedCycle2.end ());
127
+ rotate (normalizedCycle2.begin (), minIterator2, normalizedCycle2.end ());
128
+
129
+ // Check clock wise
130
+ if (normalizedCycle1 == normalizedCycle2)
131
+ {
132
+ return true ;
133
+ }
134
+
135
+ // Check counter clock wise
136
+ reverse (normalizedCycle2.begin () + 1 , normalizedCycle2.end ());
137
+ return (normalizedCycle1 == normalizedCycle2);
124
138
}
125
139
};
0 commit comments