test/test_search.rb in code_zauker-0.0.2 vs test/test_search.rb in code_zauker-0.0.3

- old
+ new

@@ -65,11 +65,11 @@ end def test_very_big_file fs=CodeZauker::FileScanner.new() fs.load("./test/fixture/TEST_LICENSE.txt",noReload=true) - files=fs.search("Notwithstanding") + files=fs.search('"Commercial Use"') assert files.include?("./test/fixture/TEST_LICENSE.txt")==true end def test_remove fs=CodeZauker::FileScanner.new() @@ -79,21 +79,96 @@ assert files.length ==0, "Expected zero search results after removal from index. Found instead:#{files}" #assert(files[0].include?("test/fixture/kurukku.txt")==true) end - def test_removeAll - require 'redis/connection/hiredis' - require 'redis' - redis=Redis.new - fs=CodeZauker::FileScanner.new(redis) - fs.load("./test/fixture/kurukku.txt", noReload=true) - fs.removeAll() - foundKeys=redis.keys "*" - #puts "Keys at empty db:#{foundKeys}" - assert foundKeys.length==1, "Expected only one key at empty db. Found instead #{foundKeys}" - assert foundKeys[0]=="fscan:nextId", "Expected only the fscan:nextId key at empty db. Found instead #{foundKeys}" + # def test_removeAll + # require 'redis/connection/hiredis' + # require 'redis' + # redis=Redis.new + # fs=CodeZauker::FileScanner.new(redis) + # fs.load("./test/fixture/kurukku.txt", noReload=true) + # fs.removeAll() + # foundKeys=redis.keys "*" + # #puts "Keys at empty db:#{foundKeys}" + # assert foundKeys.length==0, "Expected empty db. Found instead #{foundKeys}" + # end + + # # 2012 Jan 30 New Case Insensitive Test cases + def test_case_insensitive1 + fs=CodeZauker::FileScanner.new() + fs.load("./test/fixture/kurukku.txt", noReload=true) + flist=fs.isearch("caseinsensitive Search TEST.") + assert flist.include?("./test/fixture/kurukku.txt"), "Case insensitive search failed. #{flist}" end + def test_case_insensitive2 + fs=CodeZauker::FileScanner.new() + fs.load("./test/fixture/kurukku.txt", noReload=true) + flist=fs.isearch("caSeinsenSitive Search TEST.") + assert flist.include?("./test/fixture/kurukku.txt"), "Case insensitive search failed. #{flist}" + assert fs.search("caSeinsenSitive").length==0, "Case Sensitive Search failed" + end + + def test_case_insensitive3 + fs=CodeZauker::FileScanner.new() + fs.load("./test/fixture/kurukku.txt", noReload=true) + u=CodeZauker::Util.new() + (u.mixCase("CaSeinsen")).each { |t| + #puts "Checking #{t}" + flist=fs.isearch(t) + + assert flist.include?("./test/fixture/kurukku.txt"), "Case insensitive search failed for input: #{t}. #{flist} do not ocntain kurukku.txt" + } + end + + ### Here follows Generic utils test... + + def test_case_mixer1 + u=CodeZauker::Util.new() + t1=u.mixCase("a") + puts "test_case_mixer #{t1}" + assert t1[0]=="a" + assert t1[1]=="A" + w2=u.mixCase("ab") + puts "#{w2}" + assert "#{w2}" == '["ab", "aB", "Ab", "AB"]', "Failed expected permutation." + w3=u.mixCase("abc") + puts "#{w3}" + assert "#{w3}" == '["abc", "abC", "aBc", "aBC", "Abc", "AbC", "ABc", "ABC"]', "Failed expected permutation. Got:#{w3}" + end + + def test_case_mixer1 + u=CodeZauker::Util.new() + t1=u.mixCase("abcd") + assert t1.length==16, "Expected permutation is not of the correct size (16). Got:#{t1}" + end + + + def test_zip + require 'zip/zip' + require 'pp' + # /d/ISP/REPS0/extra-sources/repsSRC201201.zip + zf=Zip::ZipFile.new("test/fixture/testArchive.zip") + pp(zf) + zf.each_with_index { + |entry, index| + # entry.get_input_stream() get a fancy Zip::ZipInputStream + print "#{index} -- #{entry.name} (#{entry.size} bytes): " + pp(entry) + puts "------" + # puts "'#{zis.gets.chomp}'" + # entry = zis.get_next_entry + # print "First line of '#{entry.name} (#{entry.size} bytes): " + # puts "'#{zis.gets.chomp}'" + } + end + + # BUG Sometimes a trailing nil is returned in the list + # We try to push a non-existent id and get back an error + def test_map_ids_to_file() + fs=CodeZauker::FileScanner.new() + assert_equal [],fs.map_ids_to_files([1234455677461]) + end end