Guest User

Untitled

a guest
Apr 24th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <assert.h>
  5. #include "list.h"
  6.  
  7. void free_char(void* d){
  8. free( d );
  9. }
  10.  
  11.  
  12. int main(int argc, char** argv){
  13. _list* l;
  14. int x, act;
  15. char* v;
  16.  
  17. printf( "." );
  18. assert( l = list_nueva(free_char) );
  19. for( x = 0; x < 100; x ++ ){
  20. char* linea;
  21. linea = (char*) malloc( 24 );
  22. sprintf( linea, "Nueva %d", x );
  23. list_agrega( l, (void*) linea );
  24. }
  25.  
  26. printf( "." );
  27. assert( l->entradas == 100 );
  28.  
  29. printf( "." );
  30. assert( strcmp( l->data[0], "Nueva 0" ) == 0 );
  31. assert( strcmp( l->data[1], "Nueva 1" ) == 0 );
  32.  
  33. list_quita( l, 22 );
  34. printf( "." );
  35. assert( l->entradas == 99 );
  36.  
  37. printf( "." );
  38. assert( strcmp( l->data[0], "Nueva 0" ) == 0 );
  39. assert( strcmp( l->data[1], "Nueva 1" ) == 0 );
  40. assert( strcmp( l->data[23], "Nueva 24" ) == 0 );
  41. assert( strcmp( l->data[97], "Nueva 98" ) == 0 );
  42. assert( strcmp( l->data[98], "Nueva 99" ) == 0 );
  43.  
  44. // Compruebo el armado ...
  45. list_inicio( l );
  46. x = 0; act = 0;
  47. assert( l->actual == act );
  48. while( ( v = list_siguiente( l ) ) ){
  49. if( x == 22 ) x ++;
  50. assert( l->actual ==( ++act ) );
  51. char lll[24];
  52. printf( "." );
  53. sprintf( lll, "Nueva %d", x );
  54. // printf( "(%d) %s == %s\n", l->actual, lll, v );
  55. assert( strcmp( v, lll ) == 0 );
  56. x ++;
  57. }
  58.  
  59. // Ahora al reves ...
  60. list_final( l );
  61. x = 99;
  62. while( ( v = list_anterior( l ) ) ){
  63. if( x == 22 ) x --;
  64. char lll[24];
  65. printf( "." );
  66. sprintf( lll, "Nueva %d", x );
  67. assert( strcmp( v, lll ) == 0 );
  68. x --;
  69. }
  70.  
  71. // Pop
  72. v = list_pop( l );
  73. printf( "." );
  74. assert( strcmp( v, "Nueva 99" ) == 0 );
  75. assert( l->entradas == 98 );
  76.  
  77. printf( "\n" );
  78. list_free( l );
  79. return 0;
  80.  
  81. }
Add Comment
Please, Sign In to add comment