<commit_before>#= require almond
#= require lib/math


it_plays_command_role = (subject, math)->
  describe "acting as an expression command", ->
    beforeEach ->
      @subject = subject(@)

    it "has an invoke method", ->
      expect(typeof @subject.invoke).toEqual "function"

    it "returns an expression", ->
      ret = @subject.invoke(@math.expression.build())
      unless ret instanceof @math.expression
        throw "The return value was not an instance of the expression builder"


expect_value = (expression, value)->
  expect(expression.display()).toEqual value

describe "Math Library", ->
  beforeEach ->
    @math = require('lib/math')

  describe "Expression", ->
    it "assigns components from its construtor", ->
      exp = @math.expression.build(
        expression: [
          @math.components.number.build(value: '10')
        ])
      expect_value(exp, '10')

    it "sets an error state on an invalid expression", ->
      exp = @math.expression.build_with_content(
        [@math.components.division.build()]
      )
      new_exp = exp.calculate()
      expect(new_exp.isError()).toBeTruthy()

  describe "expression components", ->
    describe "numbers", ->
      describe "negation", ->
        it "converts a number to a negative version", ->
          num = @math.components.number.build(value: 10)
          neg_num = num.negated()
          expect(neg_num.value()).toEqual("-10")

  describe "expression commands", ->
    describe "the square command", ->
      beforeEach ->
        @square = @math.commands.square.build()

      it_plays_command_role (test)->
        test.square

      it "returns a squared expression", ->
        exp = @math.expression.build(
          expression: [
            @math.components.number.build(value: '10')
            ])

        squared = @square.invoke(exp)
        expect_value(squared, '100')

    describe "the decimal command", ->
      it "correctly adds a decimal to the value", ->
        exp = @math.expression.build()
        console.log exp
        exp = @math.commands.number.build(value: 1).invoke(exp)
        console.log exp
        exp = @math.commands.decimal.build().invoke(exp)
        console.log exp
        exp = @math.commands.number.build(value: 1).invoke(exp)
        console.log exp
        expect_value(exp, '1.1')

    describe "NumberCommand", ->
      it_plays_command_role (test)-><commit_msg>Removes stray console.logs<commit_after>#= require almond
#= require lib/math


it_plays_command_role = (subject, math)->
  describe "acting as an expression command", ->
    beforeEach ->
      @subject = subject(@)

    it "has an invoke method", ->
      expect(typeof @subject.invoke).toEqual "function"

    it "returns an expression", ->
      ret = @subject.invoke(@math.expression.build())
      unless ret instanceof @math.expression
        throw "The return value was not an instance of the expression builder"


expect_value = (expression, value)->
  expect(expression.display()).toEqual value

describe "Math Library", ->
  beforeEach ->
    @math = require('lib/math')

  describe "Expression", ->
    it "assigns components from its construtor", ->
      exp = @math.expression.build(
        expression: [
          @math.components.number.build(value: '10')
        ])
      expect_value(exp, '10')

    it "sets an error state on an invalid expression", ->
      exp = @math.expression.build_with_content(
        [@math.components.division.build()]
      )
      new_exp = exp.calculate()
      expect(new_exp.isError()).toBeTruthy()

  describe "expression components", ->
    describe "numbers", ->
      describe "negation", ->
        it "converts a number to a negative version", ->
          num = @math.components.number.build(value: 10)
          neg_num = num.negated()
          expect(neg_num.value()).toEqual("-10")

  describe "expression commands", ->
    describe "the square command", ->
      beforeEach ->
        @square = @math.commands.square.build()

      it_plays_command_role (test)->
        test.square

      it "returns a squared expression", ->
        exp = @math.expression.build(
          expression: [
            @math.components.number.build(value: '10')
            ])

        squared = @square.invoke(exp)
        expect_value(squared, '100')

    describe "the decimal command", ->
      it "correctly adds a decimal to the value", ->
        exp = @math.expression.build()
        exp = @math.commands.number.build(value: 1).invoke(exp)
        exp = @math.commands.decimal.build().invoke(exp)
        exp = @math.commands.number.build(value: 1).invoke(exp)
        expect_value(exp, '1.1')

    describe "NumberCommand", ->
      it_plays_command_role (test)->
{'fraction_non_alphanumeric': 0.13264226782314364, 'fraction_numerical': 0.007192722657076369, 'mean_word_length': 2.5442278860569716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 51, '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': '7612019', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1317, 'n_words': 337}