Skip to content

Commit

Permalink
E2E for path finder
Browse files Browse the repository at this point in the history
  • Loading branch information
sadanandpai committed Mar 29, 2024
1 parent 5988ca2 commit a022ba2
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 3 deletions.
46 changes: 46 additions & 0 deletions cypress/e2e/path-finder/home.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const mazes = [
'Prims',
'Kruskal',
'Recursive Backtracking',
'Recursive Division',
'Wilson',
'Binary',
'Ellers',
'Side Winder',
'Labyrinth',
];

const pathFinders = [
'Breadth First Search',
'Depth First Search',
'A* Search',
'Greedy Best First',
];

describe('path finder', () => {
beforeEach(() => {
cy.visit('/#/path-finder');
cy.viewport(1440, 900);
});

it('should verify the maze dropdowns', () => {
cy.get('#maze').should('contain.text', 'Select a Maze');

for (const maze of mazes) {
cy.get('#maze').should('contain.text', maze);
}
});

it('should verify the path finder dropdowns', () => {
cy.get('#path-finder').should('contain.text', 'Select a Path finder');

for (const pathFinder of pathFinders) {
cy.get('#path-finder').should('contain.text', pathFinder);
}
});

it('should verify the grid', () => {
cy.get('[data-cell-type="1"]').should('have.length', 1);
cy.get('[data-cell-type="2"]').should('have.length', 1);
});
});
81 changes: 81 additions & 0 deletions cypress/e2e/path-finder/maze.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
function verifyMaze() {
cy.get('[data-testid="generate-maze"]').click();
cy.get('[data-testid="generate-maze"]').should('be.enabled');

cy.get('[data-cell-type="1"]').should('have.length', 1);
cy.get('[data-cell-type="2"]').should('have.length', 1);
cy.get('[data-cell-type="0"]').should('have.length', 807);
cy.get('[data-cell-type="3"]').should('have.length', 728);
}

describe('path finder', () => {
beforeEach(() => {
cy.visit('/#/path-finder');
cy.viewport(1440, 900);

const generateMaze = cy.get('[data-testid="generate-maze"]');
generateMaze.should('be.visible');
generateMaze.should('be.disabled');
});

it('should verify the grid', () => {
cy.get('[data-cell-type="1"]').should('have.length', 1);
cy.get('[data-cell-type="2"]').should('have.length', 1);
});

it('should verify the prims maze generation', () => {
cy.get('#maze').select('Prims');
verifyMaze();
});

it('should verify the kruskal maze generation', () => {
cy.get('#maze').select('Kruskal');
verifyMaze();
});

it('should verify the recursive backtracking maze generation', () => {
cy.get('#maze').select('Recursive Backtracking');
verifyMaze();
});

it('should verify the recursive division maze generation', () => {
cy.get('#maze').select('Recursive Division');
verifyMaze();
});

it('should verify the wilson maze generation', () => {
cy.get('#maze').select('Wilson');
verifyMaze();
});

it('should verify the binary maze generation', () => {
cy.get('#maze').select('Binary');
verifyMaze();
});

it('should verify the ellers maze generation', () => {
cy.get('#maze').select('Ellers');
verifyMaze();
});

it('should verify the side winder maze generation', () => {
cy.get('#maze').select('Side Winder');
verifyMaze();
});

it('should verify the labyrinth maze generation', () => {
cy.get('#maze').select('Labyrinth');
verifyMaze();
});

it('should verify the random maze generation', () => {
cy.get('#maze').select('Random');
cy.get('[data-testid="generate-maze"]').click();
cy.get('[data-testid="generate-maze"]').should('be.enabled');

cy.get('[data-cell-type="1"]').should('have.length', 1);
cy.get('[data-cell-type="2"]').should('have.length', 1);
cy.get('[data-cell-type="0"]').should('have.length.greaterThan', 500);
cy.get('[data-cell-type="3"]').should('have.length.greaterThan', 100);
});
});
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/apps/path-finder/algorithms/path-finder/a-star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function exploreNeighbors(
}
}

// A* algoirthm
// A* algorithm
export async function aStar({
grid: stateGrid,
entry,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/path-finder/algorithms/path-finder/greedy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function exploreNeighbors(
}
}

// A* algoirthm
// Greedy best first search algorithm
export async function greedy({
grid: stateGrid,
entry,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/path-finder/components/controller/execution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Execution({ defaultSpeed }: Props) {
<select
className={classes.pathFinder}
name="path-finder"
id="maze"
id="path-finder"
value={pathFinder}
onChange={handleChange}
disabled={disabled}
Expand Down

0 comments on commit a022ba2

Please sign in to comment.