threepipe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Author: Axel Antoine
  3. * mail: ax.antoine@gmail.com
  4. * website: http://axantoine.com
  5. * Created on Thu Nov 10 2022
  6. *
  7. * Loki, Inria project-team with Université de Lille
  8. * within the Joint Research Unit UMR 9189
  9. * CNRS - Centrale Lille - Université de Lille, CRIStAL
  10. * https://loki.lille.inria.fr
  11. *
  12. * Licence: Licence.md
  13. */
  14. // declare global {
  15. // namespace jest {
  16. // interface Matchers<R> {
  17. // toBeHalfedge(expected: Halfedge): CustomMatcherResult;
  18. // toBeVertex(expected: Vertex): CustomMatcherResult;
  19. // toBeOneOfHalfedges(expected: Halfedge[]): CustomMatcherResult;
  20. // }
  21. // }
  22. // }
  23. // expect.extend({
  24. //
  25. // toBeHalfedge(received: Halfedge, expected: Halfedge) {
  26. // const pass = received === expected;
  27. //
  28. // return {
  29. // message: () =>
  30. // `Expected Halfedges ${pass? 'not ': ''}to be equal`+
  31. // '\nReceived: '+ received.id +
  32. // '\nExpected: '+ expected.id,
  33. // pass: pass,
  34. // };
  35. // },
  36. //
  37. // toBeOneOfHalfedges(received: Halfedge, expected: Halfedge[]) {
  38. // const pass = expected.indexOf(received) !== -1;
  39. //
  40. // return {
  41. // message: () =>
  42. // `Expected Halfedges ${pass? 'not ': ''}to be in the list`+
  43. // '\nReceived: '+ received.id +
  44. // '\nExpected list: '+ expected.map(e => e.id).join(', '),
  45. // pass: pass,
  46. // };
  47. // },
  48. //
  49. // toBeVertex(received: Vertex, expected: Vertex) {
  50. // const pass = received === expected;
  51. //
  52. // return {
  53. // message: () =>
  54. // `Expected Vertices ${pass? 'not ': ''}to be equal`+
  55. // '\nReceived: '+ received.id +
  56. // '\nExpected: '+ expected.id,
  57. // pass: pass,
  58. // };
  59. // },
  60. //
  61. // });
  62. export function generatorSize(g: Generator) {
  63. let cpt = 0;
  64. let v = g.next();
  65. while(!v.done) {
  66. cpt += 1;
  67. v = g.next();
  68. }
  69. return cpt;
  70. }
  71. export function generatorToArray<T>(g: Generator<T>) {
  72. const array = new Array<T>();
  73. let v = g.next();
  74. while(!v.done) {
  75. array.push(v.value);
  76. v = g.next();
  77. }
  78. return array;
  79. }