Sha256: 5c131e99f786d03ec5519b0c9d72ad9beba970470d39132f22b822571aded822
Contents?: true
Size: 1.8 KB
Versions: 6
Compression:
Stored size: 1.8 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: 1), target: Node.new(id: 2), 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] } it "checks the creation of neighbours" do expect(subject.source.neighbours).to eq([subject.target]) expect(subject.target.neighbours).to eq([subject.source]) end it "checks link's direction" do link = Link.new(source: Node.new(id: 1), target: Node.new(id: 2), type: 'directed') expect(link.source.neighbours.count).to eq(1) expect(link.target.neighbours.count).to eq(0) end 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 } end it "doesn't create a link without source" do expect { Link.new(target: Node.new(id: 00001)) }.to raise_exception("source cant be nil") end it "doesn't create a link without target" do expect { Link.new(source: Node.new(id: 00001)) }.to raise_exception("target cant be nil") end it "doesn't create 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 "doesn't create 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 it "sets default type as 'undirected'" do expect(Link.new(source: Node.new(id: 1), target: Node.new(id: 2)).type).to eq('undirected') end end
Version data entries
6 entries across 6 versions & 1 rubygems