<commit_before>'use strict'

var convert = require('../lib/base/convert')
var assert = require('assert')

var wrong = {
  header: {
    version: 0,
    payload: -1,
    ret: 0,
    controlflags: 0,
    size: 0,
    offset: 0
  },
  payload: ''
}

var withoutPayload = {
  header: {
    version: 0,
    payload: -1,
    ret: 0,
    controlflags: 0,
    size: 0,
    offset: 0
  }
}

var correct = {
  header: {
    version: 0,
    payload: 12,
    ret: 12,
    controlflags: 32,
    size: 12,
    offset: 0
  },
  payload: '      22.375'
}

describe('Convert Tests', function () {
  describe('preparePayload', function () {
    it('short convert true to the string "1"', function () {
      assert.equal(convert.preparePayload(true), '1')
    })

    it('short convert false to the string "0"', function () {
      assert.equal(convert.preparePayload(false), '0')
    })

    it('short convert 1 to the string "1"', function () {
      assert.equal(convert.preparePayload(1), '1')
    })

    it('short convert 0 to the string "0"', function () {
      assert.equal(convert.preparePayload(0), '0')
    })
  })

  describe('extractValue', function () {
    it('should extract the value from one correct and one wrong message', function (done) {
      var messages = [correct, wrong]
      convert.extractValue(function (err, result) {
        assert.equal(err, undefined)
        assert.equal(result, 22.375)
        done()
      })(null, messages)
    })

    it('should extract the value from one wrong and one correct message', function (done) {
      var messages = [wrong, correct]
      convert.extractValue(function (err, result) {
        assert.equal(err, undefined)
        assert.equal(result, 22.375)
        done()
      })(null, messages)
    })

    it('should extract the value from a message with undefined payload and one correct message', function (done) {
      var messages = [withoutPayload, correct]
      convert.extractValue(function (err, result) {
        assert.equal(err, undefined)
        assert.equal(result, 22.375)
        done()
      })(null, messages)
    })

    it('should retunrn null when message payload is null', function (done) {
      var messages = [{<commit_msg>Fixed typo<commit_after>'use strict'

var convert = require('../lib/base/convert')
var assert = require('assert')

var wrong = {
  header: {
    version: 0,
    payload: -1,
    ret: 0,
    controlflags: 0,
    size: 0,
    offset: 0
  },
  payload: ''
}

var withoutPayload = {
  header: {
    version: 0,
    payload: -1,
    ret: 0,
    controlflags: 0,
    size: 0,
    offset: 0
  }
}

var correct = {
  header: {
    version: 0,
    payload: 12,
    ret: 12,
    controlflags: 32,
    size: 12,
    offset: 0
  },
  payload: '      22.375'
}

describe('Convert Tests', function () {
  describe('preparePayload', function () {
    it('short convert true to the string "1"', function () {
      assert.equal(convert.preparePayload(true), '1')
    })

    it('short convert false to the string "0"', function () {
      assert.equal(convert.preparePayload(false), '0')
    })

    it('short convert 1 to the string "1"', function () {
      assert.equal(convert.preparePayload(1), '1')
    })

    it('short convert 0 to the string "0"', function () {
      assert.equal(convert.preparePayload(0), '0')
    })
  })

  describe('extractValue', function () {
    it('should extract the value from one correct and one wrong message', function (done) {
      var messages = [correct, wrong]
      convert.extractValue(function (err, result) {
        assert.equal(err, undefined)
        assert.equal(result, 22.375)
        done()
      })(null, messages)
    })

    it('should extract the value from one wrong and one correct message', function (done) {
      var messages = [wrong, correct]
      convert.extractValue(function (err, result) {
        assert.equal(err, undefined)
        assert.equal(result, 22.375)
        done()
      })(null, messages)
    })

    it('should extract the value from a message with undefined payload and one correct message', function (done) {
      var messages = [withoutPayload, correct]
      convert.extractValue(function (err, result) {
        assert.equal(err, undefined)
        assert.equal(result, 22.375)
        done()
      })(null, messages)
    })

    it('should return null when message payload is null', function (done) {
      var messages = [{
{'fraction_non_alphanumeric': 0.1360544217687075, 'fraction_numerical': 0.024489795918367346, 'mean_word_length': 2.6334431630971995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4359957', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1314, 'n_words': 399}