Source: eval/result/DiffTestResult.js

  1. import {AbstractTestResult} from './AbstractTestResult.js';
  2. import {ActualDiff} from '../actual/ActualDiff.js';
  3. /**
  4. * The result for a diff test case.
  5. */
  6. export class DiffTestResult extends AbstractTestResult {
  7. /**
  8. * The time (in ms) it took to produced the result. Null indicates failure.
  9. * @type {?Number}
  10. * @const
  11. */
  12. runtime;
  13. /**
  14. * Construct a new DiffTestResult instance.
  15. @param {String} caseName The name of the corresponding diff test case.
  16. * @param {String} algorithm The name of the algorithm that produced the
  17. * diff.
  18. * @param {Number} runtime The time (in ms) it took to produced the result.
  19. * Null indicates failure.
  20. * @param {?ActualDiff} actual The actual diff produced by the
  21. * algorithm. Null indicates failure.
  22. * @param {String} verdict The verdict for this diff result.
  23. */
  24. constructor(
  25. caseName,
  26. algorithm,
  27. runtime,
  28. actual,
  29. verdict,
  30. ) {
  31. super(
  32. caseName,
  33. algorithm,
  34. actual,
  35. verdict,
  36. );
  37. this.runtime = runtime;
  38. }
  39. /**
  40. * @return {Array<String>} The header row for a list of diff test results to
  41. * use in tables.
  42. */
  43. static header() {
  44. return [
  45. 'Algorithm',
  46. 'Runtime',
  47. 'Edit Script Cost',
  48. 'Edit Script Size',
  49. 'Insertions',
  50. 'Moves',
  51. 'Updates',
  52. 'Deletions',
  53. 'Diff Size',
  54. ];
  55. }
  56. /**
  57. * @return {Array<String>} The row of values of this result for use in tables.
  58. */
  59. values() {
  60. // A non-OK verdict indicates failure, fill the array with it
  61. if (!this.isOk()) {
  62. return [
  63. this.algorithm,
  64. ...(new Array(DiffTestResult.header().length - 1)
  65. .fill(this.verdict)),
  66. ];
  67. }
  68. return [
  69. this.algorithm,
  70. this.runtime,
  71. this.actual.cost,
  72. this.actual.editOperations,
  73. this.actual.insertions,
  74. this.actual.moves,
  75. this.actual.updates,
  76. this.actual.deletions,
  77. this.actual.diffSize,
  78. ];
  79. }
  80. }