range-test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. 'use strict';
  2. var main = require('../package.json').main;
  3. var schedule = require('../' + main);
  4. module.exports = {
  5. "step defaults to 1": function(test) {
  6. var range = new schedule.Range(2, 6);
  7. test.equals(1, range.step);
  8. test.done();
  9. },
  10. "when step is 1": {
  11. "setUp": function(done) {
  12. this.range = new schedule.Range(2, 6, 1);
  13. done();
  14. },
  15. "includes start value": function(test) {
  16. test.ok(this.range.contains(2));
  17. test.done();
  18. },
  19. "includes end value": function(test) {
  20. test.ok(this.range.contains(6));
  21. test.done();
  22. },
  23. "includes value between start and end": function(test) {
  24. test.ok(this.range.contains(3));
  25. test.done();
  26. },
  27. "excludes values outside of start and end": function(test) {
  28. test.ok(!this.range.contains(1));
  29. test.ok(!this.range.contains(7));
  30. test.done();
  31. }
  32. },
  33. "when step > 1": {
  34. "setUp": function(done) {
  35. this.range = new schedule.Range(2, 6, 2);
  36. done();
  37. },
  38. "includes start value": function(test) {
  39. test.ok(this.range.contains(2));
  40. test.done();
  41. },
  42. "excludes end value": function(test) {
  43. test.ok(!this.range.contains(6));
  44. test.done();
  45. },
  46. "includes value between start and end that is evenly divisible by step": function(test) {
  47. test.ok(this.range.contains(4));
  48. test.done();
  49. },
  50. "excludes value between start and end that is not evenly divisible by step": function(test) {
  51. test.ok(!this.range.contains(5));
  52. test.done();
  53. },
  54. "excludes values outside of start and end": function(test) {
  55. test.ok(!this.range.contains(1));
  56. test.ok(!this.range.contains(7));
  57. test.done();
  58. }
  59. }
  60. };