Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $(APP): setup $(OBJS)
$(CXX) -o $(APP) $(OBJS) $(LDFLAGS)

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) -c $< $(CXX_FLAGS) $(TEST_CXX_FLAGS) $(INCLUDES) -o $@
$(CXX) -c $< $(CXX_FLAGS) $(TEST_CXX_FLAGS) $(INCLUDES) $(TEST_INCLUDES) -o $@

$(TEST_OBJ_DIR)/%.o: $(TEST_DIR)/%.cpp
$(CXX) -c $< $(CXX_FLAGS) $(TEST_CXX_FLAGS) $(INCLUDES) $(TEST_INCLUDES) -o $@
Expand Down
13 changes: 12 additions & 1 deletion src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include "Primos.h"
#include "SalvaCalculo.h"
#include <map>
#include <iostream>

using namespace std;

#ifdef WITH_UNIT_TEST
#include <gtest/gtest.h>
Expand All @@ -27,14 +30,22 @@ int main(int argc, char** argv) {
}
#else

using namespace std;

void imprimeCalculo(Calculo *calculo) {
printf("%s\n", calculo->nome().c_str());
printf("%s\t\t%s\n", "Indice", "Valor");
for (unsigned int i = 0; i < calculo->numeroResultados(); i++) {
printf("%d\t\t%d\n", i, calculo->resultado(i));
}
string with_sep = calculo->toString(';');
cout << endl;
cout <<"teste do separador com ;" << endl;
cout << with_sep << endl;

string with_sep2 = calculo->toString(',');
cout << endl;
cout <<"teste do separador com ," << endl;
cout << with_sep2 << endl;
}

/*
Expand Down
21 changes: 19 additions & 2 deletions src/Primos.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "Primos.h"
#include <math.h>
#include <iostream>
#include <string>
#include <stdio.h>


using namespace std;

Primos::Primos(int inicio, unsigned int tamanho, Interceptador *interceptador) : Calculo(inicio, tamanho, interceptador) {
this->resultados.reserve(tamanho);
Expand Down Expand Up @@ -38,8 +43,20 @@ int Primos::resultado(unsigned int indice) {
}

string Primos::toString(char sep){
// TODO: Implementar
return "";
string str;
string a;
unsigned int i = 0;
char s[2] = {sep, 0};
for(vector<int>::iterator it = this->resultados.begin(); it != this->resultados.end(); it++){
a = to_string(*it);
str.append(a);
if(i < (this->resultados.size() - 1)){
str.append(s);
}
i++;
}

return str;
}

void Primos::limpaCalculo() {
Expand Down
44 changes: 40 additions & 4 deletions test/TestPrimos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* and open the template in the editor.
*/
#include <gtest/gtest.h>
#include <hippomocks.h>

#include "Primos.h"

Expand All @@ -22,10 +23,26 @@ class TestPrimos : public ::testing::Test {

};

TEST_F(TestPrimos, Teste) {
EXPECT_TRUE(primos->resultado(0) == 0);
EXPECT_TRUE(primos->numeroResultados() == 0);
}
class TestPrimosInterceptador : public ::testing::Test {

protected:
Calculo* primos;
MockRepository *mocks;
Interceptador *interceptador;

virtual void SetUp( ) {
mocks = new MockRepository();
interceptador = mocks->Mock<Interceptador>();
primos = new Primos(0, 10, interceptador);
primos->calcula();
}

virtual void TearDown( ) {
mocks->OnCallDestructor(interceptador);
delete primos;
}

};


////////////////////
Expand All @@ -48,6 +65,11 @@ class TestPrimosInitialize : public ::testing::Test {

};

TEST_F(TestPrimos, Teste) {
EXPECT_TRUE(primos->resultado(0) == 0);
EXPECT_TRUE(primos->numeroResultados() == 0);
}

TEST_F(TestPrimosInitialize, TesteDeTamanho){
EXPECT_TRUE(primos->numeroResultados() == 10);
}
Expand All @@ -68,4 +90,18 @@ TEST_F(TestPrimosInitialize, TesteDeResultado){

TEST_F(TestPrimosInitialize, TesteDeNome) {
EXPECT_STREQ(primos->nome().c_str(), "Primos");
}

TEST_F(TestPrimosInitialize, TesteToString) {
EXPECT_STREQ(primos->toString(';').c_str(), "2;3;5;7;11;13;17;19;23;29");
EXPECT_STREQ(primos->toString(',').c_str(), "2,3,5,7,11,13,17,19,23,29");
}

TEST_F(TestPrimosInterceptador, TesteDeResultadoZero) {
mocks->ExpectCall(this->interceptador, Interceptador::intercepta).With(7).Return(15);
mocks->ExpectCall(this->interceptador, Interceptador::intercepta).With(11).Return(66);
mocks->ExpectCall(this->interceptador, Interceptador::intercepta).With(17).Return(44);
EXPECT_TRUE(primos->resultado(3) == 15);
EXPECT_FALSE(primos->resultado(4) == 99);
EXPECT_TRUE(primos->resultado(6) == 44);
}