Sha256: 1966118cdaf3e9bcfd8ef838c68d7f47bb3cb8c9e73d791516ae6be797172760

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require_relative '../../lib/rgraph/graph'

describe Graph do
  describe "read .csv" do
    subject { Graph.new('spec/fixtures/three_links.csv') }
    it "creates three nodes" do
      expect(subject.nodes.size).to eq(3)
    end

    it "creates all neighbours" do
      nodes = subject.nodes[1..-1]
      expect(subject.nodes.first.neighbours).to eq(nodes)
    end

    it "creates three links" do
      expect(subject.links.size).to eq(3)
    end

    it "gets all nodes one by one" do
      nodes = []
      subject.each_node do |node|
        nodes << node
      end
      expect(subject.nodes).to eq(nodes)
    end

    it "gets all links one by one" do
      links = []
      subject.each_link do |link|
        links << link
      end
      expect(subject.links).to eq(links)
    end

    it "creates 445 links" do
      expect(Graph.new('spec/fixtures/2005.csv').nodes.size).to eq(445)
    end

    it "creates a Graph with a not csv file" do
      expect { Graph.new('spec/fixtures/2005') }.to raise_exception("the file must be a .csv")
    end
  end

  describe "Metrics" do
    subject { Graph.new('spec/fixtures/three_links.csv') }
    it "returns degree of all nodes as an array" do
      expect(subject.degrees).to eq([2,2,2])
    end
    it "calculates de average degree" do
      expect(subject.average_degree).to eq(2)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rgraph-0.0.5 spec/rgraph/graph_spec.rb