chore: setup linting
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import { test, expect } from "vitest"
|
||||
import { encodeFloat, decodeFloat } from "./encoding"
|
||||
import { expect, test } from 'vitest';
|
||||
import { decodeFloat, encodeFloat } from './encoding';
|
||||
|
||||
test("encode_float", () => {
|
||||
test('encode_float', () => {
|
||||
const input = 1.23;
|
||||
const encoded = encodeFloat(input)
|
||||
const output = decodeFloat(encoded)
|
||||
console.log(input, output)
|
||||
const encoded = encodeFloat(input);
|
||||
const output = decodeFloat(encoded);
|
||||
console.log(input, output);
|
||||
expect(output).toBeCloseTo(input);
|
||||
});
|
||||
|
||||
test("encode 2.0", () => {
|
||||
test('encode 2.0', () => {
|
||||
const input = 2.0;
|
||||
const encoded = encodeFloat(input)
|
||||
expect(encoded).toEqual(1073741824)
|
||||
const encoded = encodeFloat(input);
|
||||
expect(encoded).toEqual(1073741824);
|
||||
});
|
||||
|
||||
test("floating point imprecision", () => {
|
||||
test('floating point imprecision', () => {
|
||||
let maxError = 0;
|
||||
new Array(10_000).fill(null).forEach((_, i) => {
|
||||
const input = i < 5_000 ? i : Math.random() * 100;
|
||||
@@ -32,7 +32,7 @@ test("floating point imprecision", () => {
|
||||
});
|
||||
|
||||
// Test with negative numbers
|
||||
test("negative numbers", () => {
|
||||
test('negative numbers', () => {
|
||||
const inputs = [-1, -0.5, -123.456, -0.0001];
|
||||
inputs.forEach(input => {
|
||||
const encoded = encodeFloat(input);
|
||||
@@ -42,31 +42,31 @@ test("negative numbers", () => {
|
||||
});
|
||||
|
||||
// Test with very small numbers
|
||||
test("very small numbers", () => {
|
||||
test('very small numbers', () => {
|
||||
const input = 1.2345e-38;
|
||||
const encoded = encodeFloat(input)
|
||||
const output = decodeFloat(encoded)
|
||||
const encoded = encodeFloat(input);
|
||||
const output = decodeFloat(encoded);
|
||||
expect(output).toBeCloseTo(input);
|
||||
});
|
||||
|
||||
// Test with zero
|
||||
test("zero", () => {
|
||||
test('zero', () => {
|
||||
const input = 0;
|
||||
const encoded = encodeFloat(input)
|
||||
const output = decodeFloat(encoded)
|
||||
const encoded = encodeFloat(input);
|
||||
const output = decodeFloat(encoded);
|
||||
expect(output).toBe(0);
|
||||
});
|
||||
|
||||
// Test with infinity
|
||||
test("infinity", () => {
|
||||
test('infinity', () => {
|
||||
const input = Infinity;
|
||||
const encoded = encodeFloat(input)
|
||||
const output = decodeFloat(encoded)
|
||||
const encoded = encodeFloat(input);
|
||||
const output = decodeFloat(encoded);
|
||||
expect(output).toBe(Infinity);
|
||||
});
|
||||
|
||||
// Test with large numbers
|
||||
test("large numbers", () => {
|
||||
test('large numbers', () => {
|
||||
const inputs = [1e+5, 1e+10];
|
||||
inputs.forEach(input => {
|
||||
const encoded = encodeFloat(input);
|
||||
|
||||
Reference in New Issue
Block a user