/specs/runtime/array.ds

http://github.com/wilkie/djehuty · Unknown · 42 lines · 34 code · 8 blank · 0 comment · 0 complexity · a8e9aa7b14dbf780ee12e0db7d47f115 MD5 · raw file

  1. module specs.runtime.array;
  2. import io.console;
  3. import math.random;
  4. describe runtime() {
  5. describe _adCmp() {
  6. it should_handle_empty_arrays() {
  7. int[] empty = [];
  8. shouldNot(empty == [1,2,3]);
  9. }
  10. }
  11. describe _adSort {
  12. it should_sort_simple_int_arrays {
  13. int[] sorted = [2,1,3].sort;
  14. should(sorted == [1,2,3]);
  15. }
  16. it should_sort_random_arrays {
  17. int[500] foo;
  18. auto r = new Random();
  19. foreach(ref element; foo) {
  20. element = cast(int)r.next();
  21. }
  22. foo.sort;
  23. int cur = foo[0];
  24. foreach(element; foo) {
  25. // Ensure it is ascending
  26. should(element >= cur);
  27. }
  28. }
  29. it should_sort_simple_double_arrays {
  30. double[] sorted = [0.0, 0.8, 0.4, 0.2, 0.9].sort;
  31. should(sorted == [0.0,0.2,0.4,0.8,0.9]);
  32. }
  33. }
  34. }