Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

TDD in C - Recently Used List Kata

2,395 views

Published on

How to do Test-Driven Development in C illustrated by solving a Recently Used List kata.

Similar slides can be found here http://www.olvemaudal.com/talks

Published in: Software
  • Be the first to comment

TDD in C - Recently Used List Kata

  1. 1. TDD in C Illustrated by the Recently-Used-List kata Olve Maudal
  2. 2. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt <empty> <empty> <empty> <empty> Source: cyber-dojo.org
  3. 3. README.txt <empty> <empty> <empty> <empty>
  4. 4. README.txt <empty> <empty> <empty> <empty>
  5. 5. README.txt rul_tests.c <empty> <empty> <empty>
  6. 6. README.txt rul_tests.c <empty> <empty> <empty>
  7. 7. README.txt rul_tests.c <empty> <empty> <empty>
  8. 8. #include <stdio.h> int main(void) { printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  9. 9. #include <stdio.h> int main(void) { printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  10. 10. #include <stdio.h> int main(void) { printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> TEST
  11. 11. #include <stdio.h> int main(void) { printf("All tests passedn"); } cc rul_tests.c && ./a.out All tests passed README.txt rul_tests.c <empty> <empty> <empty> TEST
  12. 12. #include <stdio.h> int main(void) { printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  13. 13. #include <stdio.h> int main(void) { printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  14. 14. #include <stdio.h> int main(void) { printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  15. 15. #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  16. 16. #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  17. 17. #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  18. 18. #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  19. 19. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  20. 20. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  21. 21. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> TEST
  22. 22. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } cc rul_tests.c && ./a.out a.out: rul_tests.c:6: main: Assertion `3 == 4' failed. README.txt rul_tests.c <empty> <empty> <empty> TEST
  23. 23. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } cc rul_tests.c && ./a.out a.out: rul_tests.c:6: main: Assertion `3 == 4' failed. README.txt rul_tests.c <empty> <empty> <empty> TEST
  24. 24. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 4); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  25. 25. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 3); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  26. 26. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 3); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  27. 27. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 3); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> TEST
  28. 28. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 3); printf("All tests passedn"); } cc rul_tests.c && ./a.out All tests passed README.txt rul_tests.c <empty> <empty> <empty> TEST
  29. 29. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 3); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  30. 30. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt <empty> <empty> <empty> <empty>
  31. 31. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt <empty> <empty> <empty> <empty>
  32. 32. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt <empty> <empty> <empty> <empty>
  33. 33. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 3); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  34. 34. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 3); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  35. 35. #include <assert.h> #include <stdio.h> int main(void) { assert(3 == 3); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  36. 36. #include <assert.h> #include <stdio.h> int main(void) { printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  37. 37. #include <assert.h> #include <stdio.h> int main(void) { printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  38. 38. #include <assert.h> #include <stdio.h> int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  39. 39. #include <assert.h> #include <stdio.h> int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  40. 40. #include <assert.h> #include <stdio.h> int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  41. 41. #include <assert.h> #include <stdio.h> int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  42. 42. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  43. 43. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  44. 44. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> TEST
  45. 45. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> cc rul_tests.c && ./a.out a.out: rul_tests.c:6: test_list_is_initially_empty: Assertion `3 == 4' failed. TEST
  46. 46. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  47. 47. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 3); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  48. 48. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 3); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  49. 49. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 3); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> TEST
  50. 50. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 3); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> cc rul_tests.c && ./a.out All tests passed TEST
  51. 51. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 3); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  52. 52. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 3); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  53. 53. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(3 == 3); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  54. 54. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert( ); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  55. 55. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert( ); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  56. 56. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  57. 57. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  58. 58. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  59. 59. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  60. 60. #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  61. 61. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  62. 62. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty>
  63. 63. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> TEST
  64. 64. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> cc rul_tests.c && ./a.out rul_tests.c:1:17: fatal error: rul.h: No such file or directory TEST
  65. 65. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c <empty> <empty> <empty> cc rul_tests.c && ./a.out rul_tests.c:1:17: fatal error: rul.h: No such file or directory TEST
  66. 66. README.txt rul_tests.c <empty> <empty> <empty>
  67. 67. README.txt rul_tests.c rul.h <empty> <empty>
  68. 68. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif
  69. 69. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif
  70. 70. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif TEST
  71. 71. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif cc rul_tests.c && ./a.out rul_tests.c:(.text+0xa): undefined reference to `rul_size' TEST
  72. 72. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif cc rul_tests.c && ./a.out rul_tests.c:(.text+0xa): undefined reference to `rul_size' TEST
  73. 73. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif cc rul_tests.c && ./a.out rul_tests.c:(.text+0xa): undefined reference to `rul_size'
  74. 74. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif cc rul_tests.c rul.c && ./a.out
  75. 75. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif cc rul_tests.c rul.c && ./a.out TEST
  76. 76. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif cc rul_tests.c rul.c && ./a.out cc: error: rul.c: No such file or directory TEST
  77. 77. README.txt rul_tests.c rul.h <empty> <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif cc rul_tests.c rul.c && ./a.out cc: error: rul.c: No such file or directory TEST
  78. 78. README.txt rul_tests.c rul.h <empty> <empty>
  79. 79. README.txt rul_tests.c rul.h rul.c <empty>
  80. 80. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return ; }
  81. 81. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return ; } ?
  82. 82. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 42; }
  83. 83. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 42; } TEST
  84. 84. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 42; } cc rul_tests.c rul.c && ./a.out test_list_is_initially_empty: Assertion `rul_size() == 0' failed. TEST
  85. 85. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 42; } cc rul_tests.c rul.c && ./a.out test_list_is_initially_empty: Assertion `rul_size() == 0' failed. TEST
  86. 86. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 0; }
  87. 87. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 0; } TEST
  88. 88. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 0; } cc rul_tests.c rul.c && ./a.out All tests passed TEST
  89. 89. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 0; } cc rul_tests.c rul.c && ./a.out All tests passed TEST
  90. 90. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  91. 91. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> TEST
  92. 92. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> cc rul_tests.c rul.c && ./a.out All tests passed TEST
  93. 93. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  94. 94. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  95. 95. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  96. 96. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size() == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  97. 97. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  98. 98. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  99. 99. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul * rul = NULL; assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  100. 100. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul * rul = NULL; assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  101. 101. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul * rul = NULL; assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  102. 102. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> size_t rul_size(void); #endif
  103. 103. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; size_t rul_size(const struct rul * rul); #endif
  104. 104. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; size_t rul_size(const struct rul * rul); #endif
  105. 105. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(void) { return 0; }
  106. 106. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(const struct rul * rul) { return 0; }
  107. 107. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(const struct rul * rul) { return 0; } TEST
  108. 108. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(const struct rul * rul) { return 0; } cc rul_tests.c rul.c && ./a.out All tests passed TEST
  109. 109. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(const struct rul * rul) { return 0; } cc rul_tests.c rul.c && ./a.out All tests passed TEST
  110. 110. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul * rul = NULL; assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  111. 111. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul * rul = NULL; assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  112. 112. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul * rul = NULL; assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  113. 113. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  114. 114. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  115. 115. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  116. 116. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; size_t rul_size(const struct rul * rul); #endif
  117. 117. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); #endif
  118. 118. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); #endif
  119. 119. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(const struct rul * rul) { return 0; }
  120. 120. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" size_t rul_size(const struct rul * rul) { return 0; }
  121. 121. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return NULL; } size_t rul_size(const struct rul * rul) { return 0; }
  122. 122. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return NULL; } size_t rul_size(const struct rul * rul) { return 0; }
  123. 123. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return NULL; } size_t rul_size(const struct rul * rul) { return 0; } TEST
  124. 124. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return NULL; } size_t rul_size(const struct rul * rul) { return 0; } cc rul_tests.c rul.c && ./a.out test_list_is_initially_empty: Assertion `rul == &myrul' failed. TEST
  125. 125. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return NULL; } size_t rul_size(const struct rul * rul) { return 0; } cc rul_tests.c rul.c && ./a.out test_list_is_initially_empty: Assertion `rul == &myrul' failed. TEST
  126. 126. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return 0; }
  127. 127. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return 0; }
  128. 128. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return 0; } TEST
  129. 129. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return 0; } cc rul_tests.c rul.c && ./a.out All tests passed TEST
  130. 130. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  131. 131. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> TEST
  132. 132. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> cc rul_tests.c rul.c && ./a.out All tests passed TEST
  133. 133. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> cc rul_tests.c rul.c && ./a.out All tests passed TEST
  134. 134. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  135. 135. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  136. 136. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  137. 137. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  138. 138. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  139. 139. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  140. 140. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> TEST
  141. 141. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> cc rul_tests.c rul.c && ./a.out All tests passed TEST
  142. 142. #include "rul.h" #include <assert.h> #include <stdio.h> static void test_list_is_initially_empty(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); assert(rul == &myrul); assert(rul_size(rul) == 0); } int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  143. 143. ... int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  144. 144. ... int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  145. 145. ... int main(void) { test_list_is_initially_empty(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  146. 146. ... int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  147. 147. ... static void test_size_of_list_increases_as_we_add_unique_items(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  148. 148. ... static void test_size_of_list_increases_as_we_add_unique_items(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> cc rul_tests.c rul.c && ./a.out test_size_of_list_increases_as_we_add_unique_items: Assertion `3 == 4' failed.
  149. 149. ... static void test_size_of_list_increases_as_we_add_unique_items(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  150. 150. ... static void test_size_of_list_increases_as_we_add_unique_items(void) { assert(3 == 4); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  151. 151. ... static void test_size_of_list_increases_as_we_add_unique_items(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(rul_size(rul) == 1); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty>
  152. 152. ... static void test_size_of_list_increases_as_we_add_unique_items(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(rul_size(rul) == 1); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> cc rul_tests.c rul.c && ./a.out rul_tests.c:(.text+0x92): undefined reference to `rul_add'
  153. 153. ... static void test_size_of_list_increases_as_we_add_unique_items(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(rul_size(rul) == 1); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> cc rul_tests.c rul.c && ./a.out rul_tests.c:(.text+0x92): undefined reference to `rul_add'
  154. 154. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); #endif
  155. 155. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif
  156. 156. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif
  157. 157. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return 0; }
  158. 158. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return 0; } void rul_add(struct rul * rul, const char * num) { }
  159. 159. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return 0; } void rul_add(struct rul * rul, const char * num) { } cc rul_tests.c rul.c && ./a.out a.out: rul_tests.c:19: test_size_of_list_increases_as_we_add_unique_items: Assertion `rul_size(rul) == 1' failed.
  160. 160. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return 0; } void rul_add(struct rul * rul, const char * num) { }
  161. 161. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { }
  162. 162. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { }
  163. 163. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; }
  164. 164. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; }
  165. 165. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; }
  166. 166. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul {}; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif
  167. 167. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif
  168. 168. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { size_t n_numbers; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif
  169. 169. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { size_t n_numbers; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif
  170. 170. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { size_t n_numbers; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif cc rul_tests.c rul.c && ./a.out All tests passed
  171. 171. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { size_t n_numbers; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif cc rul_tests.c rul.c && ./a.out All tests passed
  172. 172. static void test_size_of_list_increases_as_we_add_unique_items(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(rul_size(rul) == 1); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  173. 173. static void test_size_of_list_increases_as_we_add_unique_items(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(rul_size(rul) == 1); rul_add(rul, "1001"); assert(rul_size(rul) == 2); rul_add(rul, "1002"); rul_add(rul, "1003"); rul_add(rul, "1004"); assert(rul_size(rul) == 5); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  174. 174. static void test_size_of_list_increases_as_we_add_unique_items(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(rul_size(rul) == 1); rul_add(rul, "1001"); assert(rul_size(rul) == 2); rul_add(rul, "1002"); rul_add(rul, "1003"); rul_add(rul, "1004"); assert(rul_size(rul) == 5); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ... cc rul_tests.c rul.c && ./a.out All tests passed
  175. 175. static void test_size_of_list_increases_as_we_add_unique_items(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(rul_size(rul) == 1); rul_add(rul, "1001"); assert(rul_size(rul) == 2); rul_add(rul, "1002"); rul_add(rul, "1003"); rul_add(rul, "1004"); assert(rul_size(rul) == 5); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  176. 176. static void test_size_of_list_increases_as_we_add_unique_items(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(rul_size(rul) == 1); rul_add(rul, "1001"); assert(rul_size(rul) == 2); rul_add(rul, "1002"); rul_add(rul, "1003"); rul_add(rul, "1004"); assert(rul_size(rul) == 5); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  177. 177. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  178. 178. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  179. 179. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  180. 180. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  181. 181. int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  182. 182. int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  183. 183. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  184. 184. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  185. 185. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  186. 186. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { size_t n_numbers; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); #endif
  187. 187. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { size_t n_numbers; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); const char * rul_get(const struct rul * rul, size_t index); #endif
  188. 188. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { size_t n_numbers; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); const char * rul_get(const struct rul * rul, size_t index); #endif
  189. 189. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; }
  190. 190. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return ""; }
  191. 191. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return ""; }
  192. 192. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return ""; } cc rul_tests.c rul.c && ./a.out rul_tests.c:34: test_indexing_into_the_list: Assertion `strcmp(rul_get(rul, 0), "1000") == 0' failed.
  193. 193. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return ""; } ? cc rul_tests.c rul.c && ./a.out rul_tests.c:34: test_indexing_into_the_list: Assertion `strcmp(rul_get(rul, 0), "1000") == 0' failed.
  194. 194. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } cc rul_tests.c rul.c && ./a.out rul_tests.c:34: test_indexing_into_the_list: Assertion `strcmp(rul_get(rul, 0), "1000") == 0' failed.
  195. 195. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; }
  196. 196. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } cc rul_tests.c rul.c && ./a.out All tests passed
  197. 197. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } cc rul_tests.c rul.c && ./a.out All tests passed
  198. 198. README.txt rul_tests.c rul.h rul.c <empty> #include "rul.h" struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } cc rul_tests.c rul.c && ./a.out All tests passed
  199. 199. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  200. 200. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  201. 201. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  202. 202. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ... cc rul_tests.c rul.c && ./a.out rul_tests.c:36: test_indexing_into_the_list: Assertion `strcmp(rul_get(rul, 0), "1001") == 0' failed.
  203. 203. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  204. 204. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); // rul_add(rul, "1001"); // assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  205. 205. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); // rul_add(rul, "1001"); // assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ... cc rul_tests.c rul.c && ./a.out All tests passed
  206. 206. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); // rul_add(rul, "1001"); // assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  207. 207. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); // rul_add(rul, "1001"); // assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  208. 208. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> struct rul { size_t n_numbers; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); const char * rul_get(const struct rul * rul, size_t index); #endif
  209. 209. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> #define MAX_NUMLEN 15 #define MAX_NUMBERS 10 struct rul { size_t n_numbers; char numbers[MAX_NUMBERS][MAX_NUMLEN+1]; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); const char * rul_get(const struct rul * rul, size_t index); #endif
  210. 210. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> #define MAX_NUMLEN 15 #define MAX_NUMBERS 10 struct rul { size_t n_numbers; char numbers[MAX_NUMBERS][MAX_NUMLEN+1]; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); const char * rul_get(const struct rul * rul, size_t index); #endif cc rul_tests.c rul.c && ./a.out All tests passed
  211. 211. README.txt rul_tests.c rul.h rul.c <empty> #ifndef UTILS_RUL_H_INCLUDED #define UTILS_RUL_H_INCLUDED #include <stddef.h> #define MAX_NUMLEN 15 #define MAX_NUMBERS 10 struct rul { size_t n_numbers; char numbers[MAX_NUMBERS][MAX_NUMLEN+1]; }; struct rul * rul_init(struct rul * rul); size_t rul_size(const struct rul * rul); void rul_add(struct rul * rul, const char * num); const char * rul_get(const struct rul * rul, size_t index); #endif cc rul_tests.c rul.c && ./a.out All tests passed
  212. 212. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } ...
  213. 213. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; strcpy(rul->numbers[0], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } ...
  214. 214. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; strcpy(rul->numbers[0], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } cc rul_tests.c rul.c && ./a.out All tests passed ...
  215. 215. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; strcpy(rul->numbers[0], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } ...
  216. 216. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; strcpy(rul->numbers[0], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return "1000"; } ...
  217. 217. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; strcpy(rul->numbers[0], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return rul->numbers[0]; } ...
  218. 218. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; strcpy(rul->numbers[0], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return rul->numbers[0]; } cc rul_tests.c rul.c && ./a.out All tests passed ...
  219. 219. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); // rul_add(rul, "1001"); // assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  220. 220. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); // rul_add(rul, "1001"); // assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  221. 221. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); // rul_add(rul, "1001"); // assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  222. 222. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  223. 223. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ... cc rul_tests.c rul.c && ./a.out All tests passed
  224. 224. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  225. 225. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); assert(strcmp(rul_get(rul, 1), "1000") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ... cc rul_tests.c rul.c && ./a.out rul_tests.c: test_indexing_into_the_list: Assertion `strcmp(rul_get(rul, 1), "1000") == 0' failed.
  226. 226. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; strcpy(rul->numbers[0], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return rul->numbers[0]; } ...
  227. 227. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; strcpy(rul->numbers[0], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { return rul->numbers[0]; } ...
  228. 228. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) return; strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ...
  229. 229. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) return; strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ... cc rul_tests.c rul.c && ./a.out All tests passed
  230. 230. README.txt rul_tests.c rul.h rul.c <empty> struct rul * rul_init(struct rul * rul) { rul->n_numbers = 0; return rul; } size_t rul_size(const struct rul * rul) { return rul->n_numbers; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) return; strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ... cc rul_tests.c rul.c && ./a.out All tests passed
  231. 231. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); assert(strcmp(rul_get(rul, 1), "1000") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  232. 232. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); assert(strcmp(rul_get(rul, 1), "1000") == 0); rul_add(rul, "1002"); rul_add(rul, "1003"); assert(strcmp(rul_get(rul, 0), "1003") == 0); assert(strcmp(rul_get(rul, 1), "1002") == 0); assert(strcmp(rul_get(rul, 2), "1001") == 0); assert(strcmp(rul_get(rul, 3), "1000") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  233. 233. static void test_indexing_into_the_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); assert(strcmp(rul_get(rul, 0), "1000") == 0); rul_add(rul, "1001"); assert(strcmp(rul_get(rul, 0), "1001") == 0); assert(strcmp(rul_get(rul, 1), "1000") == 0); rul_add(rul, "1002"); rul_add(rul, "1003"); assert(strcmp(rul_get(rul, 0), "1003") == 0); assert(strcmp(rul_get(rul, 1), "1002") == 0); assert(strcmp(rul_get(rul, 2), "1001") == 0); assert(strcmp(rul_get(rul, 3), "1000") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ... cc rul_tests.c rul.c && ./a.out All tests passed
  234. 234. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  235. 235. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  236. 236. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  237. 237. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  238. 238. int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  239. 239. int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); test_adding_unique_items_to_full_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  240. 240. static void test_adding_unique_items_to_full_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); char num[MAX_NUMLEN+1]; for (int i = 0; i < MAX_NUMBERS; i++) { sprintf(num, "10%02d", i); rul_add(rul, num); } assert(rul_size(rul) == MAX_NUMBERS); assert(strcmp(rul_get(rul, MAX_NUMBERS-1), "1000") == 0); rul_add(rul, "1234"); assert(rul_size(rul) == MAX_NUMBERS); assert(strcmp(rul_get(rul, 0), "1234") == 0); assert(strcmp(rul_get(rul, MAX_NUMBERS-1), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); test_adding_unique_items_to_full_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  241. 241. static void test_adding_unique_items_to_full_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); char num[MAX_NUMLEN+1]; for (int i = 0; i < MAX_NUMBERS; i++) { sprintf(num, "10%02d", i); rul_add(rul, num); } assert(rul_size(rul) == MAX_NUMBERS); assert(strcmp(rul_get(rul, MAX_NUMBERS-1), "1000") == 0); rul_add(rul, "1234"); assert(rul_size(rul) == MAX_NUMBERS); assert(strcmp(rul_get(rul, 0), "1234") == 0); assert(strcmp(rul_get(rul, MAX_NUMBERS-1), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); test_adding_unique_items_to_full_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ... cc rul_tests.c rul.c && ./a.out test_adding_unique_items_to_full_list: Assertion `strcmp(rul_get(rul, 0), "1234") == 0' failed.
  242. 242. static void test_adding_unique_items_to_full_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); char num[MAX_NUMLEN+1]; for (int i = 0; i < MAX_NUMBERS; i++) { sprintf(num, "10%02d", i); rul_add(rul, num); } assert(rul_size(rul) == MAX_NUMBERS); assert(strcmp(rul_get(rul, MAX_NUMBERS-1), "1000") == 0); rul_add(rul, "1234"); assert(rul_size(rul) == MAX_NUMBERS); assert(strcmp(rul_get(rul, 0), "1234") == 0); assert(strcmp(rul_get(rul, MAX_NUMBERS-1), "1001") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); test_adding_unique_items_to_full_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ... cc rul_tests.c rul.c && ./a.out test_adding_unique_items_to_full_list: Assertion `strcmp(rul_get(rul, 0), "1234") == 0' failed.
  243. 243. README.txt rul_tests.c rul.h rul.c <empty> void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) return; strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ...
  244. 244. README.txt rul_tests.c rul.h rul.c <empty> void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) return; strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ...
  245. 245. README.txt rul_tests.c rul.h rul.c <empty> void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) remove_oldest_number(rul); strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ...
  246. 246. README.txt rul_tests.c rul.h rul.c <empty> static void remove_oldest_number(struct rul * rul) { for (size_t i = 0; i < rul->n_numbers - 1; i++) strcpy(rul->numbers[i], rul->numbers[i+1]); rul->n_numbers--; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) remove_oldest_number(rul); strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ...
  247. 247. README.txt rul_tests.c rul.h rul.c <empty> static void remove_oldest_number(struct rul * rul) { for (size_t i = 0; i < rul->n_numbers - 1; i++) strcpy(rul->numbers[i], rul->numbers[i+1]); rul->n_numbers--; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) remove_oldest_number(rul); strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ... cc rul_tests.c rul.c && ./a.out All tests passed
  248. 248. README.txt rul_tests.c rul.h rul.c <empty> static void remove_oldest_number(struct rul * rul) { for (size_t i = 0; i < rul->n_numbers - 1; i++) strcpy(rul->numbers[i], rul->numbers[i+1]); rul->n_numbers--; } void rul_add(struct rul * rul, const char * num) { if (strlen(num) > MAX_NUMLEN) return; if (rul->n_numbers == MAX_NUMBERS) remove_oldest_number(rul); strcpy(rul->numbers[rul->n_numbers], num); rul->n_numbers++; } const char * rul_get(const struct rul * rul, size_t index) { if (index + 1 > rul->n_numbers) return ""; return rul->numbers[rul->n_numbers - (index + 1)]; } ... cc rul_tests.c rul.c && ./a.out All tests passed
  249. 249. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  250. 250. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  251. 251. Develop a recently-used-list module for holding a limited set of unique phone numbers in a Last-In-First-Out order. Initially, you may assume that numbers added to the list are no longer than 15 digits. You may also assume that the capacity of the list is 10 items. (Imagine that this code is to be used to show a list of the most recently used phone numbers in a very simple cordless phone.) o) A recently-used-list is initially empty. As you add unique numbers, the list grows, until capacity is reached. o) Numbers in the list can be looked up by index. The zeroth element is the most recently used item. o) Numbers in the list are unique. If you add a number that already exists, the number is moved to the zeroth element in the list. o) When adding a unique number to a full list, the oldest number is dropped to make room for the new entry. README.txt rul_tests.c rul.h rul.c <empty>
  252. 252. int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); test_adding_unique_items_to_full_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  253. 253. int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); test_adding_unique_items_to_full_list(); test_adding_existing_numbers_to_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...
  254. 254. static void test_adding_existing_numbers_to_list(void) { struct rul myrul; struct rul * rul = rul_init(&myrul); rul_add(rul, "1000"); rul_add(rul, "1001"); rul_add(rul, "1002"); rul_add(rul, "1003"); assert(rul_size(rul) == 4); rul_add(rul, "1002"); assert(rul_size(rul) == 4); assert(strcmp(rul_get(rul, 0), "1002") == 0); } int main(void) { test_list_is_initially_empty(); test_size_of_list_increases_as_we_add_unique_items(); test_indexing_into_the_list(); test_adding_unique_items_to_full_list(); test_adding_existing_numbers_to_list(); printf("All tests passedn"); } README.txt rul_tests.c rul.h rul.c <empty> ...

×