@@ -102,12 +102,144 @@ test__compact_size_with_suffix__is_bytes()
102102}
103103
104104
105+ int
106+ test__compact_size_with_suffix__is_kilobytes ()
107+ {
108+ /* Arrange */
109+ int size = 65536 ;
110+ char result [16 ] = { 0 };
111+ const char * expected = "64 KB" ;
112+
113+ /* Act */
114+ compact_size_with_suffix (size , result );
115+
116+ /* Assert */
117+ if (strcmp (result , expected ) != 0 ) {
118+ printf ("\nRESULT: %s\nEXPECTED: %s\n" , result , expected );
119+ return 1 ;
120+ }
121+
122+ return 0 ;
123+ }
124+
125+
126+ int
127+ test__compact_size_with_suffix__is_megabytes ()
128+ {
129+ /* Arrange */
130+ int size = 1048576 ;
131+ char result [16 ] = { 0 };
132+ const char * expected = "1 MB" ;
133+
134+ /* Act */
135+ compact_size_with_suffix (size , result );
136+
137+ /* Assert */
138+ if (strcmp (result , expected ) != 0 ) {
139+ printf ("\nRESULT: %s\nEXPECTED: %s\n" , result , expected );
140+ return 1 ;
141+ }
142+
143+ return 0 ;
144+ }
145+
146+
147+ int
148+ test__compact_size_with_suffix__is_not_megabytes ()
149+ {
150+ /* Arrange */
151+ int size = 1048575 ;
152+ char result [16 ] = { 0 };
153+ const char * expected = "1023 KB" ;
154+
155+ /* Act */
156+ compact_size_with_suffix (size , result );
157+
158+ /* Assert */
159+ if (strcmp (result , expected ) != 0 ) {
160+ printf ("\nRESULT: %s\nEXPECTED: %s\n" , result , expected );
161+ return 1 ;
162+ }
163+
164+ return 0 ;
165+ }
166+
167+
168+ int
169+ test__compact_size_with_suffix__is_gigabytes ()
170+ {
171+ /* Arrange */
172+ long long size = 1073741824 ;
173+ char result [16 ] = { 0 };
174+ const char * expected = "1 GB" ;
175+
176+ /* Act */
177+ compact_size_with_suffix (size , result );
178+
179+ /* Assert */
180+ if (strcmp (result , expected ) != 0 ) {
181+ printf ("\nRESULT: %s\nEXPECTED: %s\n" , result , expected );
182+ return 1 ;
183+ }
184+
185+ return 0 ;
186+ }
187+
188+
189+ int
190+ test__compact_size_with_suffix__is_not_gigabytes ()
191+ {
192+ /* Arrange */
193+ long long size = 1073741823 ;
194+ char result [16 ] = { 0 };
195+ const char * expected = "1023 MB" ;
196+
197+ /* Act */
198+ compact_size_with_suffix (size , result );
199+
200+ /* Assert */
201+ if (strcmp (result , expected ) != 0 ) {
202+ printf ("\nRESULT: %s\nEXPECTED: %s\n" , result , expected );
203+ return 1 ;
204+ }
205+
206+ return 0 ;
207+ }
208+
209+
210+ //int
211+ //test__compact_size_with_suffix__works_with_ntfs_volume_limit()
212+ //{
213+ // /* Arrange */
214+ // long long size = 281474976710656;
215+ // char result[16] = { 0 };
216+ // const char * expected = "1023 MB";
217+ //
218+ // /* Act */
219+ // compact_size_with_suffix(size, result);
220+ //
221+ // /* Assert */
222+ // if (strcmp(result, expected) != 0) {
223+ // printf("\nRESULT: %s\nEXPECTED: %s\n", result, expected);
224+ // return 1;
225+ // }
226+ //
227+ // return 0;
228+ //}
229+
230+
105231int
106232main ()
107233{
108234 int failed_count = 0 ;
109235
110236 failed_count += test__compact_size_with_suffix__is_bytes ();
237+ failed_count += test__compact_size_with_suffix__is_kilobytes ();
238+ failed_count += test__compact_size_with_suffix__is_megabytes ();
239+ failed_count += test__compact_size_with_suffix__is_not_megabytes ();
240+ failed_count += test__compact_size_with_suffix__is_gigabytes ();
241+ failed_count += test__compact_size_with_suffix__is_not_gigabytes ();
242+ //failed_count += test__compact_size_with_suffix__works_with_ntfs_volume_limit();
111243 failed_count += test__create_horizontal_line__is_console_width ();
112244 //failed_count += test__create_footer();
113245 failed_count += test__get_console_info__sets_attributes ();
0 commit comments