Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 2175c70

Browse files
committed
Adding test code for cloud type 'Location'
1 parent 91e68bb commit 2175c70

File tree

2 files changed

+104
-1
lines changed

2 files changed

+104
-1
lines changed

test/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ set(TEST_SRCS
2424
src/main.cpp
2525
src/test_addPropertyReal.cpp
2626
src/test_callback.cpp
27+
src/test_CloudColor.cpp
28+
src/test_CloudLocation.cpp
2729
src/test_decode.cpp
2830
src/test_encode.cpp
2931
src/test_publishEvery.cpp
@@ -32,7 +34,6 @@ set(TEST_SRCS
3234
src/test_readOnly.cpp
3335
src/test_writeOnly.cpp
3436
src/TestUtil.cpp
35-
src/test_CloudColor.cpp
3637

3738
../src/ArduinoCloudThing.cpp
3839
../src/ArduinoCloudProperty.cpp

test/src/test_CloudLocation.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All rights reserved.
3+
*/
4+
5+
/**************************************************************************************
6+
INCLUDE
7+
**************************************************************************************/
8+
9+
#include <catch.hpp>
10+
11+
#include <ArduinoCloudThing.h>
12+
13+
/**************************************************************************************
14+
TEST CODE
15+
**************************************************************************************/
16+
17+
SCENARIO("Tesing cloud type 'Location' Ctor", "[Location::Location]") {
18+
WHEN("A Location(1.0f, 2.0f) is being instantiated") {
19+
Location loc(1.0f, 2.0f);
20+
THEN("The member variable 'lat' should be 1.0f") {
21+
REQUIRE(loc.lat == 1.0f);
22+
}
23+
THEN("The member variable 'lon' should be 2.0f") {
24+
REQUIRE(loc.lon == 2.0f);
25+
}
26+
}
27+
}
28+
29+
/**************************************************************************************/
30+
31+
SCENARIO("Tesing cloud type 'Location' assignment operator", "[Location::operator =]") {
32+
Location loc1(1.0f, 2.0f),
33+
loc2(3.0f, 4.0f);
34+
loc1 = loc2;
35+
WHEN("One location is assigned to the other") {
36+
THEN("The coordinates of the second location should be assigned to the first") {
37+
REQUIRE(loc1.lat == 3.0f);
38+
REQUIRE(loc1.lon == 4.0f);
39+
}
40+
}
41+
}
42+
43+
/**************************************************************************************/
44+
45+
SCENARIO("Tesing cloud type 'Location' operator -", "[Location::operator -]") {
46+
Location loc1(1.0f, 2.0f),
47+
loc2(3.0f, 4.0f);
48+
Location loc3 = loc1 - loc2;
49+
WHEN("One location is subtracted from the other") {
50+
THEN("The result should be calculated according the rule lon3 = lon1 - lon2, lat3 = lat1 - lat2") {
51+
REQUIRE(loc3.lat == loc1.lat - loc2.lat);
52+
REQUIRE(loc3.lon == loc1.lon - loc2.lon);
53+
}
54+
}
55+
}
56+
57+
/**************************************************************************************/
58+
59+
SCENARIO("Tesing cloud type 'Location' comparison operator ==", "[Location::operator ==]") {
60+
Location loc1(1.0f, 2.0f),
61+
loc2(3.0f, 4.0f),
62+
loc3(1.0f, 2.0f);
63+
WHEN("Two locations are identical (lat as well as lon)") {
64+
THEN("The comparison operation should return true") {
65+
REQUIRE((loc1 == loc3) == true);
66+
}
67+
}
68+
69+
WHEN("Two locations are not identical (either lat or lon do not match)") {
70+
THEN("The comparison operation should return false") {
71+
REQUIRE((loc1 == loc2) == false);
72+
}
73+
}
74+
}
75+
76+
/**************************************************************************************/
77+
78+
SCENARIO("Tesing cloud type 'Location' comparison operator !=", "[Location::operator !=]") {
79+
Location loc1(1.0f, 2.0f),
80+
loc2(3.0f, 4.0f),
81+
loc3(1.0f, 2.0f);
82+
WHEN("Two locations are identical (lat as well as lon)") {
83+
THEN("The comparison operation should return false") {
84+
REQUIRE((loc1 != loc3) == false);
85+
}
86+
}
87+
88+
WHEN("Two locations are not identical (either lat or lon do not match)") {
89+
THEN("The comparison operation should return true") {
90+
REQUIRE((loc1 != loc2) == true);
91+
}
92+
}
93+
}
94+
95+
/**************************************************************************************/
96+
97+
SCENARIO("Tesing cloud type 'Location' function distance for calculating euclidean 2d distance between two points", "[Location::distance]") {
98+
Location loc1(0.0f, 0.0f),
99+
loc2(1.0f, 1.0f);
100+
101+
REQUIRE(Location::distance(loc1, loc2) == sqrt(2.0f));
102+
}

0 commit comments

Comments
 (0)