In connection with the type promotion, your uint8 will be advertised on the int platform, which is likely to be larger than the 8-bit (usually 32-bit) in most modern "Computer".
this line:
if ((test1 - test2) < 0)
if equivalent
if ((int)((int)test1 - (int)test2) < 0) = -255 < 0
which is true.
However for this line
uint8_t test3 = test1 - test2;
he is equivalent
uint8_t test3 = (uint8_t)((int)test1 - (int)test2);
So, as test1 - test2 < 0 , so test3 > 0 (welcome to the world of computers!) Correctly!
This explains your result.
But for uint32 , because it has a "higher" rank than native int , so it does not "advance" and remains like uint32 all the time, or, in other words,
this line:
if ((test1 - test2) > 0)
if equivalent
if ((uint32_t)((uint32_t)test1 - (uint32_t)test2) > 0) = large positive number > 0
and this line
uint32_t test3 = test1 - test2;
equivalently
uint32_t test3 = (uint32_t)test1 - (uint32_t)test2;
Thus, you have both test1 - test2 > 0 , and test3 > 0 .
So, in your two cases, both can be correct only when working on an 8-bit machine. Or, suppose, in the future, the native int will be 64-bit, then both cases will be correct too ...