Application Android et IOS pour l'amicale des élèves
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.

Shape.test.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* eslint-disable */
  2. import React from 'react';
  3. import BaseShape from '../Shapes/BaseShape';
  4. import ShapeI from '../Shapes/ShapeI';
  5. const colors = {
  6. tetrisI: '#000001',
  7. tetrisO: '#000002',
  8. tetrisT: '#000003',
  9. tetrisS: '#000004',
  10. tetrisZ: '#000005',
  11. tetrisJ: '#000006',
  12. tetrisL: '#000007',
  13. };
  14. test('constructor', () => {
  15. expect(() => new BaseShape()).toThrow(Error);
  16. let T = new ShapeI(colors);
  17. expect(T.position.y).toBe(0);
  18. expect(T.position.x).toBe(3);
  19. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
  20. expect(T.getColor()).toBe(colors.tetrisI);
  21. });
  22. test('move', () => {
  23. let T = new ShapeI(colors);
  24. T.move(0, 1);
  25. expect(T.position.x).toBe(3);
  26. expect(T.position.y).toBe(1);
  27. T.move(1, 0);
  28. expect(T.position.x).toBe(4);
  29. expect(T.position.y).toBe(1);
  30. T.move(1, 1);
  31. expect(T.position.x).toBe(5);
  32. expect(T.position.y).toBe(2);
  33. T.move(2, 2);
  34. expect(T.position.x).toBe(7);
  35. expect(T.position.y).toBe(4);
  36. T.move(-1, -1);
  37. expect(T.position.x).toBe(6);
  38. expect(T.position.y).toBe(3);
  39. });
  40. test('rotate', () => {
  41. let T = new ShapeI(colors);
  42. T.rotate(true);
  43. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
  44. T.rotate(true);
  45. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[2]);
  46. T.rotate(true);
  47. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[3]);
  48. T.rotate(true);
  49. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
  50. T.rotate(false);
  51. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[3]);
  52. T.rotate(false);
  53. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[2]);
  54. T.rotate(false);
  55. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[1]);
  56. T.rotate(false);
  57. expect(T.getCurrentShape()).toStrictEqual(T.getShapes()[0]);
  58. });
  59. test('getCellsCoordinates', () => {
  60. let T = new ShapeI(colors);
  61. expect(T.getCellsCoordinates(false)).toStrictEqual([
  62. {x: 0, y: 1},
  63. {x: 1, y: 1},
  64. {x: 2, y: 1},
  65. {x: 3, y: 1},
  66. ]);
  67. expect(T.getCellsCoordinates(true)).toStrictEqual([
  68. {x: 3, y: 1},
  69. {x: 4, y: 1},
  70. {x: 5, y: 1},
  71. {x: 6, y: 1},
  72. ]);
  73. T.move(1, 1);
  74. expect(T.getCellsCoordinates(false)).toStrictEqual([
  75. {x: 0, y: 1},
  76. {x: 1, y: 1},
  77. {x: 2, y: 1},
  78. {x: 3, y: 1},
  79. ]);
  80. expect(T.getCellsCoordinates(true)).toStrictEqual([
  81. {x: 4, y: 2},
  82. {x: 5, y: 2},
  83. {x: 6, y: 2},
  84. {x: 7, y: 2},
  85. ]);
  86. T.rotate(true);
  87. expect(T.getCellsCoordinates(false)).toStrictEqual([
  88. {x: 2, y: 0},
  89. {x: 2, y: 1},
  90. {x: 2, y: 2},
  91. {x: 2, y: 3},
  92. ]);
  93. expect(T.getCellsCoordinates(true)).toStrictEqual([
  94. {x: 6, y: 1},
  95. {x: 6, y: 2},
  96. {x: 6, y: 3},
  97. {x: 6, y: 4},
  98. ]);
  99. });