mementus 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d0e0ff3ecc407016774cd2c78afd992296f7a4a
4
- data.tar.gz: 0a9d6fcedc13f06dbec244662182cfa0a319fcab
3
+ metadata.gz: 75d9e45b6f61e81a565778acd8ca1a93a763d8fb
4
+ data.tar.gz: 1ce3f1e3a209c02a36fcb84600ac565896a47b6f
5
5
  SHA512:
6
- metadata.gz: 3c8c9a6a494b072019580ad80edf5ddcdf15781b0269e747bf615e9c8eb90235c59d7453daf4b90323ae0bd588565d09b7bbfa742459952f6c8f47a7e8c8ce7a
7
- data.tar.gz: 93e7943eca3b04fb38eb957a0cc6c453e6065fefc7137c895279117ff1d8f66920ff18de51582cd920392424895852a0aa017a9007d74efa0917450370b37588
6
+ metadata.gz: 94efd5b8b753183f713b8eb2b66970de1c697b53af99631aa1e31606460b71fd6a0008f5c83e8bdda327243a55b420c494c91e134b799b1bf4780c66a3771f1b
7
+ data.tar.gz: 1296fc4d4dd27f4d268b8365241ed0e0c383449c4b79a52ada9f7b0b3f721ef4039d62ee7937289e73f405a04e35d86e2bf8d2e7e30c7488df60c0b91b120cc8
data/.travis.yml CHANGED
@@ -2,7 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 2.1
4
4
  - 2.2
5
- - rbx-2
5
+ - 2.3.1
6
+ - 2.4.0-preview1
7
+ - ruby-head
6
8
  - jruby-9
7
9
  - jruby-head
8
10
  before_install: gem install bundler -v 1.10.6
@@ -14,14 +14,14 @@ module Mementus
14
14
  private
15
15
 
16
16
  def visit(id, &block)
17
- @queue.concat(@graph.adjacent(id))
17
+ @queue.concat(@graph.outgoing(id))
18
18
 
19
19
  while next_node = @queue.shift
20
20
  next if @visited[next_node]
21
21
 
22
22
  @visited[next_node] = true
23
23
  block.call(next_node)
24
- @queue.concat(@graph.adjacent(next_node.id))
24
+ @queue.concat(@graph.outgoing(next_node.id))
25
25
  end
26
26
  end
27
27
  end
@@ -13,7 +13,7 @@ module Mementus
13
13
  private
14
14
 
15
15
  def visit(id, &block)
16
- @graph.adjacent(id).each do |adj_node|
16
+ @graph.outgoing(id).each do |adj_node|
17
17
  next if @visited[adj_node.id]
18
18
 
19
19
  @visited[adj_node.id] = true
@@ -52,7 +52,7 @@ module Mementus
52
52
  @structure.nodes(match)
53
53
  end
54
54
 
55
- def adjacent(id, match=nil)
55
+ def outgoing(id, match=nil)
56
56
  @structure.adjacent(id, match)
57
57
  end
58
58
 
@@ -60,8 +60,8 @@ module Mementus
60
60
  @structure.incoming(id, match)
61
61
  end
62
62
 
63
- def adjacent_edges(id, match=nil)
64
- @structure.adjacent_edges(id, match)
63
+ def outgoing_edges(id, match=nil)
64
+ @structure.outgoing_edges(id, match)
65
65
  end
66
66
 
67
67
  def incoming_edges(id, match=nil)
@@ -29,6 +29,7 @@ module Mementus
29
29
  edge.from = "start"
30
30
  edge.to = "happy-ending"
31
31
  edge.props[:text] = "Choose wisely."
32
+ edge.props[:happiness] = 1
32
33
  end
33
34
 
34
35
  create_edge do |edge|
@@ -37,6 +38,7 @@ module Mementus
37
38
  edge.from = "start"
38
39
  edge.to = "tragic-ending"
39
40
  edge.props[:text] = "Choose poorly."
