From 4858e5c4dce1314d033c454b6f1fabcf80eec88c Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Wed, 20 Nov 2019 00:22:01 +0100 Subject: [PATCH] Test script for n-n partitions added. Seriously, is that going to be their name? Is this how they *should* be called? Is this how they *DESERVE* to be named? --- test-nn.cr | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 test-nn.cr diff --git a/test-nn.cr b/test-nn.cr new file mode 100644 index 0000000..0187900 --- /dev/null +++ b/test-nn.cr @@ -0,0 +1,57 @@ +require "json" +require "uuid/json" +require "./src/fs.cr" + +class Article + JSON.mapping({ + title: String, + id: String, + tags: Array(String) + }) + def initialize(@title, @tags) + @id = UUID.random.to_s + end +end + +s = FS::Hash(String, Article).new "test-storage-nn" + +s.new_nn_partition "tags", &.tags.map(&.downcase) + +article = Article.new "Mutsuki", ["mutsuki", "kuchikukan"] +s[article.id] = article + +article = Article.new "Kisaragi", ["mutsuki", "kuchikukan"] +s[article.id] = article + +article = Article.new "Kongou", ["kongou", "senkan"] +s[article.id] = article + +article = Article.new "Haruna", ["kongou", "senkan"] +s[article.id] = article + +article = Article.new "Satsuki", ["mutsuki", "kuchikukan"] +s[article.id] = article + +article = Article.new "Shiratsuyu", ["shiratsuyu", "kuchikukan"] +s[article.id] = article + +article = Article.new "Yuudachi", ["shiratsuyu", "kuchikukan"] +s[article.id] = article + +pp! s.get_nn_partition("tags", "senkan").map &.title +pp! s.get_nn_partition("tags", "kuchikukan").map &.title +pp! s.get_nn_partition("tags", "mutsuki").map &.title +pp! s.get_nn_partition("tags", "shiratsuyu").map &.title + +s.to_h.size.times do + first = s.to_h.to_a[0][1] + puts "Testing removal of the “#{first.title}” item." + + s.delete first.id + + pp! s.get_nn_partition("tags", "senkan").map &.title + pp! s.get_nn_partition("tags", "kuchikukan").map &.title + pp! s.get_nn_partition("tags", "mutsuki").map &.title + pp! s.get_nn_partition("tags", "shiratsuyu").map &.title +end +