Skip to content
Snippets Groups Projects
Commit b491385d authored by Oliver Heidmann's avatar Oliver Heidmann Committed by Uwe Schulzweida
Browse files

removed old tests for old function, added new rudimentary tests for string_to_number

parent 584ea9d5
No related branches found
No related tags found
2 merge requests!326convert_to_number not called string_to_number, fixed usage of .fail enabling...,!322Fixing and cleaning up handling of operator argument sourrounding the use of scientific notations
...@@ -13,57 +13,6 @@ cdoExit() ...@@ -13,57 +13,6 @@ cdoExit()
} }
go_bandit([]() { go_bandit([]() {
//============================================================================== //==============================================================================
bandit::describe("Testing function 'tokenize_comma_seperated_int_list'", []() {
bandit::describe("Testing tokenization with proper input", []() {
std::string to_be_tokenized{ "1,-2.0,1.0e3,-4.5e-2,0,0.0e043" };
std::vector<float> expected_tokens = { 1, -2.0, 1000.0, -0.045,0,0.0 };
std::pair<bool, std::vector<float>> result = tokenize_comma_seperated_number_list<float>(to_be_tokenized);
bandit::it("returns true on success", [&]() { AssertThat(std::get<0>(result), Equals(true)); });
bandit::it("returns the right tokens", [&]() { AssertThat(std::get<1>(result), EqualsContainer(expected_tokens)); });
});
bandit::describe("Testing tokenization with proper input", []() {
std::string to_be_tokenized{ "1,-2.0,1.0e3,-4.5e-2" };
std::vector<double> expected_tokens = { 1, -2.0, 1000.0, -0.045 };
std::pair<bool, std::vector<double>> result = tokenize_comma_seperated_number_list<double>(to_be_tokenized);
bandit::it("returns true on success", [&]() { AssertThat(std::get<0>(result), Equals(true)); });
bandit::it("returns the right tokens", [&]() { AssertThat(std::get<1>(result), EqualsContainer(expected_tokens)); });
});
});
bandit::describe("Testing function 'tokenize_comma_seperated_int_list'", []() {
bandit::describe("Testing tokenization with proper input", []() {
std::string to_be_tokenized{ "1,-2,3,4" };
std::vector<std::string> expected_tokens = { "1", "-2", "3", "4" };
std::tuple<bool, std::vector<std::string>> result = tokenize_comma_seperated_int_list(to_be_tokenized);
bandit::it("returns true on success", [&]() { AssertThat(std::get<0>(result), Equals(true)); });
bandit::it("returns the right tokens", [&]() { AssertThat(std::get<1>(result), EqualsContainer(expected_tokens)); });
});
bandit::describe("Testing tokenization with input containing non int", []() {
std::vector<std::string> expected_tokens = {};
std::string to_be_tokenized{ "1,a,3,4" };
std::tuple<bool, std::vector<std::string>> result = tokenize_comma_seperated_int_list(to_be_tokenized);
bandit::it("returns false on failure", [&]() { AssertThat(std::get<0>(result), Equals(false)); });
bandit::it("returns a empty list", [&]() { AssertThat(std::get<1>(result), EqualsContainer(expected_tokens)); });
});
bandit::describe("Testing tokenization with input containing a float value", []() {
std::vector<std::string> expected_tokens = {};
std::string to_be_tokenized{ "1,1.2,3" };
std::tuple<bool, std::vector<std::string>> result = tokenize_comma_seperated_int_list(to_be_tokenized);
bandit::it("returns false", [&]() { AssertThat(std::get<0>(result), Equals(false)); });
bandit::it("returns empty list", [&]() { AssertThat(std::get<1>(result), EqualsContainer(expected_tokens)); });
});
bandit::describe("Testing tokenization with input containing a single value", []() {
std::vector<std::string> expected_tokens = { "1" };
std::string to_be_tokenized{ "1" };
std::tuple<bool, std::vector<std::string>> result = tokenize_comma_seperated_int_list(to_be_tokenized);
bandit::it("returns true", [&]() { AssertThat(std::get<0>(result), Equals(true)); });
bandit::it("returns the token '1'", [&]() { AssertThat(std::get<1>(result), EqualsContainer(expected_tokens)); });
});
});
bandit::describe("Testing trim functions", []() { bandit::describe("Testing trim functions", []() {
bandit::describe("Testing ltrim function", []() { bandit::describe("Testing ltrim function", []() {
std::string to_be_trimmed = " spaces in front "; std::string to_be_trimmed = " spaces in front ";
...@@ -74,6 +23,36 @@ go_bandit([]() { ...@@ -74,6 +23,36 @@ go_bandit([]() {
}); });
}); });
}); });
bandit::describe("Testing string_to_number", []() {
bandit::describe("Testing float", []() {
std::string test_str = "0.02";
float expected = 0.02;
bandit::it("correctly converts", [&]() {
auto [success, result] = string_to_number<float>(test_str);
AssertThat(success, Equals(true));
AssertThat(result, Equals(expected));
});
});
bandit::describe("Testing int", []() {
std::string test_str = "2";
int expected = 2;
bandit::it("correctly converts", [&]() {
auto [success, result] = string_to_number<int>(test_str);
AssertThat(success, Equals(true));
AssertThat(result, Equals(expected));
});
});
bandit::describe("Testing double", []() {
std::string test_str = "0.02";
double expected = 0.02;
bandit::it("correctly converts", [&]() {
auto [success, result] = string_to_number<double>(test_str);
AssertThat(success, Equals(true));
AssertThat(result, Equals(expected));
});
});
});
bandit::describe("Testing rtrim function", []() { bandit::describe("Testing rtrim function", []() {
std::string to_be_trimmed = " spaces in back "; std::string to_be_trimmed = " spaces in back ";
std::string expected = " spaces in back"; std::string expected = " spaces in back";
......
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