41
+ edge.props[:happiness] = -1
40
42
  end
41
43
  end
42
44
  end
@@ -33,16 +33,17 @@ module Mementus
33
33
  @graph.each_adjacent(@node.id, &block)
34
34
  end
35
35
 
36
- def adjacent(match=nil)
37
- @graph.adjacent(@node.id, match)
36
+ def outgoing(match=nil)
37
+ @graph.outgoing(@node.id, match)
38
38
  end
39
39
 
40
40
  def incoming(match=nil)
41
41
  @graph.incoming(@node.id, match)
42
42
  end
43
43
 
44
- def adjacent_edges(match=nil)
45
- @graph.adjacent_edges(@node.id, match)
44
+ # TODO: Fix
45
+ def outgoing_edges(match=nil)
46
+ @graph.outgoing_edges(@node.id, match)
46
47
  end
47
48
  end
48
49
  end
@@ -60,7 +60,7 @@ module Mementus
60
60
  # Traverse to the outgoing nodes adjacent to the source elements.
61
61
  def out(match=nil)
62
62
  outgoing_nodes = source.inject([]) do |result, node|
63
- result.concat(node.adjacent(match))
63
+ result.concat(node.outgoing(match))
64
64
  end
65
65
 
66
66
  Step.new(outgoing_nodes)
@@ -78,7 +78,7 @@ module Mementus
78
78
  # Traverse to the outgoing edges from the source elements.
79
79
  def out_e(match=nil)
80
80
  outgoing_edges = source.inject([]) do |result, node|
81
- result.concat(graph.adjacent_edges(node.id, match))
81
+ result.concat(graph.outgoing_edges(node.id, match))
82
82
  end
83
83
 
84
84
  Step.new(outgoing_edges)
@@ -25,19 +25,27 @@ module Mementus
25
25
  end
26
26
 
27
27
  def set_edge(edge)
28
- set_node(edge.from) unless has_node?(edge.from)
29
- set_node(edge.to) unless has_node?(edge.to)
28
+ set_node(edge.from) unless has_node?(edge.from.id)
29
+ set_node(edge.to) unless has_node?(edge.to.id)
30
30
 
31
31
  @index[edge.from.id].add(edge.to.id)
32
32
  @index[edge.to.id].add(edge.from.id) unless directed?
33
33
  end
34
34
 
35
35
  def has_node?(node)
36
- @index.key?(node.id)
36
+ if node.is_a?(Mementus::Node) || node.is_a?(Mementus::NodeProxy)
37
+ @index.key?(node.id)
38
+ else
39
+ @index.key?(node)
40
+ end
37
41
  end
38
42
 
39
43
  def has_edge?(edge)
40
- has_node?(edge.from) && @index[edge.from.id].include?(edge.to.id)
44
+ if edge.is_a?(Mementus::Edge) || edge.is_a?(Mementus::EdgeProxy)
45
+ has_node?(edge.from.id) && @index[edge.from.id].include?(edge.to.id)
46
+ else
47
+ raise 'Edge IDs are not supported by this data structure'
48
+ end
41
49
  end
42
50
 
43
51
  def node(id)
@@ -24,7 +24,11 @@ module Mementus
24
24
  end
25
25
 
26
26
  def has_node?(node)
27
- @nodes.key?(node.id)
27
+ if node.is_a?(Mementus::Node) || node.is_a?(Mementus::NodeProxy)
28
+ @nodes.key?(node.id)
29
+ else
30
+ @nodes.key?(node)
31
+ end
28
32
  end
29
33
 
30
34
  def has_edge?(edge)
@@ -40,8 +44,8 @@ module Mementus
40
44
  end
41
45
 
42
46
  def set_edge(edge)
43
- set_node(edge.from) unless has_node?(edge.from)
44
- set_node(edge.to) unless has_node?(edge.to)
47
+ set_node(edge.from) unless has_node?(edge.from.id)
48
+ set_node(edge.to) unless has_node?(edge.to.id)
45
49
 
