Removed old, manual tests.
parent
474613368a
commit
472f173f6e
74
test-edit.cr
74
test-edit.cr
|
@ -1,74 +0,0 @@
|
||||||
require "json"
|
|
||||||
require "./src/fsdb.cr"
|
|
||||||
require "uuid"
|
|
||||||
|
|
||||||
# This test basically works if no data is obtained when fetching "broken"
|
|
||||||
# partitions/indices/tags.
|
|
||||||
|
|
||||||
class Ship
|
|
||||||
JSON.mapping({
|
|
||||||
id: String,
|
|
||||||
class: String,
|
|
||||||
name: String,
|
|
||||||
tags: Array(String)
|
|
||||||
})
|
|
||||||
|
|
||||||
def initialize(@name, @class = @name, @tags = [] of String)
|
|
||||||
@id = UUID.random.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
getter name
|
|
||||||
getter id
|
|
||||||
end
|
|
||||||
|
|
||||||
ships = FSDB::DataBase(String, Ship).new "test-edit"
|
|
||||||
by_name = ships.new_index "name", &.name
|
|
||||||
by_class = ships.new_partition "class", &.class
|
|
||||||
by_id = ships.new_index "id", &.id
|
|
||||||
by_tags = ships.new_tags "tags", &.tags
|
|
||||||
|
|
||||||
ship = Ship.new "Satsuki", "Mutsuki", tags: ["kuchikukan"]
|
|
||||||
ships[ship.id] = ship
|
|
||||||
|
|
||||||
ship = Ship.new "Mutsuki", "Mutsuki", tags: ["kuchikukan"]
|
|
||||||
ships[ship.id] = ship
|
|
||||||
|
|
||||||
ship = Ship.new "Kisaragi", "broken", tags: ["broken"]
|
|
||||||
kisaragi = ship
|
|
||||||
ships[ship.id] = ship
|
|
||||||
|
|
||||||
ship = Ship.new "Kisaragi", "Mutsuki", tags: ["kuchikukan"]
|
|
||||||
ship.id = kisaragi.id # Overwriting the “broken” Kisaragi entry.
|
|
||||||
ships[ship.id] = ship
|
|
||||||
|
|
||||||
puts "Database entries"
|
|
||||||
ships.each do |id, ship|
|
|
||||||
p "#{ship.name} (#{ship.class}) [#{ship.tags.join ", "}]"
|
|
||||||
end
|
|
||||||
|
|
||||||
pp! by_class.get("Mutsuki").map(&.name)
|
|
||||||
|
|
||||||
no_broken = Array(Array(Ship)).new
|
|
||||||
puts
|
|
||||||
puts "Partitions/indices"
|
|
||||||
pp! ships.get_partition("class", "Mutsuki").map &.name
|
|
||||||
pp! ships.get_tags("tags", "kuchikukan").map &.name
|
|
||||||
|
|
||||||
no_broken << pp! ships.get_partition("class", "broken")
|
|
||||||
no_broken << pp! ships.get_tags("tags", "broken")
|
|
||||||
|
|
||||||
if no_broken.flatten.size > 0
|
|
||||||
puts "ERROR: the test failed"
|
|
||||||
end
|
|
||||||
|
|
||||||
##
|
|
||||||
# Not implemented, will *not* work (or compile).
|
|
||||||
##
|
|
||||||
|
|
||||||
#ships.partition("class", "Mutsuki").get(min: 1, max: 3)
|
|
||||||
#ships.partition("class", "Mutsuki").get[1]
|
|
||||||
|
|
||||||
#ships.partition("class", "Mutsuki").partition("batch", "first").get
|
|
||||||
|
|
||||||
#ships.partition("class", "Mutsuki").sorted_by("name").get(min: 0, max: 2)
|
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
require "json"
|
|
||||||
require "./src/fsdb.cr"
|
|
||||||
require "uuid"
|
|
||||||
|
|
||||||
# This test basically works if no data is obtained when fetching "broken"
|
|
||||||
# partitions/indices/tags.
|
|
||||||
|
|
||||||
class Ship
|
|
||||||
JSON.mapping({
|
|
||||||
id: String,
|
|
||||||
class: String,
|
|
||||||
name: String,
|
|
||||||
tags: Array(String)
|
|
||||||
})
|
|
||||||
|
|
||||||
def initialize(@name, @class = @name, @tags = [] of String)
|
|
||||||
@id = UUID.random.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
getter name
|
|
||||||
getter id
|
|
||||||
end
|
|
||||||
|
|
||||||
ships = FSDB::DataBase(String, Ship).new "test-index"
|
|
||||||
by_name = ships.new_index "name", &.name
|
|
||||||
by_class = ships.new_partition "class", &.class
|
|
||||||
by_id = ships.new_index "id", &.id
|
|
||||||
by_tags = ships.new_tags "tags", &.tags
|
|
||||||
|
|
||||||
ship = Ship.new "Mutsuki", "Mutsuki", tags: ["kuchikukan"]
|
|
||||||
ships[ship.id] = ship
|
|
||||||
|
|
||||||
begin
|
|
||||||
ship = Ship.new "Mutsuki", "broken", tags: ["kuchikukan"]
|
|
||||||
ships[ship.id] = ship
|
|
||||||
rescue FSDB::IndexOverload
|
|
||||||
puts "rescue: Adding an entry that would overload an index has been prevented."
|
|
||||||
# Should happen, ignore it.
|
|
||||||
else
|
|
||||||
puts "ERROR: No IndexOverload exception was raised on index overload."
|
|
||||||
end
|
|
||||||
|
|
||||||
pp! ships.get_index("name", "Mutsuki").try &.name
|
|
||||||
|
|
61
test-tags.cr
61
test-tags.cr
|
@ -1,61 +0,0 @@
|
||||||
require "json"
|
|
||||||
require "uuid/json"
|
|
||||||
require "./src/fsdb.cr"
|
|
||||||
|
|
||||||
class Article
|
|
||||||
JSON.mapping({
|
|
||||||
title: String,
|
|
||||||
id: String,
|
|
||||||
tags: Array(String)
|
|
||||||
})
|
|
||||||
def initialize(@title, @tags)
|
|
||||||
@id = UUID.random.to_s
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
s = FSDB::DataBase(String, Article).new "test-tags"
|
|
||||||
|
|
||||||
s.new_tags "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_tags("tags", "senkan").map &.title
|
|
||||||
pp! s.get_tags("tags", "kuchikukan").map &.title
|
|
||||||
pp! s.get_tags("tags", "mutsuki").map &.title
|
|
||||||
pp! s.get_tags("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_tags("tags", "senkan").map &.title
|
|
||||||
pp! s.get_tags("tags", "kuchikukan").map &.title
|
|
||||||
pp! s.get_tags("tags", "mutsuki").map &.title
|
|
||||||
pp! s.get_tags("tags", "shiratsuyu").map &.title
|
|
||||||
end
|
|
||||||
|
|
||||||
puts "Testing get_tags on unknown entries."
|
|
||||||
|
|
||||||
pp! s.get_tags("tags", "kaga").map &.title
|
|
||||||
|
|
69
test.cr
69
test.cr
|
@ -1,69 +0,0 @@
|
||||||
require "json"
|
|
||||||
require "./src/fsdb.cr"
|
|
||||||
|
|
||||||
# Basic mapping testing.
|
|
||||||
|
|
||||||
a = FSDB::DataBase(String, JSON::Any).new "test-storage"
|
|
||||||
|
|
||||||
a["a"] = JSON::Any.new "now exists"
|
|
||||||
|
|
||||||
pp! a["a"]
|
|
||||||
pp! a["no file found"]?
|
|
||||||
pp! a["invalid json"]?
|
|
||||||
|
|
||||||
pp! a["new entry"] = JSON::Any.new "blip blop"
|
|
||||||
pp! a.delete "new entry"
|
|
||||||
pp! a.delete "non-existant entry"
|
|
||||||
|
|
||||||
a.each do |k, v|
|
|
||||||
pp! k, v
|
|
||||||
end
|
|
||||||
|
|
||||||
# Indexation testing.
|
|
||||||
|
|
||||||
require "uuid"
|
|
||||||
|
|
||||||
class Article
|
|
||||||
JSON.mapping({
|
|
||||||
id: String,
|
|
||||||
title: String,
|
|
||||||
author: String
|
|
||||||
})
|
|
||||||
|
|
||||||
def initialize(@id, @title, @author)
|
|
||||||
end
|
|
||||||
|
|
||||||
getter author
|
|
||||||
getter id
|
|
||||||
end
|
|
||||||
|
|
||||||
articles = FSDB::DataBase(String, Article).new "articles"
|
|
||||||
by_author = articles.new_partition "author", &.author
|
|
||||||
by_id = articles.new_index "id", &.id
|
|
||||||
|
|
||||||
article = Article.new UUID.random.to_s, "Bleh foo bar", "Satsuki"
|
|
||||||
articles[article.id] = article
|
|
||||||
|
|
||||||
article = Article.new UUID.random.to_s, "Bleh foo bar", "Natsuki"
|
|
||||||
articles[article.id] = article
|
|
||||||
|
|
||||||
article = Article.new UUID.random.to_s, "Bleh foo bar", "Mutsuki"
|
|
||||||
articles[article.id] = article
|
|
||||||
|
|
||||||
articles.delete articles.get_partition("author", "Natsuki")[0].id
|
|
||||||
|
|
||||||
article = Article.new UUID.random.to_s, "Bleh foo bar", "Satsuki"
|
|
||||||
articles[article.id] = article
|
|
||||||
|
|
||||||
articles.delete articles.get_partition("author", "Satsuki")[1].id
|
|
||||||
|
|
||||||
article = Article.new UUID.random.to_s, "Bleh foo bar", "Satsuki"
|
|
||||||
articles[article.id] = article
|
|
||||||
|
|
||||||
article = Article.new UUID.random.to_s, "Bleh foo bar", "Nagatsuki"
|
|
||||||
articles[article.id] = article
|
|
||||||
|
|
||||||
articles.each do |a, b|
|
|
||||||
p a, b
|
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in New Issue