buscador-visual / source /tests /lib.test.js
Segizu's picture
Buscador Visual: b煤squeda por texto/imagen/regi贸n con SigLIP 2 en el navegador
d18636b verified
Raw History Blame Contribute Delete
880 Bytes
import { describe, it, expect } from 'vitest';
import { l2normalize, dot, rank, relativeBars, normRect, fitSize } from '../src/lib.js';
describe('lib', () => {
it('normaliza', () => { const v = l2normalize([3, 4]); expect(v[0]).toBeCloseTo(0.6); expect(dot(v, v)).toBeCloseTo(1); });
it('rank ordena y excluye', () => {
const vs = [[1, 0], [0, 1], [0.7, 0.7]].map(l2normalize);
const r = rank(l2normalize([1, 0.1]), vs, 2, 0);
expect(r.map((x) => x.index)).toEqual([2, 1]);
});
it('barras relativas', () => { const b = relativeBars([{ score: 0.2 }, { score: 0.1 }]); expect(b[0].bar).toBe(1); expect(b[1].bar).toBe(0); });
it('rect normalizado', () => { expect(normRect(0.8, 1.2, 0.2, -0.1)).toEqual([0.2, 0, 0.8, 1]); });
it('fitSize', () => { expect(fitSize(1280, 960, 640)).toEqual([640, 480]); expect(fitSize(100, 50, 640)).toEqual([100, 50]); });
});