Skip to content

Commit

Permalink
docs: update examples and rearrange tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed Mar 25, 2024
1 parent e459df4 commit ac93021
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Collection } from '@stdlib/types/array';
* @param x - value at which to evaluate a polynomial
* @returns evaluated polynomial
*/
type EvaluationFunction = ( x: number ) => number;
type PolynomialFunction = ( x: number ) => number;

/**
* Interface for evaluating polynomials.
Expand All @@ -49,7 +49,7 @@ interface EvalPoly {
* @returns evaluated polynomial
*
* @example
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* var v = evalpoly( [ 3.0, 2.0, 1.0 ], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*/
( c: Collection<number>, x: number ): number;
Expand All @@ -68,15 +68,15 @@ interface EvalPoly {
* @returns function for evaluating a polynomial
*
* @example
* var polyval = evalpoly.factory( [3.0,2.0,1.0] );
* var polyval = evalpoly.factory( [ 3.0, 2.0, 1.0 ] );
*
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*
* v = polyval( 5.0 ); // => 3*5^0 + 2*5^1 + 1*5^2
* // returns 38.0
*/
factory( c: Collection<number> ): EvaluationFunction;
factory( c: Collection<number> ): PolynomialFunction;
}

/**
Expand All @@ -94,11 +94,11 @@ interface EvalPoly {
* @returns evaluated polynomial
*
* @example
* var v = evalpoly( [3.0,2.0,1.0], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* var v = evalpoly( [ 3.0, 2.0, 1.0 ], 10.0 ); // 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
*
* @example
* var polyval = evalpoly.factory( [3.0,2.0,1.0] );
* var polyval = evalpoly.factory( [ 3.0, 2.0, 1.0 ] );
*
* var v = polyval( 10.0 ); // => 3*10^0 + 2*10^1 + 1*10^2
* // returns 123.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,17 @@ import evalpoly = require( './index' );
// Attached to main export is a `factory` method which returns a function...
{
const c = [ 3.0, 2.0, 1.0 ];
evalpoly.factory( c ); // $ExpectType EvaluationFunction
evalpoly.factory( c ); // $ExpectType PolynomialFunction
}

// The compiler throws an error if the `factory` method is provided a first argument which is not an array of numbers...
{
evalpoly.factory( true ); // $ExpectError
evalpoly.factory( false ); // $ExpectError
evalpoly.factory( 'abc' ); // $ExpectError
evalpoly.factory( 123 ); // $ExpectError
evalpoly.factory( {} ); // $ExpectError
evalpoly.factory( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the `factory` method is provided an unsupported number of arguments...
Expand All @@ -74,7 +84,7 @@ import evalpoly = require( './index' );
polyval( 1.0 ); // $ExpectType number
}

// The `factory` method returns a function which does not compile if provided a first argument which is not a number...
// The compiler throws an error if the function returned by the `factory` method is provided a first argument which is not a number...
{
const c = [ 3.0, 2.0, 1.0 ];
const polyval = evalpoly.factory( c );
Expand All @@ -85,13 +95,3 @@ import evalpoly = require( './index' );
polyval( {} ); // $ExpectError
polyval( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the `factory` method is provided a first argument which is not an array of numbers...
{
evalpoly.factory( true ); // $ExpectError
evalpoly.factory( false ); // $ExpectError
evalpoly.factory( 'abc' ); // $ExpectError
evalpoly.factory( 123 ); // $ExpectError
evalpoly.factory( {} ); // $ExpectError
evalpoly.factory( ( x: number ): number => x ); // $ExpectError
}

0 comments on commit ac93021

Please sign in to comment.