All files / src/functions/convertXYZ xyz2Glyphs.spec.ts

100% Statements 41/41
100% Branches 7/7
100% Functions 0/0
100% Lines 41/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 41 42 43 44 45 461x   1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 12x 1x 1x   1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x  
import { describe, expect, test } from 'vitest';
 
import { xyz2Glyphs } from './xyz2Glyphs';
import type { VoxelCoordinates } from '@/types/voxelTypes';
 
describe('XYZ to Glyphs', () => {
  describe('output', () => {
    const xyz: VoxelCoordinates = {
      VoxelX: 1110,
      VoxelY: 86,
      VoxelZ: 291,
      PlanetIndex: 0,
      SolarSystemIndex: 564,
    };
    test('output is exactly 12 chars', () => {
      const coords = xyz2Glyphs(xyz);
      expect(coords.split('').length).toBe(12);
    });
    test('output contains only valid chars', () => {
      const coords = xyz2Glyphs(xyz);
      const validChars = '1234567890abcdef';
      for (const coord of coords.split('')) {
        expect(validChars.includes(coord.toLocaleLowerCase())).toBe(true);
      }
    });
  });
 
  describe('conversions', () => {
    test.each([
      [1110, 86, 291, 0, 564, '023456123456'],
      [563, 86, 1861, 0, 564, '023456745233'],
      [72, 4, -2013, 0, 2083, '082304823048'],
    ])('convert { x:%s, y:%s, z:%s, pi:%s, ssi:%s } to glyphs', (x, y, z, pi, ssi, g) => {
      const xyz: VoxelCoordinates = {
        VoxelX: x,
        VoxelY: y,
        VoxelZ: z,
        PlanetIndex: pi,
        SolarSystemIndex: ssi,
      };
      const coords = xyz2Glyphs(xyz);
      expect(coords).toBe(g);
    });
  });
});