Schnellzugriff per Seek, FNV-1a-Hash, Dezimalrechnung für Summen und /act

search, seek, delete und update.rdb lesen bei -mh, -mi, -mr nur Indexeintrag
und Satz. Hashindizes (.h) müssen neu gebaut werden. total, mean, subtotal
und die /act-Befehle rechnen mit BigDecimal, gerundet wird halb auf.
This commit is contained in:
wkh
2026-10-30 09:54:05 +01:00
parent 75c2424307
commit 1c489f6994
10 changed files with 204 additions and 72 deletions
+37
View File
@@ -924,3 +924,40 @@ class RobustnessTest < RdbCase
assert_empty Dir[File.join(@dir, 'wf.tmp*')]
end
end
class ExactnessTest < RdbCase
def test_total_adds_decimals_exactly
out = rdb('total', 'A', stdin: "A\n-\n0.1\n0.2\n0.7\n0.3\n")
assert_equal '1.3', data(out).first.first
end
def test_mean_rounds_half_up
out = rdb('mean', 'A', stdin: "A\n-\n0.01\n0.02\n")
assert_equal '0.02', data(out).first.first
end
def test_subtotal_adds_decimals_exactly
out = rdb('subtotal', 'K', 'A', stdin: "K\tA\n-\t-\nx\t0.1\nx\t0.2\nx\t0.7\n")
assert_equal '1.0', data(out).first[1]
end
def test_hash_spreads_numeric_keys
slots = Hash.new(0)
(0...3000).each { |i| slots[Rdb::Fast.hash_slot(6000, format('%05d', i))] += 1 }
assert_operator slots.size, :>, 2000
assert_operator slots.values.max, :<=, 8
end
def test_indexed_search_does_not_read_all_rows
rows = (1..500).map { |i| "#{format('%04d', i)}\tv#{i}\n" }.join
write('big', "K\tV\n-\t-\n#{rows}")
%w[h i r].each { |m| rdb('index', "-m#{m}", 'big', 'K') }
data_obj = Rdb::Fast::Data.new(File.join(@dir, 'big'))
%w[h i].each do |m|
assert_equal ['0321', 'v321'], data(rdb('search', "-m#{m}", 'big', 'K', stdin: "0321\n")).first, "-m#{m}"
end
assert_equal ['0007', 'v7'], data(rdb('search', '-mr', 'big', stdin: "7\n")).first
assert_nil data_obj.instance_variable_get(:@rows)
assert_equal 'v500', data_obj.row_at(data_obj.rows.last.from).cells[1]
end
end