<commit_before>import { decode } from '../src/quasi-binary.js'
import test from 'ava'

function numberArray (min, max) {
  return [...Array(max + 1 - min).keys()].map(v => Number(v + min))
}

test('quasi-binary:decodeOneSimple', t => {
  // Every byte value below 253
  const values = numberArray(0, 252)
  for (const value of values) t.true(value === decode([value])[0])
})

test('quasi-binary:decodeOneComplex', t => {
  // The special >= 253 cases
  t.is(decode([253, 0])[0], 253)
  t.is(decode([253, 1])[0], 254)
  t.is(decode([253, 2])[0], 255)
})

test('quasi-binary:decodeMultiple', t => {
  // Just random things in a random order
  const decoded = Buffer.from([15, 0, 35, 255, 240, 254, 123, 9, 253, 0, 1])
  const encoded = [15, 0, 35, 253, 2, 240, 253, 1, 123, 9, 253, 0, 0, 1]

  t.true(decode(encoded).equals(decoded))

  // All values: 0..252, 253, 0, 253, 1, 253, 2 (encoded) or 0..255 (decoded)
  const decoded2 = Buffer.from(numberArray(0, 255))
  const encoded2 = numberArray(0, 258)
  encoded2[254] = 0
  encoded2[255] = 253
  encoded2[256] = 1
  encoded2[257] = 253
  encoded2[258] = 2

  t.true(decode(encoded2).equals(decoded2))
})

test('quasi-binary:error:inputOverflow', t => {
  // Test all overflowing values: 254, 255
  t.is(decode([254]), 'inputOverflow')
  t.is(decode([255]), 'inputOverflow')
})

test('quasi-binary:error:outputOverflow', t => {
  // Test all overflowing values: 3..255
  const overflowing = numberArray(3, 255)

  for (const val of overflowing) {
    t.is(decode([253, val]), 'outputOverflow')
  }
})<commit_msg>Fix Quasi Binary error tests<commit_after>import { decode } from '../src/quasi-binary.js'
import test from 'ava'

function numberArray (min, max) {
  return [...Array(max + 1 - min).keys()].map(v => Number(v + min))
}

test('quasi-binary:decodeOneSimple', t => {
  // Every byte value below 253
  const values = numberArray(0, 252)
  for (const value of values) t.true(value === decode([value])[0])
})

test('quasi-binary:decodeOneComplex', t => {
  // The special >= 253 cases
  t.is(decode([253, 0])[0], 253)
  t.is(decode([253, 1])[0], 254)
  t.is(decode([253, 2])[0], 255)
})

test('quasi-binary:decodeMultiple', t => {
  // Just random things in a random order
  const decoded = Buffer.from([15, 0, 35, 255, 240, 254, 123, 9, 253, 0, 1])
  const encoded = [15, 0, 35, 253, 2, 240, 253, 1, 123, 9, 253, 0, 0, 1]

  t.true(decode(encoded).equals(decoded))

  // All values: 0..252, 253, 0, 253, 1, 253, 2 (encoded) or 0..255 (decoded)
  const decoded2 = Buffer.from(numberArray(0, 255))
  const encoded2 = numberArray(0, 258)
  encoded2[254] = 0
  encoded2[255] = 253
  encoded2[256] = 1
  encoded2[257] = 253
  encoded2[258] = 2

  t.true(decode(encoded2).equals(decoded2))
})

test('quasi-binary:error:inputOverflow', t => {
  // Test all overflowing values: 254, 255
  t.throws(() => decode([254]), 'inputOverflow')
  t.throws(() => decode([255]), 'inputOverflow')
})

test('quasi-binary:error:outputOverflow', t => {
  // Test all overflowing values: 3..255
  const overflowing = numberArray(3, 255)

  for (const val of overflowing) {
    t.throws(() => decode([253, val]), 'outputOverflow')
  }
})
{'fraction_non_alphanumeric': 0.19008525418377012, 'fraction_numerical': 0.10672560783075466, 'mean_word_length': 3.9577464788732395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6471363', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1148, 'n_words': 313}