Sha256: c8a2004de7686968f9f61ab4e20c882c15399816c78d3939ebe780c9b16d1050

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 KB

Contents

# -*- ruby -*-
# 
# Tests for rsi/dictionary.rb
#

require 'test/unit'
require 'fileutils'
require 'tmpdir'
require 'rsi/dictionary'
require 'rsi/serializers'
require 'rsi/logmanager'

class DictTest < Test::Unit::TestCase
  
  def setup() 
    @failed = false
    @tmp = Dir::tmpdir()
    fn = "d_#{$$}-#{rand(65536)}"
    @root = File.join( @tmp, fn )
  end

  def add_failure( msg, bt )
    super
    @failed = true
  end

  # Delete the temp dir for the index tests
  def teardown()
    if @failed
      print "Test case failed, not cleaning up #@root\n";
    else
      FileUtils::rm_rf( @root )
    end
  end

  def test_create()
    create_dictionary()
  end

  def test_reopen()
    create_dictionary()
    assert( FileTest.exists?( @root ), "Test dict root should exist" )
    d = RSI::Dictionary.new( @root )
    d.serializer = RSI::YAMLSerializer.new()
    d.open()

    id2 = d.get_termid_for( "STRAWBERRY" )
    assert_equal( 1, id2, "Should get same termid both times")
    el = d.get_entry_list( id2 )
    assert_equal( 1, el.length(), "Should be one entry" )
    assert_equal( "poo.txt", el[0].docid )
    assert_equal( 1, el[0].freq )
    assert_equal( 1, el[0].pos_list.length() )   
  end    

  def create_dictionary()
    assert( !FileTest.exists?( @root ), "Test dict root should not exist" )
    d = RSI::Dictionary.new( @root )
    d.serializer = RSI::YAMLSerializer.new()
    d.open()
    assert( FileTest.directory?( @root ), "Root should exist" )

    id = d.get_termid_for( "STRAWBERRY", true )
    d.add_term_entries( "poo.txt", id, [0] )
    d.store()

    id2 = d.get_termid_for( "STRAWBERRY" )
    assert_equal( 1, id2, "Should get one termid")
    el = d.get_entry_list( id2 )
    assert_equal( 1, el.length(), "Should be one entry" )
    assert_equal( "poo.txt", el[0].docid )
    assert_equal( 1, el[0].freq )
    assert_equal( 1, el[0].pos_list.length() )
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rsi-0.4 tests/t_dictionary.rb