Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <algorithm>
#include <vector>
#include <gtest/gtest.h>
class ExampleClass : public testing::Test {
protected:
virtual void SetUp() {
numbers.push_back(1);
numbers.push_back(2);
numbers.push_back(3);
}
virtual void TearDown() {
// Just for for fun
numbers.clear();
}
std::vector<int> numbers;
};
TEST_F(ExampleClass, Size) {
EXPECT_EQ(3, numbers.size());
numbers.push_back(4);
EXPECT_EQ(4, numbers.size());
numbers.clear();
EXPECT_EQ(0, numbers.size());
}
TEST_F(ExampleClass, Swap) {
EXPECT_EQ(2, numbers[1]);
EXPECT_EQ(3, numbers[2]);
std::swap(numbers[1], numbers[2]);
EXPECT_EQ(3, numbers[1]);
EXPECT_EQ(2, numbers[2]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment