File size: 3,585 Bytes
78d2150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "../../unity/unity.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

/* Unity required hooks */
void setUp(void) {
  /* Setup code here, or leave empty */
}
void tearDown(void) {
  /* Cleanup code here, or leave empty */
}

/* The following helpers and the target function `null` are defined in the
   included program source (this test file is included into expr.c),
   so we can call them directly:
     - VALUE struct and TYPE enum
     - int_value, str_value, freev
     - toarith
     - null
*/

/* Integer cases */

static void test_null_integer_zero_true(void) {
  VALUE *v = int_value(0);
  TEST_ASSERT_TRUE(null(v));
  freev(v);
}

static void test_null_integer_one_false(void) {
  VALUE *v = int_value(1);
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

static void test_null_integer_negative_false(void) {
  VALUE *v = str_value("-1");
  TEST_ASSERT_TRUE(toarith(v));
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

static void test_null_integer_negative_zero_true(void) {
  VALUE *v = str_value("-0");
  TEST_ASSERT_TRUE(toarith(v));
  TEST_ASSERT_TRUE(null(v));
  freev(v);
}

static void test_null_integer_large_nonzero_false(void) {
  VALUE *v = str_value("123456789012345678901234567890");
  TEST_ASSERT_TRUE(toarith(v));
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

/* String cases */

static void test_null_string_empty_true(void) {
  VALUE *v = str_value("");
  TEST_ASSERT_TRUE(null(v));
  freev(v);
}

static void test_null_string_zero_true(void) {
  VALUE *v = str_value("0");
  TEST_ASSERT_TRUE(null(v));
  freev(v);
}

static void test_null_string_many_zeros_true(void) {
  VALUE *v = str_value("000000");
  TEST_ASSERT_TRUE(null(v));
  freev(v);
}

static void test_null_string_minus_zeros_true(void) {
  VALUE *v = str_value("-00000");
  TEST_ASSERT_TRUE(null(v));
  freev(v);
}

static void test_null_string_single_minus_false(void) {
  VALUE *v = str_value("-");
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

static void test_null_string_nonzero_digit_false(void) {
  VALUE *v = str_value("1");
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

static void test_null_string_leading_zeros_then_nonzero_false(void) {
  VALUE *v = str_value("000100");
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

static void test_null_string_minus_then_nonzero_false(void) {
  VALUE *v = str_value("-10");
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

static void test_null_string_plus_zero_false(void) {
  VALUE *v = str_value("+0");
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

static void test_null_string_space_zero_false(void) {
  VALUE *v = str_value(" 0");
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

static void test_null_string_alpha_false(void) {
  VALUE *v = str_value("foo");
  TEST_ASSERT_FALSE(null(v));
  freev(v);
}

/* Main runner */
int main(void) {
  UNITY_BEGIN();

  RUN_TEST(test_null_integer_zero_true);
  RUN_TEST(test_null_integer_one_false);
  RUN_TEST(test_null_integer_negative_false);
  RUN_TEST(test_null_integer_negative_zero_true);
  RUN_TEST(test_null_integer_large_nonzero_false);

  RUN_TEST(test_null_string_empty_true);
  RUN_TEST(test_null_string_zero_true);
  RUN_TEST(test_null_string_many_zeros_true);
  RUN_TEST(test_null_string_minus_zeros_true);
  RUN_TEST(test_null_string_single_minus_false);
  RUN_TEST(test_null_string_nonzero_digit_false);
  RUN_TEST(test_null_string_leading_zeros_then_nonzero_false);
  RUN_TEST(test_null_string_minus_then_nonzero_false);
  RUN_TEST(test_null_string_plus_zero_false);
  RUN_TEST(test_null_string_space_zero_false);
  RUN_TEST(test_null_string_alpha_false);

  return UNITY_END();
}