1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <stdio.h>
#include "tests.h"
int d(int v){
return 2*v;
}
void compare_pointers() {
char * str = "aaaaaaaaaa";
char * a = &str[2];
char * b = &str[3];
int t = a < b;
is_true(t);
b = &str[1];
t = a > b;
is_true(t);
t = a == b;
is_false(t);
t = a < b;
is_false(t);
b = &str[2];
t = a == b;
is_true(t);
t = a < b;
is_false(t);
t = a <= b;
is_true(t);
t = a >= b;
is_true(t);
t = a == 0;
is_false(t);
}
int main()
{
plan(16);
int x = 1;
// Without else
if (x == 1)
pass("%s", "x is equal to one");
if (x == 1){
pass("%s", "x is equal to one");
}
// With else
if (x != 1){
fail("%s", "x is not equal to one");
} else {
pass("%s", "x is equal to one");
}
if ( NULL) {
fail("%s", "NULL is zero");
} else {
pass("%s", "NULL is not zero");
}
if ( ! NULL) {
pass("%s", "Invert : ! NULL is zero");
} else {
fail("%s", "Invert : ! NULL is not zero");
}
diag("Operation inside function")
int ii = 5;
if ((ii = d(ii)) != (-1)){
is_eq(ii,10)
}
diag("if - else");
{
int a = 10;
int b = 5 ;
int c = 0 ;
if ( a < b )
{
} else if (b > c)
{
pass("ok");
}
}
diag("Pointer comparisons");
compare_pointers();
done_testing();
}
|