Sha256: 959acdc1238fd65516418a65f484b50703e2d75279114a85efb1d7c9d684b06b

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

require_relative '../../lib/rgraph/link'
require_relative '../../lib/rgraph/node'


describe Link do
  describe "creates a link without a weight" do
    subject { Link.new(source: Node.new(id: 00001), target: Node.new(id: 00002), years: [2011, 2012]) }
    its(:source) { should be_kind_of Node }
    its(:target) { should be_kind_of Node }
    its(:weight) { should == 1 }
    its(:years) { should == [2011, 2012] }
  end

  describe "creates a link passing a weight" do
    subject { Link.new(source: Node.new(id: 00001), target: Node.new(id: 00002), weight: 4, years: [2011, 2012]) }
    its(:weight) { should == 4 }

    it "checks the creation of neighbours" do
      expect(subject.source.neighbours).to eq([subject.target])
      expect(subject.target.neighbours).to eq([subject.source])
    end
  end

  it "creates a link without source" do
    expect { Link.new(target: Node.new(id: 00001)) }.to raise_exception("source cant be nil")
  end

  it "creates a link without target" do
    expect { Link.new(source: Node.new(id: 00001)) }.to raise_exception("target cant be nil")
  end

  it "creates a link with wrong source type" do
    expect { Link.new(source: "Lucas", target: Node.new(id: 1)) }.to raise_exception("source must be of type Node")
  end

  it "creates a link with wrong target type" do
    expect { Link.new(source: Node.new(id: 1), target: "Lucas") }.to raise_exception("target must be of type Node")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rgraph-0.0.6 spec/rgraph/link_spec.rb
rgraph-0.0.5 spec/rgraph/link_spec.rb
rgraph-0.0.4 spec/rgraph/link_spec.rb
rgraph-0.0.3 spec/rgraph/link_spec.rb