You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

strset.t.c 907B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "strset.h"
  2. #include <stdio.h>
  3. #include <snow/snow.h>
  4. describe(l2_strset) {
  5. struct l2_strset set;
  6. before_each() {
  7. l2_strset_init(&set);
  8. }
  9. after_each() {
  10. l2_strset_free(&set);
  11. }
  12. test("basic functionality") {
  13. asserteq(l2_strset_put_copy(&set, "hello"), 1);
  14. asserteq(l2_strset_put_copy(&set, "world"), 2);
  15. asserteq(l2_strset_get(&set, "hello"), 1);
  16. asserteq(l2_strset_get(&set, "world"), 2);
  17. }
  18. it("handles duplicates") {
  19. asserteq(l2_strset_put_copy(&set, "hello"), 1);
  20. asserteq(l2_strset_put_copy(&set, "hello"), 1);
  21. asserteq(l2_strset_put_copy(&set, "world"), 2);
  22. }
  23. it("handles a whole bunch of values") {
  24. char buf[128];
  25. for (int i = 0; i < 1000; ++i) {
  26. sprintf(buf, "test-%d", i);
  27. asserteq(l2_strset_put_copy(&set, buf), i + 1);
  28. }
  29. for (int i = 0; i < 1000; ++i) {
  30. sprintf(buf, "test-%d", i);
  31. asserteq(l2_strset_get(&set, buf), i + 1);
  32. }
  33. }
  34. }