Skip to content

Commit 9333f71

Browse files
committed
test: add tests for DataType instances
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 92e6653 commit 9333f71

1 file changed

Lines changed: 69 additions & 2 deletions

File tree

  • lib/node_modules/@stdlib/ndarray/base/dtype-char/test

lib/node_modules/@stdlib/ndarray/base/dtype-char/test/test.js

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
// MODULES //
2222

2323
var tape = require( 'tape' );
24+
var DataType = require( '@stdlib/ndarray/dtype-ctor' );
25+
var structFactory = require( '@stdlib/dstructs/struct' );
2426
var dtypeChar = require( './../lib' );
2527

2628

@@ -91,7 +93,7 @@ tape( 'the function returns an object mapping data type strings to single letter
9193
t.end();
9294
});
9395

94-
tape( 'the function returns the single letter character abbreviation for an underlying array data type', function test( t ) {
96+
tape( 'the function returns the single letter character abbreviation for an underlying array data type (data type string)', function test( t ) {
9597
var expected;
9698
var ch;
9799
var i;
@@ -123,8 +125,73 @@ tape( 'the function returns the single letter character abbreviation for an unde
123125
t.end();
124126
});
125127

128+
tape( 'the function returns the single letter character abbreviation for an underlying array data type (data type instance)', function test( t ) {
129+
var expected;
130+
var dtypes;
131+
var ch;
132+
var i;
133+
134+
dtypes = [
135+
'float64',
136+
'float32',
137+
'float16',
138+
'int8',
139+
'uint8',
140+
'uint8c',
141+
'int16',
142+
'uint16',
143+
'int32',
144+
'uint32',
145+
'binary',
146+
'generic',
147+
'complex32',
148+
'complex64',
149+
'complex128',
150+
'bool'
151+
];
152+
153+
expected = [
154+
'd',
155+
'f',
156+
'h',
157+
's',
158+
'b',
159+
'a',
160+
'k',
161+
't',
162+
'i',
163+
'u',
164+
'r',
165+
'o',
166+
'j',
167+
'c',
168+
'z',
169+
'x'
170+
];
171+
for ( i = 0; i < dtypes.length; i++ ) {
172+
ch = dtypeChar( new DataType( dtypes[ i ] ) );
173+
t.strictEqual( ch, expected[ i ], 'returns '+expected[i]+' when provided '+dtypes[i] );
174+
}
175+
t.end();
176+
});
177+
126178
tape( 'the function returns `null` if provided an unknown/unsupported data type', function test( t ) {
127-
var ch = dtypeChar( 'foobar' );
179+
var schema;
180+
var ch;
181+
182+
ch = dtypeChar( 'foobar' );
183+
t.strictEqual( ch, null, 'returns expected value' );
184+
185+
schema = [
186+
{
187+
'name': 'foo',
188+
'type': 'float64'
189+
}
190+
];
191+
ch = dtypeChar( structFactory( schema ) );
192+
t.strictEqual( ch, null, 'returns expected value' );
193+
194+
ch = dtypeChar( new DataType( structFactory( schema ) ) );
128195
t.strictEqual( ch, null, 'returns expected value' );
129196
t.end();
130197
});

0 commit comments

Comments
 (0)