blob: 88e1df0cac76daee411a0db9ce54aa5957d85b0e [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2019 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {assert} from 'chai';
6import {linearRegression} from './math.js';
7
8describe('linearRegression', () => {
9 it('calculate slope and intercept using formula', () => {
10 const values = [0, 1, 2, 3, 4, 5, 6];
11 const [slope, intercept] = linearRegression(values, 7);
12 assert.equal(slope, 1);
13 assert.equal(intercept, 0);
14 });
15
16 it('calculate slope and intercept using last n data points', () => {
17 const values = [0, 1, 0, 3, 5, 7, 9];
18 const [slope, intercept] = linearRegression(values, 4);
19 assert.equal(slope, 2);
20 assert.equal(intercept, 3);
21 });
22});