@@ -6,10 +6,12 @@ or emulator. It is almost a drop-in replacement of ArduinoUnit with some
66advantages. AUnit supports timeouts and test fixtures. It somtimes consume 50%
77less flash memory on the AVR platform, and it has been tested to work on the
88AVR, ESP8266, ESP32 and Teensy platforms. The sister AUniter project provides
9- command line tools to verify, upload and validate the unit tests. AUniter tools
10- can be used in a continuous integration systems like Jenkins.
9+ command line tools to verify, upload and validate the unit tests. The AUniter
10+ tools can be used in a continuous integration system like Jenkins.
1111
12- Version: 1.0.1 (2018-06-27)
12+ Version: 1.1 (2018-07-23)
13+
14+ [ ![ AUniter Jenkins Badge] ( https://us-central1-xparks2015.cloudfunctions.net/badge?project=AUnit )] ( https://github.com/bxparks/AUniter )
1315
1416## Summary
1517
@@ -94,6 +96,9 @@ Here are the features in AUnit which are not available in ArduinoUnit 2.2:
9496* Case-insensitive string comparisons:
9597 * ` assertStringCaseEqual() `
9698 * ` assertStringCaseNotEqual() `
99+ * Approximate comparisons:
100+ * ` assertNear() `
101+ * ` asssertNotNear() `
97102* Test fixtures using the "F" variations of existing macros:
98103 * ` testF() `
99104 * ` testingF() `
@@ -357,13 +362,6 @@ are available. These are essentially identical to ArduinoUnit:
357362* ` assertLessOrEqual(a, b) `
358363* ` assertMoreOrEqual(a, b) `
359364
360- Two additional macros provide case-insensitive string comparisons
361- (analogous to ` ASSERT_STRCASEEQ() ` and ` ASSERT_STRCASENE() ` in
362- Google Test):
363-
364- * ` assertStringCaseEqual() `
365- * ` assertStringCaseNotEqual() `
366-
367365#### Supported Parameter Types
368366
369367The 6 core assert macros (assertEqual, assertNotEqual, assertLess, assertMore,
@@ -477,6 +475,75 @@ difficult to remember (and sometimes difficult to understand). The best way to
477475avoid these compiler errors is to make sure that the assertion parameter types
478476are identical, potentially using explicit casting.
479477
478+ ### Case Insensitive String Comparisons
479+
480+ Two macros provide case-insensitive string comparisons (analogous to
481+ ` ASSERT_STRCASEEQ() ` and ` ASSERT_STRCASENE() ` in Google Test):
482+
483+ * ` assertStringCaseEqual(a, b) `
484+ * ` assertStringCaseNotEqual(a, b) `
485+
486+ The supported types for ` (a, b) ` are all 9 combinations of Arduino string types:
487+
488+ * ` (const char *, const char *) `
489+ * ` (const char *, const String&) `
490+ * ` (const char *, const __FlashStringHelper*) `
491+ * ` (const String&, const char*) `
492+ * ` (const String&, const String&) `
493+ * ` (const String&, const __FlashStringHelper*) `
494+ * ` (const __FlashStringHelper*, const char*) `
495+ * ` (const __FlashStringHelper*, const String&) `
496+ * ` (const __FlashStringHelper*, const __FlashStringHelper*) `
497+
498+ *** ArduinoUnit Compatibility*** : _ Not available in ArduinoUnit._
499+
500+ ### Approximate Comparisons
501+
502+ Floating point values are difficult to compare because of internal rounding
503+ errors. Google Test provides
504+ [ two types of macros to handle floating points] ( https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#floating-point-comparison ) :
505+ * ` ASSERT_FLOAT_EQ(a, b) ` , ` ASSERT_DOUBLE_EQ(a, b) ` - determine if the
506+ floating point numbers are within 4
507+ [ Units in the Last Place (ULPs)] ( https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ )
508+ * ` ASSERT_NEAR(a, b, error) ` - determine if the absolute distance between
509+ ` a ` and ` b ` is within the given ` error `
510+
511+ Since floating point operations are relatively rare in Arduino programming,
512+ AUnit offers only the equilvalent of ` ASSERT_NEAR() ` function:
513+
514+ * ` assertNear(a, b, error) `
515+ * ` assertNotNear(a, b, error) `
516+
517+ Upon failure, the error messages will look something like:
518+ ```
519+ Assertion failed: |(1.00) - (1.10)| > (0.20), file AUnitTest.ino, line 517.
520+ Assertion failed: |(4.00) - (1.10)| <= (0.20), file AUnitTest.ino, line 527.
521+ ```
522+
523+ Unlike Google Test where ` ASSERT_NEAR() ` supports only the ` double ` type, both
524+ ` assertNear() ` and ` assertNotNear() ` support integral types as well. The full
525+ list of supported types is:
526+
527+ * ` int `
528+ * ` unsigned int `
529+ * ` long `
530+ * ` unsigned long `
531+ * ` double `
532+
533+ Other primitive types (e.g. ` char ` or ` float ` ) will be automatically converted
534+ to one of these supported types by the compiler.
535+
536+ Note that the ` abs() ` of 2 values of a signed integer type can be larger than
537+ the maximum value that can be represented by the given signed type. Since signed
538+ integer overflow is an
539+ [ undefined behavior] ( https://stackoverflow.com/questions/16188263/is-signed-integer-overflow-still-undefined-behavior-in-c )
540+ in C and C++11, I cannot predict what the compiler will do in that case.
541+ Unsigned types should not have this problem because the distance between two
542+ values of an unsigned type should always fit inside the given unsigned type.
543+ Technically, a similar problem exists for the floating point types (which are
544+ naturally signed), but it is unlikely that you are dealing with floating point
545+ values so close to the maximum values.
546+
480547### Boolean Assertions
481548
482549The following boolean asserts are also available:
@@ -1083,7 +1150,7 @@ framework, but let me know if you truly need a timeout of greater than 4m15s).
10831150
10841151*** ArduinoUnit Compatibility*** : _ Only available in AUnit._
10851152
1086- ## Commandline Tools and Continous Integration
1153+ ## Commandline Tools and Continuous Integration
10871154
10881155### AUniter
10891156
@@ -1205,6 +1272,15 @@ allows those assertion statements to have access to the internal states of the
12051272` Test ` instance, which makes certain functions (like the early return upon
12061273delayed failure) slightly easier to implement.
12071274
1275+ ### Comparing Pointers
1276+
1277+ Currently the ` assertEqual() ` and other ` assertXxx() ` methods do not support
1278+ comparing arbitrary pointers (i.e. ` (void*) ` . This could change if
1279+ [ Issue #34 ] ( https://github.com/bxparks/AUnit/issues/34 ) is
1280+ resolved. In the meantime, a workaround is to cast the pointer to a ` uintptr_t `
1281+ integer type from ` #include <stdint.h> ` and then calling ` assertEqual() ` on the
1282+ integer type.
1283+
12081284## Benchmarks
12091285
12101286AUnit consumes as much as 65% less flash memory than ArduinoUnit 2.2 on an AVR
0 commit comments