<commit_before>'use strict';

// MODULES //

var tape = require( 'tape' );
var linspace = require( '@stdlib/math/utils/linspace' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var cos = require( '@stdlib/math/base/special/cos' );
var PINF = require( '@stdlib/math/constants/float64-pinf' );
var NINF = require( '@stdlib/math/constants/float64-ninf' );
var EPS = require( '@stdlib/math/constants/float64-eps' );
var PI = require( '@stdlib/math/constants/float64-pi' );
var cosm1 = require( './../lib' );


// VARIABLES //

var NPIO4 = -7.85398163397448309616e-1; // -4/pi
var PIO4 = 7.85398163397448309616e-1; // 4/pi


// FIXTURES //

var data = require( './fixtures/python/data.json' );


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.equal( typeof cos, 'function', 'main export is a function' );
	t.end();
});

tape( 'the function computes the cosine minues one more accurately inside the interval [-pi/4,pi/4]', function test( t ) {
	var expected;
	var delta;
	var tol;
	var x;
	var y;
	var i;

	x = data.x;
	expected = data.expected;

	for ( i = 0; i < x.length; i++ ) {
		y = cosm1( x[i] );
		if ( y === expected[ i ] ) {
			t.equal( y, expected[ i ], 'x: '+x[i]+'. Expected: '+expected[i] );
		} else {
			delta = abs( y - expected[i] );
			tol = 2.0 * EPS * abs( expected[i] );
			t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected[i]+'. Tolerance: '+tol+'.' );
		}
	}

	t.end();
});

tape( 'the function computes `cos(x) - 1.0` outside the interval [-pi/4,pi/4]', function test( t ) {
	var expected;
	var delta;
	var tol;
	var x;
	var y;
	var i;

	x = linspace( PIO4, 4*PI, 100 );

	for ( i = 0; i < x.length; i++ ) {
		y = cosm1( x[i] );
		expected = cos( x[i] ) - 1;
		delta = abs( y - expected );
		tol = EPS * abs( expected );
		t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected+'. Tolerance: '+tol+'.' );
	}

	x = linspace( -4*PI, NPIO4, 100 );

	for ( i = 0; i < x.length; i++ ) {
		y = cosm1( x[i] );
		expected = cos( x[i] ) - 1.0;
		delta = abs( y - expected );
		tol = EPS * abs( expected );
		t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. Expected: '+expected+'. Tolerance: '+tol+'.' );
	}

	t.end();
});

tape( 'the function returns `NaN` if provided a `NaN`', function test( t ) {
	var v = cosm1( NaN );
	t.equal( isnan( v ), true, 'returns NaN' );<commit_msg>Print delta between actual and expected test output<commit_after>'use strict';

// MODULES //

var tape = require( 'tape' );
var linspace = require( '@stdlib/math/utils/linspace' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var abs = require( '@stdlib/math/base/special/abs' );
var cos = require( '@stdlib/math/base/special/cos' );
var PINF = require( '@stdlib/math/constants/float64-pinf' );
var NINF = require( '@stdlib/math/constants/float64-ninf' );
var EPS = require( '@stdlib/math/constants/float64-eps' );
var PI = require( '@stdlib/math/constants/float64-pi' );
var cosm1 = require( './../lib' );


// VARIABLES //

var NPIO4 = -7.85398163397448309616e-1; // -4/pi
var PIO4 = 7.85398163397448309616e-1; // 4/pi


// FIXTURES //

var data = require( './fixtures/python/data.json' );


// TESTS //

tape( 'main export is a function', function test( t ) {
	t.ok( true, __filename );
	t.equal( typeof cos, 'function', 'main export is a function' );
	t.end();
});

tape( 'the function computes the cosine minues one more accurately inside the interval [-pi/4,pi/4]', function test( t ) {
	var expected;
	var delta;
	var tol;
	var x;
	var y;
	var i;

	x = data.x;
	expected = data.expected;

	for ( i = 0; i < x.length; i++ ) {
		y = cosm1( x[i] );
		if ( y === expected[ i ] ) {
			t.equal( y, expected[ i ], 'x: '+x[i]+'. E: '+expected[i] );
		} else {
			delta = abs( y - expected[i] );
			tol = 2.0 * EPS * abs( expected[i] );
			t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected[i]+'. tol: '+tol+'. Δ: '+delta+'.');
		}
	}

	t.end();
});

tape( 'the function computes `cos(x) - 1.0` outside the interval [-pi/4,pi/4]', function test( t ) {
	var expected;
	var delta;
	var tol;
	var x;
	var y;
	var i;

	x = linspace( PIO4, 4*PI, 100 );

	for ( i = 0; i < x.length; i++ ) {
		y = cosm1( x[i] );
		expected = cos( x[i] ) - 1;
		delta = abs( y - expected );
		tol = EPS * abs( expected );
		t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected+'. tol: '+tol+'. Δ: '+delta+'.');
	}

	x = linspace( -4*PI, NPIO4, 100 );

	for ( i = 0; i < x.length; i++ ) {
		y = cosm1( x[i] );
		expected = cos( x[i] ) - 1.0;
		delta = abs( y - expected );
		tol = EPS * abs( expected );
		t.ok( delta <= tol, 'within tolerance. x: '+x[i]+'. Value: '+y+'. E: '+expected+'. tol: '+tol+'. Δ: '+delta+'.');
	}

	t.end();
});

tape( 'the function returns `NaN` if provided `NaN`', function test( t ) {
	var v = cosm1( NaN );
	t.equal( isnan( v ), true, 'returns NaN' );
{'fraction_non_alphanumeric': 0.21558079298665073, 'fraction_numerical': 0.033871289101414626, 'mean_word_length': 3.0451248992747786, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6887703', 'n_tokens_mistral': 2217, 'n_tokens_neox': 2012, 'n_words': 580}