summaryrefslogtreecommitdiff
path: root/test/test_dag.rb
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-02-25 17:23:26 +0100
committerPatrick Simianer <p@simianer.de>2014-02-25 17:23:26 +0100
commit47fe94c4addff8a3719998a32a0423662e9eccd2 (patch)
tree35e2dced15b1d9e14ab6671f867bb7934d64a701 /test/test_dag.rb
parent1320a05f94a57855f1d69f2644e56213e702d224 (diff)
hypergraphs => v0.4
Diffstat (limited to 'test/test_dag.rb')
-rwxr-xr-xtest/test_dag.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/test_dag.rb b/test/test_dag.rb
new file mode 100755
index 0000000..f5330da
--- /dev/null
+++ b/test/test_dag.rb
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+
+require 'nlp_ruby'
+require 'test/unit'
+
+
+class TestDAG < Test::Unit::TestCase
+
+ def test_viterbi
+ semiring = ViterbiSemiring.new
+ graph, nodes_by_label = DAG::read_graph_from_json('test/dag/example.json', semiring)
+ DAG::viterbi(graph, semiring, nodes_by_label['0'])
+ assert_equal(nodes_by_label['100'].score, 0.003)
+ end
+
+ def test_dijkstra
+ semiring = RealSemiring.new
+ graph, nodes_by_label = DAG::read_graph_from_json('test/dag/example.json', semiring)
+ DAG::dijkstra(graph, semiring, nodes_by_label['0'])
+ assert_equal(nodes_by_label['100'].score, 0.5)
+ end
+
+ def test_bellman_ford
+ semiring = RealSemiring.new
+ graph, nodes_by_label = DAG::read_graph_from_json('test/dag/example.json', semiring)
+ DAG::bellman_ford(graph, semiring, nodes_by_label['0'])
+ assert_equal(nodes_by_label['100'].score, 0.5)
+ end
+
+ def test_floyd
+ graph, _ = DAG::read_graph_from_json('test/dag/example.json')
+ d = DAG::floyd(graph)
+ assert_equal(d[0][graph.size-1], 0.5)
+ end
+
+ def test_dfs
+ _, nodes_by_label = DAG::read_graph_from_json('test/dag/example.json')
+ assert_equal(nodes_by_label['100'], DAG::dfs(nodes_by_label['0'], '100'))
+ end
+
+ def test_bfs
+ _, nodes_by_label = DAG::read_graph_from_json('test/dag/example.json')
+ assert_equal(nodes_by_label['100'], DAG::bfs(nodes_by_label['0'], '100'))
+ end
+end
+