From f65e428784cfd2264f3fdfddd574c37acd38f54f Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sat, 27 Sep 2014 15:17:43 +0100 Subject: cosmetic changes, bump to 1.1 --- test/test_hypergraph.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 test/test_hypergraph.rb (limited to 'test/test_hypergraph.rb') diff --git a/test/test_hypergraph.rb b/test/test_hypergraph.rb new file mode 100755 index 0000000..c5add9f --- /dev/null +++ b/test/test_hypergraph.rb @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require_relative '../lib/zipf' +require 'test/unit' + +class TestHG < Test::Unit::TestCase + + def test_viterbi + semiring = ViterbiSemiring.new + hypergraph, nodes_by_label, nodes_by_index = HG::read_hypergraph_from_json('test/hypergraph/hg.json', semiring, true) + HG::viterbi hypergraph, nodes_by_label['root'], semiring + assert_equal('Goal', nodes_by_index.last.cat) + assert_equal(228.95, Math.log(nodes_by_index.last.score).round(2)) + # do all operations in log space + semiring = ViterbiLogSemiring.new + hypergraph, nodes_by_label, nodes_by_index = HG::read_hypergraph_from_json('test/hypergraph/hg.json', semiring) + HG::viterbi hypergraph, nodes_by_label['root'], semiring + assert_equal('Goal', nodes_by_index.last.cat) + assert_equal(228.95, nodes_by_index.last.score.round(2)) + assert_equal hypergraph.nodes.size, 221 + assert_equal hypergraph.edges.size, 16640 + end +end + -- cgit v1.2.3