|
21 | 21 | // MODULES // |
22 | 22 |
|
23 | 23 | var tape = require( 'tape' ); |
| 24 | +var DataType = require( '@stdlib/ndarray-dtype-ctor' ); |
| 25 | +var structFactory = require( '@stdlib/dstructs-struct' ); |
24 | 26 | var dtypeChar = require( './../lib' ); |
25 | 27 |
|
26 | 28 |
|
@@ -91,7 +93,7 @@ tape( 'the function returns an object mapping data type strings to single letter |
91 | 93 | t.end(); |
92 | 94 | }); |
93 | 95 |
|
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 ) { |
95 | 97 | var expected; |
96 | 98 | var ch; |
97 | 99 | var i; |
@@ -123,8 +125,73 @@ tape( 'the function returns the single letter character abbreviation for an unde |
123 | 125 | t.end(); |
124 | 126 | }); |
125 | 127 |
|
| 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 | + |
126 | 178 | 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 ) ) ); |
128 | 195 | t.strictEqual( ch, null, 'returns expected value' ); |
129 | 196 | t.end(); |
130 | 197 | }); |
0 commit comments