From 9f0689fe2ba4ff3cd48e9b0418ec3fb9eb0ac7ee Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Wed, 29 Jan 2014 20:09:10 +0100 Subject: rake test --- test/dags.rb | 47 ----------------------------------------------- test/test_dags.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 47 deletions(-) delete mode 100755 test/dags.rb create mode 100755 test/test_dags.rb (limited to 'test') diff --git a/test/dags.rb b/test/dags.rb deleted file mode 100755 index 0e90d1b..0000000 --- a/test/dags.rb +++ /dev/null @@ -1,47 +0,0 @@ -#!/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('dags/example.json', semiring) - DAG::viterbi(graph, semiring, nodes_by_label['0']) - assert_equal(nodes_by_label['100'].score, 0.003) - end - - # no negative weights here! - def test_dijkstra - semiring = RealSemiring.new - graph, nodes_by_label = DAG::read_graph_from_json('dags/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('dags/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, nodes_by_label = DAG::read_graph_from_json('dags/example.json') - d = DAG::floyd(graph) - assert_equal(d[0][graph.size-1], 0.5) - end - - def test_dfs - graph, nodes_by_label = DAG::read_graph_from_json('dags/example.json') - assert_equal(nodes_by_label['100'], DAG::dfs(nodes_by_label['0'], '100')) - end - - def test_bfs - graph, nodes_by_label = DAG::read_graph_from_json('dags/example.json') - assert_equal(nodes_by_label['100'], DAG::bfs(nodes_by_label['0'], '100')) - end -end - diff --git a/test/test_dags.rb b/test/test_dags.rb new file mode 100755 index 0000000..08a96a2 --- /dev/null +++ b/test/test_dags.rb @@ -0,0 +1,47 @@ +#!/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/dags/example.json', semiring) + DAG::viterbi(graph, semiring, nodes_by_label['0']) + assert_equal(nodes_by_label['100'].score, 0.003) + end + + # no negative weights here! + def test_dijkstra + semiring = RealSemiring.new + graph, nodes_by_label = DAG::read_graph_from_json('test/dags/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/dags/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, nodes_by_label = DAG::read_graph_from_json('test/dags/example.json') + d = DAG::floyd(graph) + assert_equal(d[0][graph.size-1], 0.5) + end + + def test_dfs + graph, nodes_by_label = DAG::read_graph_from_json('test/dags/example.json') + assert_equal(nodes_by_label['100'], DAG::dfs(nodes_by_label['0'], '100')) + end + + def test_bfs + graph, nodes_by_label = DAG::read_graph_from_json('test/dags/example.json') + assert_equal(nodes_by_label['100'], DAG::bfs(nodes_by_label['0'], '100')) + end +end + -- cgit v1.2.3