mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(string): add SStrToFloat
This commit is contained in:
parent
3d59699e1b
commit
28d60b4c4a
3 changed files with 203 additions and 0 deletions
|
|
@ -218,6 +218,68 @@ TEST_CASE("SStrStr", "[string]") {
|
|||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SStrToFloat", "[string]") {
|
||||
SECTION("converts empty string to float") {
|
||||
auto string = "";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == 0.0f);
|
||||
}
|
||||
|
||||
SECTION("converts whitespace string to float") {
|
||||
auto string = " ";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == 0.0f);
|
||||
}
|
||||
|
||||
SECTION("converts string with positive int to float") {
|
||||
auto string = "123";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == 123.0f);
|
||||
}
|
||||
|
||||
SECTION("converts string with negative int to float") {
|
||||
auto string = "-123";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == -123.0f);
|
||||
}
|
||||
|
||||
SECTION("converts string with positive float to float") {
|
||||
auto string = "1.5";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == 1.5f);
|
||||
}
|
||||
|
||||
SECTION("converts string with negative float to float") {
|
||||
auto string = "-1.5";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == -1.5f);
|
||||
}
|
||||
|
||||
SECTION("converts string with float and positive exponent to float") {
|
||||
auto string = "1.5e3";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == 1500.0f);
|
||||
}
|
||||
|
||||
SECTION("converts string with float and negative exponent to float") {
|
||||
auto string = "1500.0e-3";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == 1.5f);
|
||||
}
|
||||
|
||||
SECTION("converts string with zero to float") {
|
||||
auto string = "0";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == 0.0f);
|
||||
}
|
||||
|
||||
SECTION("converts string with leading zero to float") {
|
||||
auto string = "01";
|
||||
auto result = SStrToFloat(string);
|
||||
REQUIRE(result == 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("SStrToInt", "[string]") {
|
||||
SECTION("converts empty string to int") {
|
||||
auto string = "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue