Msushi

Untitled

Mar 16th, 2021
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. test('Only unmatched elements propose', function() {
  2. let traces = f(companies, candidates).trace;
  3. for (let k = 0; k < traces.length;++k) {
  4. for (let j = 0; j < k; ++j) {
  5. if (traces[k].from === traces[j].from && traces[k].fromCo && traces[j].fromCo) {
  6. let findReassignment = false;
  7. for (let r = j; j < k; ++j) {
  8. if (traces[j].to === traces[r].to && traces[r].fromCo && traces[j].fromCo) {
  9. findReassignment = true;
  10. }
  11. }
  12. if (!findReassignment) {
  13. assert(false);
  14. return;
  15. }
  16. }
  17. }
  18. }
  19. assert(true);
  20. });
  21.  
  22. test('Traces do not contain invalid values (>= n)', function() {
  23. let traces = f(companies, candidates).trace;
  24. for (let k = 0;k < traces.length; ++k) {
  25. assert(traces[k].from < n);
  26. assert(traces[k].to < n);
  27. }
  28. });
  29.  
  30. test('Out is the result of the trace (checking last)', function() {
  31. let functionOutput = f(companies, candidates);
  32. //console.log(functionOutput);
  33. let lastTrace = functionOutput.trace[functionOutput.trace.length-1];
  34. let companyMatch = 0;
  35. let candidateMatch = 0;
  36. if (lastTrace.fromCo) {
  37. companyMatch = lastTrace.from;
  38. candidateMatch = lastTrace.to;
  39. }
  40. else {
  41. companyMatch = lastTrace.to;
  42. candidateMatch = lastTrace.from;
  43. }
  44. //console.log(companyMatch);
  45. //console.log(candidateMatch);
  46. for (let k = 0; k < n; ++k) {
  47. if (functionOutput.out[k].company === companyMatch && functionOutput.out[k].candidate === candidateMatch) {
  48. assert(true);
  49. return;
  50. }
  51. }
  52. assert(false);
  53. });
  54.  
  55. test('Check for duplicate traces', function() {
  56. let functionOutput = f(companies, candidates);
  57. let firstTrace = functionOutput.trace[0];
  58. let companyMatch = 0;
  59. let candidateMatch = 0;
  60. if (firstTrace.fromCo) {
  61. companyMatch = firstTrace.from;
  62. candidateMatch = firstTrace.to;
  63. }
  64. else {
  65. companyMatch = firstTrace.to;
  66. candidateMatch = firstTrace.from;
  67. }
  68. let containsMatch = false;
  69. for (let k = 0; k < n; ++k) {
  70. if (functionOutput.out[k].company === companyMatch && functionOutput.out[k].candidate === candidateMatch) {
  71. containsMatch = true;
  72. }
  73. }
  74. if (!containsMatch) {
  75. for (let k = 1; k < functionOutput.trace.length; ++k) {
  76. if (functionOutput.trace[k].from === companyMatch) {
  77. assert(true);
  78. return;
  79. }
  80. }
  81. assert(false);
  82. }
  83. else {
  84. assert(true);
  85. }
  86. });
  87. }
Advertisement
Add Comment
Please, Sign In to add comment