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