All files / src/polynomial/line line.ts

100% Statements 7/7
100% Branches 0/0
100% Functions 5/5
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27      6x 61x     5x       33x               13x       13x      
import { IPolynomial } from '../definition'
import { Root } from '../../root-finder'
 
export class Line implements IPolynomial {
  constructor(protected readonly m: number, protected readonly k: number) {}
 
  public calculate(x: number): number {
    return this.m * x + this.k
  }
 
  public findRoot(): Root {
    return {
      converged: true,
      iterations: 0,
      value: -this.k / this.m,
    }
  }
 
  public getK(): number {
    return this.k
  }
 
  public getM(): number {
    return this.m
  }
}