Guest User

Untitled

a guest
Jan 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. const worker_module = require('../../api/controllers/WorkerController.js');
  2. const assert = require('assert');
  3. const WorkerController = worker_module.WorkerController;
  4. function newCall(Cls, arguments) {
  5. return new (Function.prototype.bind.apply(Cls, [Cls].concat(arguments)));
  6. }
  7. describe('WorkerControllerConstruct', function() {
  8. describe('#constructor', function () {
  9. const inputs = Array.from({length: 20}, (x,i) => i);
  10. const testargs = [];
  11. for (const i of inputs) {
  12. for (const j of inputs) {
  13. testargs.push({
  14. args: [i, j],
  15. expected: [
  16. (workerController) => assert.equal(workerController.maxOpen, i),
  17. (workerController) => assert.equal(workerController.time, j),
  18. ]
  19. });
  20. }
  21. }
  22.  
  23. for (const testarg of testargs) {
  24. it('Construct with args (' + testarg.args.toString() + ')', function () {
  25. let args = testarg.args;
  26. let expectations = testarg.expected;
  27. let worker = newCall(WorkerController, args);
  28. for (const expected of expectations) {
  29. expected(worker);
  30. }
  31. });
  32. }
  33. });
  34. });
  35.  
  36. describe('JobCountNumber', function() {
  37. describe('#nextNumber', function() {
  38. let testargs = [
  39. {
  40. args: new JobCountNumber(0, 1),
  41. expected:[
  42. (counter) => assert.equal(counter.currentYear, 0),
  43. (counter) => assert.equal(counter.currentNumber, 2)
  44. ]
  45. }, {
  46. args: new JobCountNumber(0, 29999),
  47. expected:[
  48. (counter) => assert.equal(counter.currentYear, 3),
  49. (counter) => assert.equal(counter.currentNumber, 0)
  50. ]
  51. }, {
  52. args: new JobCountNumber(3, 0),
  53. expected:[
  54. (counter) => assert.equal(counter.currentYear, 3),
  55. (counter) => assert.equal(counter.currentNumber, 1)
  56. ]
  57. }, {
  58. args: new JobCountNumber(3, 9999),
  59. expected:[
  60. (counter) => assert.equal(counter.currentYear, 4),
  61. (counter) => assert.equal(counter.currentNumber, 0)
  62. ]
  63. }, {
  64. args: new JobCountNumber(14, 9999),
  65. expected:[
  66. (counter) => assert.equal(counter.currentYear, 15),
  67. (counter) => assert.equal(counter.currentNumber, 0)
  68. ]
  69. }, {
  70. args: new JobCountNumber(15, 9999),
  71. expected:[
  72. (counter) => assert.equal(counter.currentYear, 15),
  73. (counter) => assert.equal(counter.currentNumber, 10000)
  74. ]
  75. }, {
  76. args: new JobCountNumber(15, 99999),
  77. expected:[
  78. (counter) => assert.equal(counter.currentYear, 16),
  79. (counter) => assert.equal(counter.currentNumber, 0)
  80. ]
  81. },
  82. ];
  83. for (let testarg of testargs) {
  84. it('NextNumber with args ' + testarg.args.toString(), function () {
  85. let args = testarg.args;
  86. args.nextNumber();
  87. let expectations = testarg.expected;
  88. for (let expected of expectations) {
  89. expected(args);
  90. }
  91. });
  92. }
  93. });
  94. });
Add Comment
Please, Sign In to add comment