Compare commits
No commits in common. "5567a9910b6dca50378c9f6424b3dd8cc93a94c3" and "f51d403b8e0036abf8050f969d002737d74d13e0" have entirely different histories.
5567a9910b
...
f51d403b8e
5 changed files with 23 additions and 36 deletions
|
@ -39,7 +39,7 @@ endif()
|
||||||
|
|
||||||
add_executable(compte_mots compte_mots.cpp)
|
add_executable(compte_mots compte_mots.cpp)
|
||||||
|
|
||||||
add_executable(parseXML xmlParser.cpp xmlParser.h Circle.h Circle.cpp)
|
add_executable(parseXML xmlParser.cpp xmlParser.h Circle.h)
|
||||||
|
|
||||||
find_path(PugiXML_INCLUDE_DIR pugixml.hpp)
|
find_path(PugiXML_INCLUDE_DIR pugixml.hpp)
|
||||||
target_link_libraries(parseXML pugixml)
|
target_link_libraries(parseXML pugixml)
|
||||||
|
@ -48,7 +48,7 @@ target_link_directories(parseXML PRIVATE ${PugiXML_INCLUDE_DIR})
|
||||||
|
|
||||||
|
|
||||||
if(GTest_FOUND)
|
if(GTest_FOUND)
|
||||||
add_executable(xmlTest gTestXMLParser.cpp Circle.h xmlParser.h xmlParser.cpp Circle.cpp)
|
add_executable(xmlTest gTestXMLParser.cpp Circle.h xmlParser.h xmlParser.cpp)
|
||||||
|
|
||||||
target_include_directories(xmlTest PRIVATE ${PugiXML_INCLUDE_DIR})
|
target_include_directories(xmlTest PRIVATE ${PugiXML_INCLUDE_DIR})
|
||||||
target_link_directories(xmlTest PRIVATE ${PugiXML_INCLUDE_DIR})
|
target_link_directories(xmlTest PRIVATE ${PugiXML_INCLUDE_DIR})
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
//
|
|
||||||
// Created by trotfunky on 14/05/19.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Circle.h"
|
|
||||||
|
|
||||||
namespace xmlParser
|
|
||||||
{
|
|
||||||
Circle::Circle() : x(0), y(1), r(2), label("Test circle")
|
|
||||||
{}
|
|
||||||
|
|
||||||
Circle::Circle(pugi::xml_node& node) : x(node.attribute("x").as_int(0)), y(node.attribute("y").as_int(1)),
|
|
||||||
r(node.attribute("r").as_int(2)), label(node.attribute("label").as_string("Test circle"))
|
|
||||||
{}
|
|
||||||
}
|
|
|
@ -10,17 +10,22 @@
|
||||||
|
|
||||||
namespace xmlParser
|
namespace xmlParser
|
||||||
{
|
{
|
||||||
class Circle
|
typedef struct Circle
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
Circle();
|
|
||||||
explicit Circle(pugi::xml_node&);
|
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
std::string label;
|
std::string label;
|
||||||
};
|
|
||||||
|
void initCirle() { x = 0; y = 1; r = 2; label = "Test circle";}
|
||||||
|
void initCircle(pugi::xml_node node)
|
||||||
|
{
|
||||||
|
x = node.attribute("x").as_int(0);
|
||||||
|
y = node.attribute("y").as_int(1);
|
||||||
|
r = node.attribute("r").as_int(2);
|
||||||
|
label = node.attribute("label").as_string("Test circle");
|
||||||
|
}
|
||||||
|
} Circle;
|
||||||
}
|
}
|
||||||
#endif //SNIPPETS_CIRCLE_H
|
#endif //SNIPPETS_CIRCLE_H
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
bool equals(const Polynomial<T1>&) const;
|
bool equals(const Polynomial<T1>&) const;
|
||||||
|
|
||||||
template <typename T1>
|
template <typename T1>
|
||||||
auto add(const Polynomial<T1>& operand) const -> Polynomial<decltype(T{} + T1{})>;
|
auto add(const Polynomial<T1>& operand) const -> Polynomial<decltype(static_cast<T>(0) + operand[0])>;
|
||||||
|
|
||||||
template <typename T1>
|
template <typename T1>
|
||||||
friend std::ostream& operator<<(std::ostream&, const Polynomial<T1>&);
|
friend std::ostream& operator<<(std::ostream&, const Polynomial<T1>&);
|
||||||
|
@ -62,7 +62,6 @@ private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Polynomial<T>::Polynomial()
|
Polynomial<T>::Polynomial()
|
||||||
{
|
{
|
||||||
// Not bad, but could be better with C++20. Not that useful either
|
|
||||||
static_assert(std::is_arithmetic<T>::value,"Polynomial must be of an arithmetic type!");
|
static_assert(std::is_arithmetic<T>::value,"Polynomial must be of an arithmetic type!");
|
||||||
factors = {0};
|
factors = {0};
|
||||||
}
|
}
|
||||||
|
@ -198,7 +197,7 @@ bool Polynomial<T>::equals(const Polynomial<T1>& operand) const
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
template<typename T1>
|
template<typename T1>
|
||||||
auto Polynomial<T>::add(const Polynomial<T1>& operand) const -> Polynomial<decltype(T{} + T1{})>
|
auto Polynomial<T>::add(const Polynomial<T1>& operand) const -> Polynomial<decltype(static_cast<T>(0) + operand[0])>
|
||||||
{
|
{
|
||||||
bool isLargest = true;
|
bool isLargest = true;
|
||||||
|
|
||||||
|
@ -213,7 +212,7 @@ auto Polynomial<T>::add(const Polynomial<T1>& operand) const -> Polynomial<declt
|
||||||
largestSize = operand.factors.size();
|
largestSize = operand.factors.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<decltype(T{} + T1{})> resultPolynomial = {};
|
std::vector<decltype(static_cast<T>(0)+operand[0])> resultPolynomial = {};
|
||||||
resultPolynomial.reserve(largestSize);
|
resultPolynomial.reserve(largestSize);
|
||||||
|
|
||||||
for(int i = 0;i<smallestSize;i++)
|
for(int i = 0;i<smallestSize;i++)
|
||||||
|
@ -226,7 +225,7 @@ auto Polynomial<T>::add(const Polynomial<T1>& operand) const -> Polynomial<declt
|
||||||
resultPolynomial.push_back((isLargest ? factors[i] : operand[i]));
|
resultPolynomial.push_back((isLargest ? factors[i] : operand[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Polynomial<decltype(T{} + T1{})>(resultPolynomial);
|
return Polynomial<decltype(static_cast<T>(0)+operand[0])>(resultPolynomial);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////
|
////////////////////
|
||||||
|
|
|
@ -9,7 +9,8 @@
|
||||||
|
|
||||||
TEST(readXML,initEmptyCircle)
|
TEST(readXML,initEmptyCircle)
|
||||||
{
|
{
|
||||||
xmlParser::Circle cercle = xmlParser::Circle();
|
xmlParser::Circle cercle;
|
||||||
|
cercle.initCirle();
|
||||||
|
|
||||||
ASSERT_EQ(cercle.x,0);
|
ASSERT_EQ(cercle.x,0);
|
||||||
ASSERT_EQ(cercle.y,1);
|
ASSERT_EQ(cercle.y,1);
|
||||||
|
@ -19,8 +20,9 @@ TEST(readXML,initEmptyCircle)
|
||||||
|
|
||||||
TEST(readXML,initEmptyCirclePugiXML)
|
TEST(readXML,initEmptyCirclePugiXML)
|
||||||
{
|
{
|
||||||
xmlParser::Circle cercle = xmlParser::Circle();
|
xmlParser::Circle cercle;
|
||||||
pugi::xml_node node;
|
pugi::xml_node node;
|
||||||
|
cercle.initCircle(node);
|
||||||
|
|
||||||
ASSERT_EQ(cercle.x,0);
|
ASSERT_EQ(cercle.x,0);
|
||||||
ASSERT_EQ(cercle.y,1);
|
ASSERT_EQ(cercle.y,1);
|
||||||
|
@ -37,13 +39,9 @@ TEST(readXML,parseXMLCircle)
|
||||||
pugi::xml_parse_result result = doc.load_string(xml.c_str());
|
pugi::xml_parse_result result = doc.load_string(xml.c_str());
|
||||||
EXPECT_NE(0,result);
|
EXPECT_NE(0,result);
|
||||||
|
|
||||||
pugi::xml_node node = doc.child("Circle");
|
xmlParser::Circle cercle;
|
||||||
xmlParser::Circle cercle = xmlParser::Circle(node);
|
|
||||||
|
|
||||||
ASSERT_EQ(cercle.x,0);
|
cercle.initCircle(doc.child("Circle"));
|
||||||
ASSERT_EQ(cercle.y,1);
|
|
||||||
ASSERT_EQ(cercle.r,2);
|
|
||||||
ASSERT_EQ(cercle.label,"testCircle");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue