<commit_before>/* eslint-env mocha */
'use strict'

const assert = require('assert')
const { OrderBook } = require('../../../lib/models')

describe('OrderBook model', () => {
  it('constructor: integrates snapshot', () => {
    const entries = [
      [100, 2, 10],
      [200, 2, -10]
    ]

    const ob = new OrderBook(entries)

    assert.deepEqual(ob.bids, [entries[0]])
    assert.deepEqual(ob.asks, [entries[1]])
  })

  it('updateWith: correctly applies update', () => {
    const entries = [
      [100, 2, 10],
      [200, 2, -10]
    ]

    const ob = new OrderBook(entries)
    ob.updateWith([100, 3, 15])

    assert.deepEqual(ob.bids[0], [100, 3, 15])
    assert.equal(ob.bids.length, 1)
<commit_msg>(feature) add ob checksum tests<commit_after>/* eslint-env mocha */
'use strict'

const assert = require('assert')
const CRC = require('crc-32')
const { OrderBook } = require('../../../lib/models')

describe('OrderBook model', () => {
  it('constructor: integrates snapshot', () => {
    const entries = [
      [100, 2, 10],
      [200, 2, -10]
    ]

    const ob = new OrderBook(entries)

    assert.deepEqual(ob.bids, [entries[0]])
    assert.deepEqual(ob.asks, [entries[1]])
  })

  it('checksum: returns expected value for normal OB', () => {
    const ob = new OrderBook({
      bids: [[6000, 1, 1], [5900, 1, 2]],
      asks: [[6100, 1, -3], [6200, 1, -4]]
    })

    assert.equal(ob.checksum(), CRC.str('6000:1:6100:-3:5900:2:6200:-4'))
  })

  it('checksum: returns expected value for raw OB', () => {
    const ob = new OrderBook({
      bids: [[100, 6000, 1], [101, 6000, 2]], // first field is order ID here
      asks: [[102, 6100, -3], [103, 6100, -4]]
    }, true)

    assert.equal(ob.checksum(), CRC.str('100:1:102:-3:101:2:103:-4'))
  })

  it('checksumArr: returns expected value for normal OB', () => {
    const ob = [
      [6000, 1, 1],
      [5900, 1, 2],
      [6100, 1, -3],
      [6200, 1, -4]
    ]

    assert.equal(
      OrderBook.checksumArr(ob),
      CRC.str('6000:1:6100:-3:5900:2:6200:-4')
    )
  })

  it('checksumArr: returns expected value for raw OB', () => {
    const ob = [
      [100, 6000, 1],
      [101, 6000, 2],
      [102, 6100, -3],
      [103, 6100, -4]
    ]

    assert.equal(
      OrderBook.checksumArr(ob, true),
      CRC.str('100:1:102:-3:101:2:103:-4')
    )
  })

  it('updateWith: correctly applies update', () => {
    const entries = [
      [100, 2, 10],
      [200, 2, -10]
    ]

    const ob = new OrderBook(entries)
    ob.updateWith([100, 3, 15])

    assert.deepEqual(ob.bids[0], [100, 3, 15])
    assert.equal(ob.bids.length, 1)

{'fraction_non_alphanumeric': 0.20244461420932008, 'fraction_numerical': 0.10160427807486631, 'mean_word_length': 2.6024759284731775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '98681', 'n_tokens_mistral': 1156, 'n_tokens_neox': 968, 'n_words': 231}