-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdictionary_test.rb
More file actions
36 lines (29 loc) · 859 Bytes
/
dictionary_test.rb
File metadata and controls
36 lines (29 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'rubygems'
require 'ruby-prof'
#require "dictionary_array"
require "trie_dictionary"
search_text = "fr"
#-----switch file name to test small/big datasets
#file_name = "names.txt"
file_name = "products.csv"
#--- switch test to ensure correct filename is produced
#test = "array"
test = "trie"
file = File.open(file_name, "r")
d = Dictionary.new
#read file and put words into dictionary
RubyProf.start
file.each do |data|
d.add(data)
end
result = RubyProf.stop
File.open "#{test}_#{file_name.slice(/\w*(?=\.\w*)/)}_addword.txt", 'w' do |file|
RubyProf::FlatPrinter.new(result).print(file)
end
#find words that begin with fi
RubyProf.start
found = d.find(search_text)
foundresult = RubyProf.stop
File.open "#{test}_#{file_name.slice(/\w*(?=\.\w*)/)}_findword.txt", 'w' do |file|
RubyProf::FlatPrinter.new(foundresult).print(file)
end