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

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