<commit_before>var dat = require('dat-core')
var test = require('tape')
var batcher = require('byte-stream')
var memdb = require('memdb')
var diff = require('sorted-diff-stream')
var from = require('from2')

var createDatConflicts = require('./createDatConflicts.js')
var dough = require('../index.js')
var DATA = require('test-data')

var TABLES = DATA.CONFLICTS.SMALL

test('dat dough', function (t) {
  var db = dat(memdb(), {valueEncoding: 'json'})
  createDatConflicts(db, TABLES, function (heads) {
    var diffStream = db.createDiffStream(heads[0], heads[1])

    var opts = {
      rowPath: function (row) { return row['value'] }
    }
    var doughStream = dough(opts)

    doughStream.merge = function (output, visual, next) {
      var table1 = output.tables[0]
      var table2 = output.tables[1]
      console.log(visual)

      t.equals(table1.height, 3)
      t.equals(table2.height, 4)
      t.deepEquals(table1.columns, ['capital', 'country'])
      t.deepEquals(table2.columns, ['capital', 'code', 'country'])
      t.same(typeof visual, 'string')
      t.same(typeof next, 'function')
      t.end()
    }

    var batchStream = batcher(3 * 2)

    diffStream.pipe(batchStream).pipe(doughStream)
  })
})

test('dough from sorted-diff-stream', function (t) {
  function keyData (data) {
    var index = 0
    data.map(function (obj) {
      var rObj = {}
      rObj.key = index
      rObj.value = obj
      index++
      console.log(rObj)
      return rObj
    })
    return data
  }

  var older = from.obj(keyData(TABLES[1]))
  var newer = from.obj(keyData(TABLES[2]))

  var diffStream = diff(older, newer)

  diffStream.on('data', console.log)
  var doughStream = dough()

  doughStream.merge = function (output, visual, next) {
    var table1 = output.tables[0]
    var table2 = output.tables[1]
    console.log(visual)

    t.equals(table1.height, 3)
    t.equals(table2.height, 4)
    t.deepEquals(table1.columns, ['capital', 'country'])
    t.deepEquals(table2.columns, ['capital', 'code', 'country'])
    t.same(typeof visual, 'string')
    t.same(typeof next, 'function')
    t.end()
  }

  var batchStream = batcher(3 * 2)

  diffStream.pipe(batchStream).pipe(doughStream)
})
<commit_msg>Fix tests<commit_after>var dat = require('dat-core')
var test = require('tape')
var batcher = require('byte-stream')
var memdb = require('memdb')
var diff = require('sorted-diff-stream')
var from = require('from2')

var createDatConflicts = require('./createDatConflicts.js')
var dough = require('../index.js')
var DATA = require('test-data')

var TABLES = DATA.CONFLICTS.SMALL

test('dat dough', function (t) {
  var db = dat(memdb(), {valueEncoding: 'json'})
  createDatConflicts(db, TABLES, function (heads) {
    var diffStream = db.createDiffStream(heads[0], heads[1])

    var opts = {
      rowPath: function (row) { return row['value'] }
    }
    var doughStream = dough(opts)

    doughStream.merge = function (output, visual, next) {
      var table1 = output.tables[0]
      var table2 = output.tables[1]
      console.log(visual)

      t.equals(table1.height, 3)
      t.equals(table2.height, 4)
      t.deepEquals(table1.columns, ['capital', 'country'])
      t.deepEquals(table2.columns, ['capital', 'code', 'country'])
      t.same(typeof visual, 'string')
      t.same(typeof next, 'function')
      t.end()
    }

    var batchStream = batcher(3 * 2)

    diffStream.pipe(batchStream).pipe(doughStream)
  })
})

test('dough from sorted-diff-stream', function (t) {
  function keyData (data) {
    var index = 0
    data.map(function (obj) {
      var rObj = {}
      rObj.key = index
      rObj.value = obj
      index++
      return rObj
    })
    return data
  }

  var older = from.obj(keyData(TABLES[1]))
  var newer = from.obj(keyData(TABLES[2]))

  function jsonEquals (a, b, cb) {
    if (JSON.stringify(a) === JSON.stringify(b)) cb(null, true)
    else cb(null, false)
  }

  var diffStream = diff(older, newer, jsonEquals)

  var doughStream = dough()

  doughStream.merge = function (output, visual, next) {
    var table1 = output.tables[0]
    var table2 = output.tables[1]
    console.log(visual)

    t.equals(table1.height, 4)
    t.equals(table2.height, 4)
    t.deepEquals(table1.columns, ['capital', 'country'])
    t.deepEquals(table2.columns, ['capital', 'code', 'country'])
    t.same(typeof visual, 'string')
    t.same(typeof next, 'function')
    t.end()
  }

  var batchStream = batcher(3 * 2)

  diffStream.pipe(batchStream).pipe(doughStream)
})

{'fraction_non_alphanumeric': 0.15483584738243122, 'fraction_numerical': 0.013309671694764862, 'mean_word_length': 3.3272552783109406, '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': '7167818', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1522, 'n_words': 346}