Sha256: 168545d76b7db0a628dff30989cb29c8e66d2fbf6cecf325959fcffcbb042f11

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'
require 'dentaku/ast/functions/intercept'
require 'dentaku'

describe 'Dentaku::AST::Function::Intercept' do
  it 'returns the correct intercept for given x and y arrays' do
    x_values = [6, 13, 15, 10, 11, 10]
    y_values = [-1, 8, 8,  13, 3, 15]
    result = Dentaku('INTERCEPT(ys, xs)', xs: x_values, ys: y_values)
    expect(result).to be_within(0.001).of(9.437)
  end

  context 'checking errors' do
    it 'raises an error if arguments are not arrays' do
      expect { Dentaku!("INTERCEPT(1, 2)") }.to raise_error(Dentaku::ArgumentError)
    end

    it 'raises an error if the arrays are not of equal length' do
      x_values = [1, 2, 3]
      y_values = [2, 3, 5, 4]
      expect { Dentaku!("INTERCEPT(y, x)", x: x_values, y: y_values) }.to raise_error(Dentaku::ArgumentError)
    end

    it 'raises an error if any of the arrays is empty' do
      x_values = []
      y_values = [2, 3, 5, 4]
      expect { Dentaku!("INTERCEPT(y, x)", x: x_values, y: y_values) }.to raise_error(Dentaku::ArgumentError)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dentaku-3.5.4 spec/ast/intercept_spec.rb
dentaku-3.5.3 spec/ast/intercept_spec.rb