2929#define kBoard_AnalogCount 16
3030#endif
3131
32+
3233// ************************************************************************
3334void setup ()
3435{
36+
3537 short ii;
3638 uint8_t timerNumber;
3739 char testName[64 ];
3840
39-
40-
4141 gYotalErrors = 0 ;
4242 gTestCount = 0 ;
4343
@@ -56,92 +56,136 @@ void setup()
5656 gTestStartTime = millis ();
5757 ATS_PrintTestStart (" Arduino" , " String Test" );
5858
59+
5960 /*
6061* Run the tests
6162 */
6263
6364 // adding a constant integer to a string:
6465 stringThree = stringOne + 123 ;
65- strcpy(charResult, " \0 " );
66+ // strcpy(charResult, "\0");
6667 stringThree. toCharArray(charResult, sizeof(charResult));
6768
68- strcpy(testName, " Adding a constant integer to a string:" );
69- if (strcmp(charResult," stringThree = 123" ) == 0 )
70- {
71- ATS_PrintTestStatus (testName, true );
72- }
73- else
74- {
75- ATS_PrintTestStatus (testName, false );
76- }
77-
78-
69+ ATS_PrintTestStatus (" 1. Adding a constant integer to a string:" , strcmp(charResult," stringThree = 123" ) == 0 );
7970
8071 // adding a constant long interger to a string:
8172 stringThree = stringOne + 123456789 ;
8273 stringThree. toCharArray(charResult, sizeof(charResult));
8374
84- strcpy(testName, " Adding a constant long interger to a string" );
85- if (strcmp(charResult," stringThree = 123456789" ) == 0 )
86- {
87- ATS_PrintTestStatus (testName, true );
88- }
89- else
90- {
91- ATS_PrintTestStatus (testName, false );
92- }
75+ ATS_PrintTestStatus (" 2. Adding a constant long interger to a string" , strcmp(charResult," stringThree = 123456789" ) == 0 );
9376
9477
9578 // adding a constant character to a string:
9679 stringThree = stringOne + ' A' ;
9780 stringThree. toCharArray(charResult, sizeof(charResult));
9881
99- strcpy(testName, " Adding a constant character to a string" );
100- if (strcmp(charResult," stringThree = A" ) == 0 )
101- {
102- ATS_PrintTestStatus (testName, true );
103- }
104- else
105- {
106- ATS_PrintTestStatus (testName, false );
107- }
108-
82+ ATS_PrintTestStatus (" 3. Adding a constant character to a string" , strcmp(charResult," stringThree = A" ) == 0 );
10983
11084
11185 // adding a constant string to a string:
11286 stringThree = stringOne + " abc" ;
11387 stringThree. toCharArray(charResult, sizeof(charResult));
11488
115- strcpy(testName, " Adding a constant string variable to a string" );
116- if (strcmp(charResult," stringThree = abc" ) == 0 )
117- {
118- ATS_PrintTestStatus (testName, true );
119- }
120- else
121- {
122- ATS_PrintTestStatus (testName, false );
123- }
89+ ATS_PrintTestStatus (" 4. Adding a constant string variable to a string" , strcmp(charResult," stringThree = abc" ) == 0 );
12490
91+ // "5. Adding a constant long interger to a string"
12592 stringThree = stringOne + stringTwo;
12693 stringThree. toCharArray(charResult, sizeof(charResult));
12794
128- strcpy(testName, " Adding a constant long interger to a string" );
129- if (strcmp(charResult," stringThree = this string" ) == 0 )
130- {
131- ATS_PrintTestStatus (testName, true );
132- }
133- else
134- {
135- ATS_PrintTestStatus (testName, false );
136- }
95+ ATS_PrintTestStatus (" 5. Adding a constant long interger to a string" , strcmp(charResult," stringThree = this string" ) == 0 );
96+
97+
98+ /*
99+ * setup up String Comparison Operater Tests
100+ */
101+
102+ stringOne = String (" this" );
103+ stringTwo = String (" that" );
104+
105+ // two strings equal:
106+ ATS_PrintTestStatus (" 6. Two strings equal" ,stringOne == " this" );
107+
108+ // two strings not equal:
109+ ATS_PrintTestStatus (" 7. Two strings not equal" ,stringOne != stringTwo);
110+
111+ // two strings not equal (case sensitivity matters):
112+ stringOne = " This" ;
113+ stringTwo = " this" ;
114+ ATS_PrintTestStatus (" 8. Two strings not equal [case sensitivity matters]" , stringOne != stringTwo);
115+
116+ // you can also use equals() to see if two strings are the same:
117+ stringOne = " this" ;
118+ stringTwo = " this" ;
119+ ATS_PrintTestStatus (" 9. Equals() method equals" , stringOne. equals(stringTwo));
120+
121+
122+ // you can also use not equals() to see if two strings are not the same:
123+ stringOne = String (" This" );
124+ stringTwo = String (" this" );
125+ ATS_PrintTestStatus (" 10. Not equals() method equals" , ! stringOne. equals(stringTwo));
126+
127+ // or perhaps you want to ignore case:
128+ ATS_PrintTestStatus (" 11. EqualsIgnoreCase() method equals" , stringOne. equalsIgnoreCase(stringTwo));
129+
130+ // a numeric string compared to the number it represents:
131+ stringOne = " 1" ;
132+ int numberOne = 1 ;
133+ ATS_PrintTestStatus (" 12. A numeric string compared to the number it represents" , stringOne == numberOne);
137134
135+ // two numeric strings compared:
136+ stringOne = " 2" ;
137+ stringTwo = " 1" ;
138+ ATS_PrintTestStatus (" 13. Two numeric strings compared" ,stringOne >= stringTwo);
139+
140+
141+ // comparison operators can be used to compare strings for alphabetic sorting too:
142+
143+
144+ stringOne = String (" Brown" );
145+ // ATS_PrintTestStatus("14. comparison operator < can be used to compare strings for alphabetic sorting ",stringOne < "Charles");
146+ // ATS_PrintTestStatus("15. comparison operator > can be used to compare strings for alphabetic sorting ",stringOne > "Adams");
147+ // ATS_PrintTestStatus("16. comparison operator <= can be used to compare strings for alphabetic sorting ",stringOne <= "Browne");
148+ // ATS_PrintTestStatus("17. comparison operator >= can be used to compare strings for alphabetic sorting ",stringOne >= "Brow");
149+
150+
151+
152+ // the compareTo() operator also allows you to compare strings
153+ stringOne = " Cucumber" ;
154+ stringTwo = " Cucuracha" ;
155+
156+ ATS_PrintTestStatus (" 18. The compareTo() operator also allows you to compare strings" , stringOne. compareTo(stringTwo) < 0 );
157+
158+ // compareTo() String with numnber > String with number:
159+ stringOne = " Sensor: 50" ;
160+ stringTwo= " Sensor: 150" ;
161+ ATS_PrintTestStatus (" 19. The compareTo() String with integers" , stringOne. compareTo(stringTwo) < 0 );
162+
163+ // compareTo() String with numnber > String with number append integer, matches example code:
164+ stringOne = " Sensor: " ;
165+ stringTwo= " Sensor: " ;
166+ stringOne += 50 ;
167+ stringTwo += 150 ;
168+ ATS_PrintTestStatus (" 20. The compareTo() compare strings with appended integers" , stringOne. compareTo(stringTwo) < 0 );
138169
139170
140171 /*
141- * Test complete
172+ * setup up String Append Operation Tests
173+ */
174+ // Serious awful problem here
175+ stringOne = String (" Sensor " );
176+ stringTwo = String (" value" );
177+
178+ stringOne += stringTwo;
179+ // ATS_PrintTestStatus("N. Adding string to string += ",(strcmp(charResult,"Sensor value" ) == 0));
180+ // ATS_PrintTestStatus("N. Adding string to string += ", stringOne.equals("Sensor value"));
181+
182+ ATS_PrintTestStatus (" 21. The compareTo() compare strings with appended integers" , stringOne. compareTo(stringTwo) < 0 );
183+ /*
184+ * Test complete
142185 */
143186 ATS_PrintTestEnd ();
144187
188+
145189}
146190
147191
@@ -155,3 +199,9 @@ void loop()
155199
156200
157201
202+
203+
204+
205+
206+
207+
0 commit comments