Skip to content

Commit

Permalink
add blocks.turnOnce and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nek0meshi committed Oct 30, 2022
1 parent 493d496 commit 81edad5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
20 changes: 13 additions & 7 deletions frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
// import React from 'react';
// import { render, screen } from '@testing-library/react';
// import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
// // test('renders learn react link', () => {
// // render(<App />);
// // const linkElement = screen.getByText(/learn react/i);
// // expect(linkElement).toBeInTheDocument();
// // });

test('example', () => {
expect(1 + 1).toBe(2);
});

export {};
25 changes: 25 additions & 0 deletions frontend/src/features/blocks/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as block from './index';

test('turnOnce', () => {
const dataSet: [number, number, number, number, number, number][] = [
// centerが0だった場合
[1, 1, 0, 0, 1, -1],
[-1, -1, 0, 0, -1, 1],
[2, -1, 0, 0, -1, -2],
[-1, 3, 0, 0, 3, 1],

// centerが0以外の場合
[4, 4, 3, 3, 4, 2],
[2, 2, 3, 3, 2, 4],

[0, 0, 0.5, 0.5, 0, 1],
[1, 1, 0.5, 0.5, 1, 0],
];

for (const [x, y, centerX, centerY, resultX, resultY] of dataSet) {
expect(block.turnOnce(x, y, centerX, centerY)).toStrictEqual([
resultX,
resultY,
]);
}
});
11 changes: 11 additions & 0 deletions frontend/src/features/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export type BlockShapeType = Readonly<{
}>;
}>;

export type MoveType = 'left' | 'right' | 'turn';

export type Turn = 0 | 1 | 2 | 3;

export const BLOCK_TYPES: Readonly<BlockType[]> = [
'i',
'o',
Expand Down Expand Up @@ -149,3 +153,10 @@ export const getNextBlock = (
y: fallingBlock.y - 1,
};
};

export const turnOnce = (
x: number,
y: number,
centerX: number,
centerY: number
) => [centerX + y - centerY, centerY - (x - centerX)];

0 comments on commit 81edad5

Please sign in to comment.