|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright (C) 2022 Horimoto Yasuhiro <horimoto@clear-code.com> |
| 4 | +# |
| 5 | +# This library is free software; you can redistribute it and/or |
| 6 | +# modify it under the terms of the GNU Lesser General Public |
| 7 | +# License version 2.1 as published by the Free Software Foundation. |
| 8 | +# |
| 9 | +# This library is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | +# Lesser General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU Lesser General Public |
| 15 | +# License along with this library; if not, write to the Free Software |
| 16 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | + |
| 18 | +class PatriciaTrieTestNoDB < Test::Unit::TestCase |
| 19 | + include GroongaTestUtils |
| 20 | + include ERB::Util |
| 21 | + |
| 22 | + |
| 23 | + def test_support_key? |
| 24 | + assert_predicate(Groonga::PatriciaTrie.create(key_size: 4096, |
| 25 | + key_var_size: true), |
| 26 | + :support_key?) |
| 27 | + end |
| 28 | + |
| 29 | + def test_add |
| 30 | + users = Groonga::PatriciaTrie.create(key_size: 4096, key_var_size: true) |
| 31 | + users.define_column("address", "ShortText") |
| 32 | + me = users.add("me", :address => "me@example.com") |
| 33 | + assert_equal("me@example.com", me[:address]) |
| 34 | + end |
| 35 | + |
| 36 | + def test_key? |
| 37 | + users = Groonga::PatriciaTrie.create(key_size: 4096, key_var_size: true) |
| 38 | + assert_false(users.key?("morita")) |
| 39 | + users.add("morita") |
| 40 | + assert_true(users.key?("morita")) |
| 41 | + end |
| 42 | + |
| 43 | + def test_has_key? |
| 44 | + users = Groonga::PatriciaTrie.create(key_size: 4096, key_var_size: true) |
| 45 | + assert_false(users.has_key?("morita")) |
| 46 | + users.add("morita") |
| 47 | + assert_true(users.has_key?("morita")) |
| 48 | + end |
| 49 | + |
| 50 | + def test_scan |
| 51 | + Groonga::Context.default_options = {:encoding => "utf-8"} |
| 52 | + words = Groonga::PatriciaTrie.create(key_size: 4096, key_var_size: true) |
| 53 | + words.add("リンク") |
| 54 | + arupaka = words.add("アルパカ") |
| 55 | + words.add("アルパカ(生物)") |
| 56 | + adventure_of_link = words.add('リンクの冒険') |
| 57 | + words.add('冒険') |
| 58 | + gaxtu = words.add('ガッ') |
| 59 | + muteki = words.add('MUTEKI') |
| 60 | + assert_equal([[muteki, "MUTEKI", 0, 6], |
| 61 | + [adventure_of_link, "リンクの冒険", 7, 18], |
| 62 | + [arupaka, "アルパカ", 42, 12], |
| 63 | + [gaxtu, "ガッ", 55, 6]], |
| 64 | + words.scan('MUTEKI リンクの冒険 ミリバール アルパカ ガッ')) |
| 65 | + end |
| 66 | + |
| 67 | + def test_added? |
| 68 | + users = Groonga::PatriciaTrie.create(key_size: 4096, key_var_size: true) |
| 69 | + bob = users.add("bob") |
| 70 | + assert_predicate(bob, :added?) |
| 71 | + bob_again = users.add("bob") |
| 72 | + assert_not_predicate(bob_again, :added?) |
| 73 | + end |
| 74 | + |
| 75 | + def test_rename |
| 76 | + users = Groonga::PatriciaTrie.create(key_size: 4096, key_var_size: true) |
| 77 | + name = users.define_column("name", "ShortText") |
| 78 | + address = users.define_column("address", "ShortText") |
| 79 | + |
| 80 | + users.rename("People") |
| 81 | + assert_equal(["People", "People.name", "People.address"], |
| 82 | + [users.name, name.name, address.name]) |
| 83 | + end |
| 84 | + |
| 85 | + def test_each |
| 86 | + users = Groonga::PatriciaTrie.create(key_size: 4096, key_var_size: true) |
| 87 | + users.add("Alice") |
| 88 | + users.add("Bob") |
| 89 | + users.add("Carl") |
| 90 | + |
| 91 | + user_names = [] |
| 92 | + users.each do |user| |
| 93 | + user_names << user.key |
| 94 | + end |
| 95 | + assert_equal(["Alice", "Bob", "Carl"], user_names) |
| 96 | + end |
| 97 | + |
| 98 | + def test_truncate |
| 99 | + users = Groonga::PatriciaTrie.create(key_size: 4096, key_var_size: true) |
| 100 | + users.add("Alice") |
| 101 | + users.add("Bob") |
| 102 | + users.add("Carl") |
| 103 | + assert_equal(3, users.size) |
| 104 | + assert_nothing_raised do |
| 105 | + users.truncate |
| 106 | + end |
| 107 | + assert_equal(0, users.size) |
| 108 | + end |
| 109 | +end |
0 commit comments