Skip to content
Snippets Groups Projects
Commit 7188ac6d authored by Maxence Naud's avatar Maxence Naud
Browse files

Fix sascalToSnake() and snakeToPascal() static function to accept digits

Fix attributes names in cpp tests
parent 2b71cded
No related branches found
No related tags found
2 merge requests!152Update Aidge export to take a graph view has an argument instead of a...,!145Improve UI for Operator/Node/GraphView/Tensor
......@@ -11,7 +11,8 @@
#include "aidge/utils/Attributes.hpp"
#include <cctype> // std::islower, std::isupper, std::tolower, std::toupper
#include <cctype> // std::isdigit, std::islower, std::isupper, std::tolower,
// std::toupper
#include <string>
std::string Aidge::Attributes::snakeToPascal(const std::string& snakeCase) {
......@@ -64,7 +65,7 @@ bool Aidge::Attributes::isPascalCase(const std::string& str) {
return false;
}
expectUpper = false;
} else if (std::islower(str[i])) {
} else if (std::islower(str[i]) || std::isdigit(str[i])) {
expectUpper = true;
} else {
return false;
......@@ -85,7 +86,7 @@ bool Aidge::Attributes::isSnakeCase(const std::string& str) {
return false;
}
lastCharWasUnderscore = true;
} else if (!std::islower(ch)) {
} else if (!std::islower(ch) && !std::isdigit(ch)) {
return false;
} else {
lastCharWasUnderscore = false;
......
......@@ -20,7 +20,7 @@ using namespace Aidge;
TEST_CASE("[core/operators] GenericOp(add & get attributes)", "[Operator]") {
SECTION("INT") {
GenericOperator_Op Testop("TestOp", 1, 1, 1);
const char* key = "intAttr";
const char* key = "IntAttr";
Testop.addAttr(key, int(5));
int registeredVal = Testop.getAttr<int>(key);
REQUIRE(registeredVal == 5);
......@@ -28,21 +28,21 @@ TEST_CASE("[core/operators] GenericOp(add & get attributes)", "[Operator]") {
SECTION("LONG") {
GenericOperator_Op Testop("TestOp", 1, 1, 1);
long value = 3;
const char* key = "longAttr";
const char* key = "LongAttr";
Testop.addAttr(key, value);
REQUIRE(Testop.getAttr<long>(key) == value);
}
SECTION("FLOAT") {
GenericOperator_Op Testop("TestOp", 1, 1, 1);
float value = 2.0;
const char* key = "floatAttr";
const char* key = "FloatAttr";
Testop.addAttr(key, value);
REQUIRE(Testop.getAttr<float>(key) == value);
}
SECTION("VECTOR<BOOL>") {
GenericOperator_Op Testop("TestOp", 1, 1, 1);
std::vector<bool> value = {true, false, false, true, true};
const char* key = "vect";
const char* key = "Vect";
Testop.addAttr(key, value);
REQUIRE(Testop.getAttr<std::vector<bool>>(key).size() == value.size());
......@@ -53,7 +53,7 @@ TEST_CASE("[core/operators] GenericOp(add & get attributes)", "[Operator]") {
SECTION("VECTOR<INT>") {
GenericOperator_Op Testop("TestOp", 1, 1, 1);
std::vector<int> value = {1, 2, 3, 4, 5, 6, 7, 8, 9};
const char* key = "vect";
const char* key = "Vect";
Testop.addAttr(key, value);
REQUIRE(Testop.getAttr<std::vector<int>>(key).size() == value.size());
......@@ -66,23 +66,23 @@ TEST_CASE("[core/operators] GenericOp(add & get attributes)", "[Operator]") {
Goal : Test that the offsets are well done by adding different attributes with different size.
*/
GenericOperator_Op Testop("TestOp", 1, 1, 1);
Testop.addAttr<long>("longAttr", 3);
Testop.addAttr<float>("floatAttr", 2.0);
Testop.addAttr<uint8_t>("uint8Attr", 5);
Testop.addAttr<long long>("llAttr", 10);
REQUIRE(Testop.getAttr<long>("longAttr") == 3);
REQUIRE(Testop.getAttr<float>("floatAttr") == 2.0);
REQUIRE(Testop.getAttr<uint8_t>("uint8Attr") == 5);
REQUIRE(Testop.getAttr<long long>("llAttr") == 10);
Testop.addAttr<long>("LongAttr", 3);
Testop.addAttr<float>("FloatAttr", 2.0);
Testop.addAttr<uint8_t>("Uint8Attr", 5);
Testop.addAttr<long long>("LlAttr", 10);
REQUIRE(Testop.getAttr<long>("LongAttr") == 3);
REQUIRE(Testop.getAttr<float>("FloatAttr") == 2.0);
REQUIRE(Testop.getAttr<uint8_t>("Uint8Attr") == 5);
REQUIRE(Testop.getAttr<long long>("LlAttr") == 10);
}
}
TEST_CASE("[core/operator] GenericOp(type check)", "[Operator]") {
SECTION("WRONG TYPE FOR GETTER") {
GenericOperator_Op Testop("TestOp", 1, 1, 1);
Testop.addAttr<long>("longAttr", 3);
Testop.addAttr<long>("LongAttr", 3);
// This line should raise a failled assert
REQUIRE_THROWS(Testop.getAttr<int>("longAttribute"));
REQUIRE_THROWS(Testop.getAttr<int>("LongAttribute"));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment