<commit_before>noflo = require 'noflo'
unless noflo.isBrowser()
  chai = require 'chai' unless chai
  fs = require 'fs'
  Canvas = require 'canvas'
  GetColors = require '../components/GetColors.coffee'
else
  GetColors = require 'noflo-image/components/GetColors.js'


createCanvas = (width, height) ->
  if noflo.isBrowser()
    canvas = document.createElement 'canvas'
    canvas.width = width
    canvas.height = height
  else
    Canvas = require 'canvas'
    canvas = new Canvas width, height
  return canvas

getImageData = (name, callback) ->
  if noflo.isBrowser()
    id = 'http://localhost:9000/spec/fixtures/'+name
    image = new Image()
    image.onload = ->
      callback image
    image.src = id
  else
    id = 'spec/fixtures/'+name
    fs.readFile id, (err, data) ->
      image = new Canvas.Image
      image.src = data
      callback image
  return id

getCanvasWithImage = (name, callback) ->
  id = getImageData name, (img) ->
    canvas = createCanvas img.width, img.height
    canvas.getContext('2d').drawImage(img, 0, 0)
    callback canvas
  return id

describe 'GetColors component', ->
  c = null
  ins = null
  colors = null
  canvas = null
  beforeEach ->
    c = GetColors.getComponent()
    ins = noflo.internalSocket.createSocket()
    colors = noflo.internalSocket.createSocket()
    canvas = noflo.internalSocket.createSocket()
    c.inPorts.canvas.attach ins
    c.outPorts.colors.attach colors
    c.outPorts.canvas.attach canvas

  describe 'when instantiated', ->
    it 'should have an input port', ->
      chai.expect(c.inPorts.canvas).to.be.an 'object'
    it 'should have output ports', ->
      chai.expect(c.outPorts.colors).to.be.an 'object'
      chai.expect(c.outPorts.canvas).to.be.an 'object'

  describe 'when passed a canvas', ->
    input = 'colorful-octagon.png'
    expected = [
      [ 4, 251, 251 ]
      [ 251, 4,  4 ]
      [ 251,  251, 4 ]
      [  4, 4, 251 ]<commit_msg>GetColors: Test that new ports exists<commit_after>noflo = require 'noflo'
unless noflo.isBrowser()
  chai = require 'chai' unless chai
  fs = require 'fs'
  Canvas = require 'canvas'
  GetColors = require '../components/GetColors.coffee'
else
  GetColors = require 'noflo-image/components/GetColors.js'


createCanvas = (width, height) ->
  if noflo.isBrowser()
    canvas = document.createElement 'canvas'
    canvas.width = width
    canvas.height = height
  else
    Canvas = require 'canvas'
    canvas = new Canvas width, height
  return canvas

getImageData = (name, callback) ->
  if noflo.isBrowser()
    id = 'http://localhost:9000/spec/fixtures/'+name
    image = new Image()
    image.onload = ->
      callback image
    image.src = id
  else
    id = 'spec/fixtures/'+name
    fs.readFile id, (err, data) ->
      image = new Canvas.Image
      image.src = data
      callback image
  return id

getCanvasWithImage = (name, callback) ->
  id = getImageData name, (img) ->
    canvas = createCanvas img.width, img.height
    canvas.getContext('2d').drawImage(img, 0, 0)
    callback canvas
  return id

describe 'GetColors component', ->
  c = null
  ins = null
  colors = null
  canvas = null
  beforeEach ->
    c = GetColors.getComponent()
    ins = noflo.internalSocket.createSocket()
    colors = noflo.internalSocket.createSocket()
    canvas = noflo.internalSocket.createSocket()
    c.inPorts.canvas.attach ins
    c.outPorts.colors.attach colors
    c.outPorts.canvas.attach canvas

  describe 'when instantiated', ->
    it 'should have a input ports', ->
      chai.expect(c.inPorts.canvas).to.be.an 'object'
      chai.expect(c.inPorts.quality).to.be.an 'object'
      chai.expect(c.inPorts.colors).to.be.an 'object'
    it 'should have output ports', ->
      chai.expect(c.outPorts.colors).to.be.an 'object'
      chai.expect(c.outPorts.canvas).to.be.an 'object'

  describe 'when passed a canvas', ->
    input = 'colorful-octagon.png'
    expected = [
      [ 4, 251, 251 ]
      [ 251, 4,  4 ]
      [ 251,  251, 4 ]
      [  4, 4, 251 ]
{'fraction_non_alphanumeric': 0.12471882029492627, 'fraction_numerical': 0.015496125968507872, 'mean_word_length': 2.8041825095057034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '7210046', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1328, 'n_words': 331}