Skip to content
Permalink
Browse files
fix some minor errors in unit test example
  • Loading branch information
James Brusey committed Jun 29, 2022
1 parent ab59d44 commit b8cb9f4c9171ca188262b92b4acf8f38e8aeaea0
Showing 1 changed file with 4 additions and 4 deletions.
@@ -74,7 +74,7 @@ Note that we need =types.h= so that we can define the types that ordinarily are
#ifndef CONTIKI
typedef unsigned short int uint16_t;
typedef short int int16_t;
#if
#endif
#+END_SRC
We don't want to accidentally include these type definitions when Contiki is being used, so =#ifndef= says "only include this bit when CONTIKI is not defined".

@@ -129,11 +129,9 @@ struct decimal *convert_temperature(struct decimal *dp, uint16_t v)
return dp;
}
#+END_SRC
The above code should fail and when we run =make= when in the =test= directory, we get:
The above code should fail and when we run =make= from the =test= directory. We get:
#+BEGIN_SRC
./test_temp
test_temp: test_temp.c:10: test_temp_calc: Assertion `result.integer_part == 66 - 39' failed.
Makefile:3: recipe for target 'test' failed
#+END_SRC
The above says that the test failed at line 10.

@@ -168,6 +166,8 @@ struct decimal *convert_temperature(struct decimal *dp, uint16_t v)
return dp;
}
#+END_SRC
By the way, if you haven't worked it out, the reason why the previous test failed was because we were trying to store a negative number in an unsigned integer.

When we try this out, we get:
#+BEGIN_SRC
test_temp: test_temp.c:17: test_temp_calc: Assertion `result.fractional_part == 60' failed.

0 comments on commit b8cb9f4

Please sign in to comment.