bool ApplicationVersion::operator== (ApplicationVersion other) { if (GetComponents().size() != other.GetComponents().size()) return false; for (unsigned int i = 0; i < GetComponents().size(); i++) { if (GetComponents().at(i) != other.GetComponents().at(i)) return false; } return true; }
bool ApplicationVersion::operator > (ApplicationVersion other) { if (GetComponents().size() != other.GetComponents().size()) { return _majorDiferentSizes(other); } for (unsigned int i = 0; i < GetComponents().size(); i++) { if (GetComponents().at(i) == other.GetComponents().at(i)) continue; return GetComponents().at(i) > other.GetComponents().at(i); } return false; }
// If version A is 10.0.2 and B 10.2 compare starting by the left only the MIN of both // If both the MIN number of the digits are equal, return as major the one with more digits bool ApplicationVersion::_majorDiferentSizes (ApplicationVersion other) { unsigned int size; size = GetComponents().size() < other.GetComponents().size() ? GetComponents().size() : other.GetComponents().size(); for (unsigned int i = 0; i < size; i++) { if (GetComponents().at(i) == other.GetComponents().at(i)) continue; return GetComponents().at(i) > other.GetComponents().at(i); } return GetComponents().size() > other.GetComponents().size(); }
TEST(VersionTest, GetComponents_UnBreakable) { ApplicationVersion version (L"123"); vector <int> components; components = version.GetComponents(); EXPECT_THAT(components.size(), 1); EXPECT_THAT(components[0], 123); }
TEST(VersionTest, GetComponents_Two) { ApplicationVersion version (L"1.2"); vector <int> components; components = version.GetComponents(); EXPECT_THAT(components.size(), 2); EXPECT_THAT(components[0], 1); EXPECT_THAT(components[1], 2); }