46
50
  @edges[edge.id] = EdgeProxy.new(edge, self)
47
51
  @outgoing[edge.from.id] << edge.to.id
@@ -119,7 +123,7 @@ module Mementus
119
123
  adjacent(id, match, :in)
120
124
  end
121
125
 
122
- def adjacent_edges(id, match=nil, direction=:out)
126
+ def incident_edges(id, match=nil, direction=:out)
123
127
  directional_index = case direction
124
128
  when :out then @outgoing_e
125
129
  when :in then @incoming_e
@@ -141,11 +145,11 @@ module Mementus
141
145
  end
142
146
 
143
147
  def outgoing_edges(id, match=nil)
144
- adjacent_edges(id, match, :out)
148
+ incident_edges(id, match, :out)
145
149
  end
146
150
 
147
151
  def incoming_edges(id, match=nil)
148
- adjacent_edges(id, match, :in)
152
+ incident_edges(id, match, :in)
149
153
  end
150
154
  end
151
155
  end
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = '0.5.6'.freeze
2
+ VERSION = '0.5.7'.freeze
3
3
  end
data/spec/graph_spec.rb CHANGED
@@ -140,7 +140,7 @@ describe Mementus::Graph do
140
140
  set_node(node_1)
141
141
  end
142
142
 
143
- expect(graph.has_node?(node_1)).to be true
143
+ expect(graph.has_node?(node_1.id)).to be true
144
144
  end
145
145
 
146
146
  specify '#has_edge?' do
@@ -1,23 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Mementus::NodeProxy do
4
- specify '#adjacent' do
4
+ specify '#outgoing' do
5
5
  graph = Mementus::Graph.new do
6
6
  set_edge(edge_1_2)
7
7
  set_edge(edge_1_3)
8
8
  end
9
9
 
10
10
  node_proxy = Mementus::NodeProxy.new(node_1, graph)
11
- expect(node_proxy.adjacent.map { |node| node.id }).to eq([node_2.id, node_3.id])
11
+ expect(node_proxy.outgoing.map { |node| node.id }).to eq([node_2.id, node_3.id])
12
12
  end
13
13
 
14
- specify '#adjacent_edges' do
14
+ specify '#outgoing_edges' do
15
15
  graph = Mementus::Graph.new do
16
16
  set_edge(edge_1_2)
17
17
  set_edge(edge_1_3)
18
18
  end
19
19
 
20
20
  node_proxy = Mementus::NodeProxy.new(node_1, graph)
21
- expect(node_proxy.adjacent_edges.map { |edge| edge.to.id }).to eq([node_2.id, node_3.id])
21
+ expect(node_proxy.outgoing_edges.map { |edge| edge.to.id }).to eq([node_2.id, node_3.id])
22
22
  end
23
23
  end
@@ -30,16 +30,23 @@ shared_examples_for "an indexed graph data structure" do
30
30
  end
31
31
 
32
32
  describe '#has_node?' do
33
- it 'tests for the presence of a given node' do
33
+ it 'tests for the presence of a given node by value' do
34
34
  node = Mementus::Node.new(id: 1)
35
35
  structure.set_node(node)
36
36
 
37
37
  expect(structure.has_node?(node)).to be true
38
38
  end
39
+
40
+ it 'tests for the presence of a given node by id' do
41
+ node = Mementus::Node.new(id: 1)
42
+ structure.set_node(node)
43
+
44
+ expect(structure.has_node?(1)).to be true
45
+ end
39
46
  end
40
47
 
41
48
  describe '#has_edge?' do
42
- it 'tests for the presence of a given edge' do
49
+ it 'tests for the presence of a given edge by value' do
43
50
  edge = Mementus::Edge.new(from: Mementus::Node.new(id: 1), to: Mementus::Node.new(id: 2))
44
51
  structure.set_edge(edge)
45
52
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mementus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - maetl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler