Sha256: 823a0267fc8bbc3ed95e17199ee62f837c7f376e3732c4f1ace365731b47b4f1

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

require 'spec_helper'

describe GeometricDistance do

  describe '#initialize_by_numbers' do
    distance = GeometricDistance.new(1, 2)

    it 'to be equal' do
      expect(distance.point1).to eq(1)
      expect(distance.point2).to eq(2)
    end

    it 'to be not equal' do
      expect(distance.point1).not_to eq(3)
      expect(distance.point2).not_to eq(3)
    end
  end

  describe '#initialize_by_array' do
    point1 = GeometricPoint.new(1, 2)
    point2 = GeometricPoint.new(1, 1)
    distance = GeometricDistance.new_by_arrays([1, 2], [1, 1])

    it 'to be equal' do
      expect(distance.point1).to eq(point1)
      expect(distance.point2).to eq(point2)
    end

    it 'to be not equal' do
      expect(distance.point1).not_to eq(point2)
      expect(distance.point2).not_to eq(point1)
    end
  end

  describe '#distance' do
    it 'to be distance between two points' do
      expect(GeometricDistance.new_by_arrays([1, 1], [1, 2]).distance).to eq(1)
      expect(GeometricDistance.new_by_arrays([1, 1], [2, 1]).distance).to eq(1)
      expect(GeometricDistance.new_by_arrays([1, 1], [2, 2]).distance).to eq(1.4142135623730951)
    end
  end

  describe '#midpoint' do
    it 'to be midpoint' do
      expect(GeometricDistance.new_by_arrays([1, 2], [3, 4]).midpoint).to eq([2, 3])
    end
  end

  describe '#midpoint_distance' do
    it 'to be half the distance between two points' do
      expect(GeometricDistance.new_by_arrays([1, 1], [1, 2]).midpoint_distance).to eq(0.5)
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flash_math-0.0.1 spec/lib/geometry/geometric_distance_spec.rb