blob: 4b4c153085f8d70fc81a08c955d7ff3302c929eb [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// 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});