Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5c7276a

Browse files
committed
Adding test code for Stream::parseFloat(...)
1 parent52ddc44 commit5c7276a

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

‎test/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ set(TEST_SRCS
5050
src/Stream/test_find.cpp
5151
src/Stream/test_findUntil.cpp
5252
src/Stream/test_getTimeout.cpp
53+
src/Stream/test_parseFloat.cpp
5354
src/Stream/test_parseInt.cpp
5455
src/Stream/test_readString.cpp
5556
src/Stream/test_readStringUntil.cpp
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2020 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
* INCLUDE
7+
**************************************************************************************/
8+
9+
#include<catch.hpp>
10+
11+
#include<StreamMock.h>
12+
13+
/**************************************************************************************
14+
* TEST CODE
15+
**************************************************************************************/
16+
17+
TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR)","[Stream-parseFloat-01]")
18+
{
19+
StreamMock mock;
20+
21+
WHEN ("Only a integer (no comma) is contained in stream")
22+
{
23+
mock <<"12";
24+
REQUIRE(mock.parseFloat() ==12.0f);
25+
}
26+
WHEN ("A positive float is contained in stream")
27+
{
28+
mock <<"12.34";
29+
REQUIRE(mock.parseFloat() ==12.34f);
30+
}
31+
WHEN ("A negative float is contained in stream")
32+
{
33+
mock <<"-12.34";
34+
REQUIRE(mock.parseFloat() == -12.34f);
35+
}
36+
WHEN ("A float is prepended by digits")
37+
{
38+
mock <<"abcdef12.34";
39+
REQUIRE(mock.parseFloat() ==12.34f);
40+
}
41+
WHEN ("The integer is prepended by whitespace chars")
42+
{
43+
mock <<"\r\n\t 12.34";
44+
REQUIRE(mock.parseFloat() ==12.34f);
45+
}
46+
}
47+
48+
TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_NONE, char ignore = NO_IGNORE_CHAR)","[Stream-parseFloat-02]")
49+
{
50+
StreamMock mock;
51+
52+
WHEN ("Only a integer is contained in stream")
53+
{
54+
mock <<"12.34";
55+
REQUIRE(mock.parseFloat(SKIP_NONE) ==12.34f);
56+
REQUIRE(mock.readString() ==arduino::String(""));
57+
}
58+
WHEN ("The integer is prepended by digits")
59+
{
60+
mock <<"abcdef12.34";
61+
REQUIRE(mock.parseFloat(SKIP_NONE) ==0);
62+
REQUIRE(mock.readString() ==arduino::String("abcdef12.34"));
63+
}
64+
WHEN ("The integer is prepended by whitespace chars")
65+
{
66+
mock <<"\r\n\t 12.34";
67+
REQUIRE(mock.parseFloat(SKIP_NONE) ==0);
68+
REQUIRE(mock.readString() ==arduino::String("\r\n\t 12.34"));
69+
}
70+
}
71+
72+
TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_WHITESPACE, char ignore = NO_IGNORE_CHAR)","[Stream-parseFloat-03]")
73+
{
74+
StreamMock mock;
75+
76+
WHEN ("The integer is prepended by whitespace chars")
77+
{
78+
mock <<"\r\n\t 12.34";
79+
REQUIRE(mock.parseFloat(SKIP_WHITESPACE) ==12.34f);
80+
REQUIRE(mock.readString() ==arduino::String(""));
81+
}
82+
}
83+
84+
85+
TEST_CASE ("Testing parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = 'a')","[Stream-parseFloat-04]")
86+
{
87+
StreamMock mock;
88+
89+
WHEN ("A float is contained in stream")
90+
{
91+
mock <<"12.34";
92+
REQUIRE(mock.parseFloat(SKIP_ALL,'a') ==12.34f);
93+
REQUIRE(mock.readString() ==arduino::String(""));
94+
}
95+
WHEN ("The float contains only ignore char values")
96+
{
97+
mock <<"12a.3a4a";
98+
REQUIRE(mock.parseFloat(SKIP_ALL,'a') ==12.34f);
99+
REQUIRE(mock.readString() ==arduino::String(""));
100+
}
101+
WHEN ("The integer contains other than ignore chars")
102+
{
103+
mock <<"1bed234";
104+
REQUIRE(mock.parseFloat(SKIP_ALL,'a') ==1.0f);
105+
REQUIRE(mock.readString() ==arduino::String("bed234"));
106+
}
107+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp