Skip to content

Commit fe61782

Browse files
committed
Adding test code for String::toFloat
1 parent b76e0af commit fe61782

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ set(TEST_SRCS
4646
src/String/test_length.cpp
4747
src/String/test_replace.cpp
4848
src/String/test_String.cpp
49+
src/String/test_toFloat.cpp
4950
src/String/test_toInt.cpp
5051
src/String/test_toLowerCase.cpp
5152
src/String/test_toUpperCase.cpp

test/src/String/test_toFloat.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <String.h>
12+
13+
/**************************************************************************************
14+
* TEST CODE
15+
**************************************************************************************/
16+
17+
TEST_CASE ("Testing String::toFloat when string is empty", "[String-toFloat-01]")
18+
{
19+
arduino::String str;
20+
float const val = str.toFloat();
21+
REQUIRE(val == 0.0f);
22+
}
23+
24+
TEST_CASE ("Testing String::toFloat when string contains no number", "[String-toFloat-02]")
25+
{
26+
arduino::String str("abc");
27+
float const val = str.toFloat();
28+
REQUIRE(val == 0.0f);
29+
}
30+
31+
TEST_CASE ("Testing String::toFloat when string contains a number", "[String-toFloat-03]")
32+
{
33+
arduino::String str("-1.2345");
34+
float const val = str.toFloat();
35+
REQUIRE(val == -1.2345f);
36+
}

0 commit comments

Comments
 (0)