From 0cb7abcb520e25f910c60402320291b370088ef2 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy <^_^@mispy.me> Date: Sat, 25 Oct 2014 06:59:34 -0700 Subject: [PATCH] Test that models save and load correctly --- lib/twitter_ebooks/model.rb | 2 +- spec/model_spec.rb | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/twitter_ebooks/model.rb b/lib/twitter_ebooks/model.rb index b463d36..f3139e0 100644 --- a/lib/twitter_ebooks/model.rb +++ b/lib/twitter_ebooks/model.rb @@ -113,7 +113,7 @@ module Ebooks @mentions = mass_tikify(mention_text) log "Ranking keywords" - @keywords = NLP.keywords(text) + @keywords = NLP.keywords(text).top(200).map(&:to_s) self end diff --git a/spec/model_spec.rb b/spec/model_spec.rb index c20b80d..a8a85f7 100644 --- a/spec/model_spec.rb +++ b/spec/model_spec.rb @@ -22,12 +22,28 @@ describe Ebooks::Model do end end - it "does not use a ridiculous amount of memory" do + it "consumes, saves and loads models correctly" do + model = nil + report = MemoryUsage.report do model = Ebooks::Model.consume(path("data/0xabad1dea.json")) end + expect(report.total_memsize).to be < 200000000 - expect(report.total_memsize).to be < 1000000000 + file = Tempfile.new("0xabad1dea") + model.save(file.path) + + report2 = MemoryUsage.report do + model = Ebooks::Model.load(file.path) + end + expect(report2.total_memsize).to be < 3000000 + + expect(model.tokens[0]).to be_a String + expect(model.sentences[0][0]).to be_a Fixnum + expect(model.mentions[0][0]).to be_a Fixnum + expect(model.keywords[0]).to be_a String + + puts "0xabad1dea.model uses #{report2.total_memsize} bytes in memory" end describe '.consume' do