5180 fichiers 38.5 Mo 0 téléchargements 231 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / api / wired / WiredNeighborhood.test.ts
WiredNeighborhood.test.ts 1.2 Ko Télécharger le fichier
import { describe, expect, it } from 'vitest';
import { decodeNeighborhood, encodeNeighborhood, NEIGHBORHOOD_MASK_INTS, neighborhoodFitsSmall } from './WiredNeighborhood';

describe('WiredNeighborhood', () =>
{
    it('walks the spiral like the official client (and the server)', () =>
    {
        // Ranks 0..4: (0,0), (1,0), (1,-1), (0,-1), (-1,-1) -> the lowest five bits.
        const mask = encodeNeighborhood([ { x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: -1 }, { x: 0, y: -1 }, { x: -1, y: -1 } ]);

        expect(NEIGHBORHOOD_MASK_INTS).toBe(14);
        expect(mask[0]).toBe(31);
        expect(mask.slice(1).every(value => value === 0)).toBe(true);
    });

    it('round-trips a drawing and drops tiles off the floor', () =>
    {
        const decoded = decodeNeighborhood(encodeNeighborhood([ { x: 10, y: 10 }, { x: -10, y: 3 }, { x: 11, y: 0 } ]));

        expect(decoded).toHaveLength(2);
        expect(decoded).toContainEqual({ x: 10, y: 10 });
        expect(decoded).toContainEqual({ x: -10, y: 3 });
    });

    it('knows when the drawing fits the small view', () =>
    {
        expect(neighborhoodFitsSmall([ { x: 5, y: -5 } ])).toBe(true);
        expect(neighborhoodFitsSmall([ { x: 6, y: 0 } ])).toBe(false);
    });
});
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser