/**
* @license Apache-2.0
*
* Copyright (c) 2018 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var randu = require( '@stdlib/random/base/randu' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var ceil = require( '@stdlib/math/base/special/ceil' );
var pkg = require( './../package.json' ).name;
var cceil = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
	var re;
	var im;
	var y;
	var i;

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		re = ( randu()*1000.0 ) - 500.0;
		im = ( randu()*1000.0 ) - 500.0;
		y = cceil( re, im );
		if ( y.length === 0 ) {
			b.fail( 'should not be empty' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+'::memory_reuse', function benchmark( b ) {
	var out;
	var re;
	var im;
	var y;
	var i;

	out = new Array( 2 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		re = ( randu()*1000.0 ) - 500.0;
		im = ( randu()*1000.0 ) - 500.0;
		y = cceil( out, re, im );
		if ( y.length === 0 ) {
			b.fail( 'should not be empty' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+'::manual', function benchmark( b ) {
	var re;
	var im;
	var y;
	var i;

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		re = ( randu()*1000.0 ) - 500.0;
		im = ( randu()*1000.0 ) - 500.0;
		y = [ ceil( re ), ceil( im ) ];
		if ( y.length === 0 ) {
			b.fail( 'should not be empty' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

bench( pkg+'::manual,memory_reuse', function benchmark( b ) {
	var re;
	var im;
	var y;
	var i;

	y = new Array( 2 );

	b.tic();
	for ( i = 0; i < b.iterations; i++ ) {
		re = ( randu()*1000.0 ) - 500.0;
		im = ( randu()*1000.0 ) - 500.0;
		y[ 0 ] = ceil( re );
		y[ 1 ] = ceil( im );
		if ( y.length === 0 ) {
			b.fail( 'should not be empty' );
		}
	}
	b.toc();
	if ( isnan( y ) ) {
		b.fail( 'should not return NaN' );
	}
	b.pass( 'benchmark finished' );
	b.end();
});

@@ -739,19 +739,21 @@
 ;%0Avar is
-nan
+Array
  = requi
@@ -765,26 +765,16 @@
 @stdlib/
-math/base/
 assert/i
@@ -775,19 +775,21 @@
 sert/is-
-nan
+array
 ' );%0Avar
@@ -1230,37 +1230,40 @@
 %09b.toc();%0A%09if ( 
+!
 is
-nan
+Array
 ( y ) ) %7B%0A%09%09b.fa
@@ -1270,38 +1270,39 @@
 il( 'should 
-not 
 return 
-NaN
+an array
 ' );%0A%09%7D%0A%09b.p
@@ -1694,37 +1694,40 @@
 %09b.toc();%0A%09if ( 
+!
 is
-nan
+Array
 ( y ) ) %7B%0A%09%09b.fa
@@ -1734,38 +1734,39 @@
 il( 'should 
-not 
 return 
-NaN
+an array
 ' );%0A%09%7D%0A%09b.p
@@ -2124,37 +2124,40 @@
 %09b.toc();%0A%09if ( 
+!
 is
-nan
+Array
 ( y ) ) %7B%0A%09%09b.fa
@@ -2164,38 +2164,39 @@
 il( 'should 
-not 
 return 
-NaN
+an array
 ' );%0A%09%7D%0A%09b.p
@@ -2613,13 +2613,16 @@
 f ( 
+!
 is
-nan
+Array
 ( y 
@@ -2649,22 +2649,23 @@
 uld 
-not 
 return 
-NaN
+an array
 ' );

Fix assertions