Menu

Importing My Own Calculator's Math Module in Node Found Two UI Bugs and No Math Bugs
πŸ“°

Importing My Own Calculator's Math Module in Node Found Two UI Bugs and No Math Bugs

DEV Community: nodeΒ·fei maiΒ·1 day ago
#bIWDJXww
#devtonodejs#devto#dev#angle#inputs
Reading 0:00
15s threshold

I could have reviewed this code by reading it. Instead I imported it and threw 67 inputs at it, which took about twenty minutes and turned up something reading would have missed.

The module is 264 lines of exact rational arithmetic over BigInt. It imports into Node with no DOM stub, no jsdom, nothing. That is the whole trick β€” pure functions deserve pure tests, and a calculator that keeps its maths separate from its buttons can be tested from a terminal.

The setup

import { parse , slopeFromPoints , slopeFromEquation , slopeFromRiseRun , proportionSolve } from './math.mjs' ;

Enter fullscreen mode

Exit fullscreen mode

Then a table of inputs, and a second implementation in Python using Fraction to recompute every answer from scratch.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.