Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | // 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 | |
| 5 | import {assert} from 'chai'; |
| 6 | import {linearRegression} from './math.js'; |
| 7 | |
| 8 | describe('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 | }); |