File: tests.js

package info (click to toggle)
node-assert 2.0.0%2B~cs3.9.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 496 kB
  • sloc: javascript: 4,088; makefile: 8
file content (40 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';

module.exports = function (numberIsNaN, t) {
	t.test('not NaN', function (st) {
		st.test('primitives', function (sst) {
			sst.notOk(numberIsNaN(), 'undefined is not NaN');
			sst.notOk(numberIsNaN(null), 'null is not NaN');
			sst.notOk(numberIsNaN(false), 'false is not NaN');
			sst.notOk(numberIsNaN(true), 'true is not NaN');
			sst.notOk(numberIsNaN(0), 'positive zero is not NaN');
			sst.notOk(numberIsNaN(Infinity), 'Infinity is not NaN');
			sst.notOk(numberIsNaN(-Infinity), '-Infinity is not NaN');
			sst.notOk(numberIsNaN('foo'), 'string is not NaN');
			sst.notOk(numberIsNaN('NaN'), 'string NaN is not NaN');
			sst.end();
		});

		st.notOk(numberIsNaN([]), 'array is not NaN');
		st.notOk(numberIsNaN({}), 'object is not NaN');
		st.notOk(numberIsNaN(function () {}), 'function is not NaN');

		st.test('valueOf', function (vt) {
			var obj = {
				valueOf: function () {
					return NaN;
				}
			};
			vt.ok(numberIsNaN(Number(obj)), 'object with valueOf of NaN, converted to Number, is NaN');
			vt.notOk(numberIsNaN(obj), 'object with valueOf of NaN is not NaN');
			vt.end();
		});

		st.end();
	});

	t.test('NaN literal', function (st) {
		st.ok(numberIsNaN(NaN), 'NaN is NaN');
		st.end();
	});
};