A web application designed to help weightlifters calculate optimal plate distribution for their target lifting weight. This tool simplifies the process of determining which plates to load on each side of the barbell, taking into account available equipment and bar weight.
Live Demo: https://barbell-math-machine.netlify.app/
The Barbell Math Machine solves a common problem in weightlifting: quickly calculating how to load a barbell to achieve a specific target weight. Users input their desired weight, select their bar type, and specify which plates are available at their gym. The application then calculates the optimal distribution of plates needed on each side of the bar using a greedy algorithm approach.
- Target Weight Input: Enter the total weight you want to lift
- Bar Weight Selection: Choose from common bar weights (15#, 35#, 45#, 58#, 65#)
- Customizable Plate Availability: Select which plates your gym has available using checkboxes:
- 45# plates
- 35# plates
- 25# plates
- 15# plates
- 10# plates
- 5# plates
- 2.5# plates
- 1.25# plates
- Automatic Calculation: Displays weight per side and optimal plate distribution
- Real-time Results: See the quantity of each plate type needed per side
- React 19.0.0 - UI framework
- Vite 6.3.6 - Build tool and development server
- Bootstrap 5.3.3 - CSS framework for styling
- JavaScript (ES6+) - Core programming language
- Jest 30.2.0 - Testing framework
- React Testing Library - Component testing utilities
barbell-math-vite/
├── src/
│ ├── barbellMath.js # Core calculation logic
│ ├── barbellMath.test.js # Unit tests for calculations
│ ├── App.jsx # Main App component
│ ├── App.test.jsx # App component tests
│ ├── main.jsx # React entry point
│ ├── init.js # Initialization script
│ └── init.test.js # Init script tests
├── __mocks__/
│ └── styleMock.js # CSS module mock for tests
├── index.html # Main HTML template
├── package.json # Dependencies and scripts
├── vite.config.js # Vite configuration
├── jest.config.cjs # Jest configuration
├── babel.config.cjs # Babel configuration for tests
└── jest.setup.js # Jest setup file
The application uses a greedy algorithm to calculate the optimal plate distribution:
- Calculates the total weight to add (target weight - bar weight)
- Divides by 2 to get weight per side
- Filters plates based on user-selected availability
- Iterates through available plates in descending order
- For each plate weight, calculates the maximum quantity that can be used
- Continues with remaining weight until fully distributed
This approach ensures the most efficient use of larger plates first, minimizing the total number of plates needed.
- Node.js (version 14 or higher)
- npm or yarn package manager
- Clone the repository:
git clone <repository-url>
cd barbell-math-vite- Install dependencies:
npm install- Start the development server:
npm run dev- Open your browser and navigate to
http://localhost:5173
npm run dev- Start development server with hot module replacementnpm run build- Build for productionnpm run preview- Preview production build locallynpm run lint- Run ESLint to check code qualitynpm test- Run all tests oncenpm run test:watch- Run tests in watch mode (re-runs on file changes)npm run test:coverage- Run tests with coverage report
- Enter Target Weight: Input the total weight you want to lift in the "Target Weight" field
- Select Bar Weight: Choose your barbell weight from the dropdown menu
- Select Available Plates: Check the boxes next to the plate weights available at your gym
- Click Calculate: Press the "Calculate" button to see results
- View Results:
- The "Weight Per Side" field shows how much weight to add to each side
- The table displays the quantity of each plate type needed per side
- Target Weight: 225#
- Bar Weight: 45#
- Available Plates: All checked
- Result: 90# per side
- 2x 45# plates
- 0x 35# plates
- 0x 25# plates
- 0x 15# plates
- 0x 10# plates
- 0x 5# plates
- 0x 2.5# plates
- 0x 1.25# plates
The project includes a comprehensive test suite built with Jest and React Testing Library, ensuring code reliability and maintainability.
The test suite includes 25 tests with 89.28% code coverage:
-
barbellMath.js (96.07% coverage)
- 23 unit tests covering calculation functions
- Tests for multiple bar weights (15#, 35#, 45#, 58#, 65#)
- Edge case handling (invalid inputs, decimal weights, zero values)
- Greedy algorithm validation
- Plate selection filtering
-
App.jsx (100% coverage)
- Component rendering tests
-
init.js (tested indirectly)
- Event listener attachment
- DOM initialization
# Run all tests once
npm test
# Run tests in watch mode (recommended during development)
npm run test:watch
# Generate coverage report
npm run test:coverageEach source file has a corresponding test file:
barbellMath.js→barbellMath.test.jsApp.jsx→App.test.jsxinit.js→init.test.js
Tests use Jest's describe and test blocks for clear organization and include:
- Setup using
beforeEachhooks for DOM elements - Comprehensive assertions using Jest matchers
- DOM manipulation testing with jsdom environment
The project uses ESLint for code quality and consistency. Configuration includes:
- React-specific rules
- React Hooks linting
- React Refresh for fast development
To create a production build:
npm run buildThis generates optimized static files in the dist/ directory ready for deployment.
This application works on all modern browsers that support ES6+ JavaScript features.
Contributions are welcome! Please ensure your code follows the existing style and passes all linting checks.
This project is private and not currently licensed for public distribution.
Potential features for future development:
- Support for kilogram weights
- Plate visualization
- Save/load custom gym equipment configurations
- Mobile-responsive design improvements
- Progressive Web App (PWA) capabilities