improved tests

This commit is contained in:
Gabriel Schlozer 2016-05-15 11:36:47 +02:00
parent 1a1e041a92
commit 2bfb49d05b

View file

@ -1,115 +1,97 @@
#include "UnitTest++/UnitTest++.h"
#include <string>
#include "UnitTest++/ParameterizedTest.h"
using namespace std;
using namespace UnitTest;
static int simpleValuesSum = 0;
static int valuesSum = 0;
static int iterationsSum = 0;
static int ignoredCounter = 0;
static int otherParameterizedTestSum = 0;
static int singleValueSuiteSum = 0;
SUITE(ParameterizedTestSimpl)
SUITE(ParameterizedTestSimple)
{
SET_SUITE_PARAMETERS(int, iVal, {
parameters.push_back(10);
parameters.push_back(20);
parameters.push_back(30);
parameters.push_back(40);
})
string simpleVowels;
int simpleVowelsHitCount = 0;
TEST(SimpleSum)
SET_SUITE_PARAMETERS(string, vowel, {
parameters.push_back("A");
parameters.push_back("E");
parameters.push_back("I");
parameters.push_back("O");
parameters.push_back("U");
parameters.push_back("Y");
});
TEST(SimpleVoyelConcat)
{
simpleValuesSum += iVal();
}
}
SUITE(ParameterizedTest)
{
TEST(TestsOfBelowAreIgnored)
{
ignoredCounter++;
CHECK_EQUAL(1, ignoredCounter);
simpleVowels += vowel();
simpleVowelsHitCount++;
}
SET_SUITE_PARAMETERS(int, parameterized, {
parameters.push_back(1);
parameters.push_back(2);
parameters.push_back(3);
parameters.push_back(4);
})
size_t lastIteration = -1;
int lastValue = 0;
TEST(IterationsAreFollowing)
TEST(SimpleVoyelConcat_Verify)
{
CHECK_EQUAL(lastIteration + 1, parameterized.getIteration());
lastIteration = parameterized.getIteration();
iterationsSum++;
CHECK_EQUAL(parameterizedCreatorvowelInstance.parameters.size(), simpleVowelsHitCount);
CHECK_EQUAL("AEIOUY", simpleVowels);
}
TEST(ValuesAreFollowing)
//////////
int hitCountNonParameterized = 0;
TEST(NonParameterizedExecutedOnce)
{
CHECK_EQUAL(lastValue + 1, parameterized());
lastValue = parameterized();
valuesSum += parameterized();
hitCountNonParameterized++;
CHECK_EQUAL(1, hitCountNonParameterized);
}
TEST(ValueAndIterationAreSync)
{
CHECK_EQUAL(parameterized.getIteration() + 1, parameterized());
}
//////////
bool enteredEmpty = false;
int hitCountEmpty = 0;
SET_SUITE_PARAMETERS(int, parameterized2, {
parameters.push_back(1000);
parameters.push_back(2000);
})
TEST(OtherPSIgnoredFromFirstPS)
{
otherParameterizedTestSum += parameterized2();
}
}
SUITE(ParameterizedTest_LessValues)
{
SET_SUITE_PARAMETERS(int, parameterizedEmpty, {
})
});
TEST(WhenNoValue_throwsException)
TEST(WhenNoParameters_throwsException)
{
CHECK_THROW(parameterizedEmpty(), runtime_error);
enteredEmpty = true;
try
{
parameterizedEmpty();
}
catch(runtime_error e) // Expected case
{
CHECK_EQUAL("No values for parameterized test", e.what());
return;
}
CHECK(false);
hitCountEmpty++;
}
TEST(WhenNoParameters_throwsException_Verify)
{
CHECK_EQUAL(0, hitCountEmpty);
CHECK(enteredEmpty);
}
//////////
int hitCountSingle = 0;
static int singleValueSuiteSum = 0;
SET_SUITE_PARAMETERS(int, parameterizedSingle, {
parameters.push_back(2);
})
});
TEST(WhenSingleValue_singleExecution)
{
singleValueSuiteSum += parameterizedSingle();
CHECK_EQUAL(2, singleValueSuiteSum);
hitCountSingle++;
}
}
SUITE(ParameterizedTest_Validation)
{
TEST(ParameterizedTest_HasBeenIterated)
TEST(WhenSingleValue_singleExecution_Verification)
{
CHECK_EQUAL(100, simpleValuesSum);
CHECK_EQUAL(1, ignoredCounter);
CHECK_EQUAL(10, valuesSum);
CHECK_EQUAL(4, iterationsSum);
CHECK_EQUAL(3000, otherParameterizedTestSum);
CHECK_EQUAL(2, singleValueSuiteSum);
CHECK_EQUAL(1, hitCountSingle);
}
}