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.8KB

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