Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

48 Zeilen
1.6 KiB

  1. /* eslint-env node, mocha */
  2. import { expect } from 'chai';
  3. import * as models from './data';
  4. import regression from '../src/regression';
  5. const { _round } = regression;
  6. describe('round', () => {
  7. it('rounds to the correct precision', () => {
  8. expect(_round(0.33333333333333333333, 9)).to.equal(0.333333333);
  9. });
  10. });
  11. describe('models', () => {
  12. Object.keys(models).forEach((model) => {
  13. describe(model, () => {
  14. Object.keys(models[model]).forEach((name) => {
  15. const example = models[model][name];
  16. describe(name, () => {
  17. it(`correctly predicts ${name}`, () => {
  18. let result = regression[model](example.data, example.config);
  19. delete result.predict;
  20. expect(result).to.deep.equal({
  21. r2: example.r2,
  22. string: example.string,
  23. points: example.points,
  24. equation: example.equation,
  25. });
  26. });
  27. it('should correctly forecast data points', () => {
  28. const result = regression[model](example.data, example.config);
  29. expect(result.predict(example.predicted[0])).to.deep.equal(example.predicted);
  30. });
  31. it('should take precision options', () => {
  32. const notSpecified = regression[model](example.data, example.config);
  33. const specified = regression[model](example.data, { ...example.config, precision: 4 });
  34. expect(specified.equation).to.deep.equal(example.equation.map(v => _round(v, 4)));
  35. expect(notSpecified.equation).to.deep.equal(example.equation.map(v => _round(v, 2)));
  36. });
  37. });
  38. });
  39. });
  40. });
  41. });