|
| 1 | +import test from 'ava' |
| 2 | +import path from 'path' |
| 3 | + |
| 4 | +const IntTypes = require(path.resolve(__dirname, '..', 'dist', 'IntTypes.js')) |
| 5 | +const FloatTypes = require(path.resolve(__dirname, '..', 'dist', 'FloatTypes.js')) |
| 6 | +const PixelTypes = require(path.resolve(__dirname, '..', 'dist', 'PixelTypes.js')) |
| 7 | +const readImageLocalFile = require(path.resolve(__dirname, '..', 'dist', 'readImageLocalFile.js')) |
| 8 | +const readMeshLocalFile = require(path.resolve(__dirname, '..', 'dist', 'readMeshLocalFile.js')) |
| 9 | +const writeLocalFileSync = require(path.resolve(__dirname, '..', 'dist', 'writeLocalFileSync.js')) |
| 10 | + |
| 11 | +const testImageInputFilePath = path.resolve(__dirname, '..', 'build', 'ExternalData', 'test', 'Input', 'cthead1.png') |
| 12 | +const testImageOutputFilePath = path.resolve(__dirname, '..', 'build', 'Testing', 'Temporary', 'writeLocalFileSyncTest-cthead1.png') |
| 13 | +const testMeshInputFilePath = path.resolve(__dirname, '..', 'build', 'ExternalData', 'test', 'Input', 'cow.vtk') |
| 14 | +const testMeshOutputFilePath = path.resolve(__dirname, '..', 'build', 'Testing', 'Temporary', 'writeLocalFileSyncTest-cow.vtk') |
| 15 | + |
| 16 | +const verifyImage = (t, image) => { |
| 17 | + t.is(image.imageType.dimension, 2, 'dimension') |
| 18 | + t.is(image.imageType.componentType, IntTypes.UInt8, 'componentType') |
| 19 | + t.is(image.imageType.pixelType, PixelTypes.RGB, 'pixelType') |
| 20 | + t.is(image.imageType.components, 3, 'components') |
| 21 | + t.is(image.origin[0], 0.0, 'origin[0]') |
| 22 | + t.is(image.origin[1], 0.0, 'origin[1]') |
| 23 | + t.is(image.spacing[0], 1.0, 'spacing[0]') |
| 24 | + t.is(image.spacing[1], 1.0, 'spacing[1]') |
| 25 | + t.is(image.direction.getElement(0, 0), 1.0, 'direction (0, 0)') |
| 26 | + t.is(image.direction.getElement(0, 1), 0.0, 'direction (0, 1)') |
| 27 | + t.is(image.direction.getElement(1, 0), 0.0, 'direction (1, 0)') |
| 28 | + t.is(image.direction.getElement(1, 1), 1.0, 'direction (1, 1)') |
| 29 | + t.is(image.size[0], 256, 'size[0]') |
| 30 | + t.is(image.size[1], 256, 'size[1]') |
| 31 | + t.is(image.data.length, 196608, 'data.length') |
| 32 | +} |
| 33 | + |
| 34 | +test('writeLocalFileSync writes an image file path on the local filesystem', t => { |
| 35 | + return readImageLocalFile(testImageInputFilePath) |
| 36 | + .then(function (image) { |
| 37 | + const useCompression = false |
| 38 | + writeLocalFileSync(useCompression, image, testImageOutputFilePath) |
| 39 | + return readImageLocalFile(testImageOutputFilePath).then(function (image) { |
| 40 | + verifyImage(t, image) |
| 41 | + }) |
| 42 | + }) |
| 43 | +}) |
| 44 | + |
| 45 | +const verifyMesh = (t, mesh) => { |
| 46 | + t.is(mesh.meshType.dimension, 3) |
| 47 | + t.is(mesh.meshType.pointComponentType, FloatTypes.Float32) |
| 48 | + t.is(mesh.meshType.cellComponentType, IntTypes.UInt32) |
| 49 | + t.is(mesh.meshType.pointPixelType, 1) |
| 50 | + t.is(mesh.meshType.cellPixelType, 1) |
| 51 | + t.is(mesh.numberOfPoints, 2903) |
| 52 | + t.is(mesh.numberOfCells, 3263) |
| 53 | +} |
| 54 | + |
| 55 | +test('writeLocalFile writes a mesh file path on the local filesystem', (t) => { |
| 56 | + return readMeshLocalFile(testMeshInputFilePath) |
| 57 | + .then(function (mesh) { |
| 58 | + writeLocalFileSync(false, mesh, testMeshOutputFilePath) |
| 59 | + return readMeshLocalFile(testMeshOutputFilePath).then(function (mesh) { |
| 60 | + verifyMesh(t, mesh) |
| 61 | + }) |
| 62 | + }) |
| 63 | +}) |
0 commit comments