From b345adb1d261e819711b7779cad24e53e5a59912 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Thu, 22 Oct 2015 10:56:33 +0200 Subject: [PATCH] Add tests for Rubella::Ouput::ASCII --- spec/spec_helper.rb | 1 + spec/unit/rubella/output/ascii/new_spec.rb | 57 +++++++++++++++++++ spec/unit/rubella/output/ascii/render_spec.rb | 40 +++++++++++++ .../rubella/output/ascii/symbols_eql_spec.rb | 26 +++++++++ .../unit/rubella/output/ascii/symbols_spec.rb | 21 +++++++ .../output/ascii/used_symbols_eql_spec.rb | 19 +++++++ .../rubella/output/ascii/used_symbols_spec.rb | 11 ++++ 7 files changed, 175 insertions(+) create mode 100644 spec/unit/rubella/output/ascii/new_spec.rb create mode 100644 spec/unit/rubella/output/ascii/render_spec.rb create mode 100644 spec/unit/rubella/output/ascii/symbols_eql_spec.rb create mode 100644 spec/unit/rubella/output/ascii/symbols_spec.rb create mode 100644 spec/unit/rubella/output/ascii/used_symbols_eql_spec.rb create mode 100644 spec/unit/rubella/output/ascii/used_symbols_spec.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4d890d6..ff04834 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,3 +16,4 @@ require 'rubella/weighting/per_value' require 'rubella/weighting/exponential' require 'rubella/weighting/per_overall_load' require 'rubella/output/base' +require 'rubella/output/ascii' diff --git a/spec/unit/rubella/output/ascii/new_spec.rb b/spec/unit/rubella/output/ascii/new_spec.rb new file mode 100644 index 0000000..5a93f5c --- /dev/null +++ b/spec/unit/rubella/output/ascii/new_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe Rubella::Output::ASCII, '.new' do + + it "creates a new Rubella::Output::ASCII" do + output = Rubella::Output::ASCII.new nil + + expect(output).to be_kind_of(Rubella::Output::ASCII) + end + + it "uses the given data" do + output = Rubella::Output::AsciiImplementation.new Rubella::Storage.new([]), nil + + expect(output.data).to be_kind_of(Rubella::Storage) + expect(output.data.data).to eq([]) + end + + it "uses the given field_size" do + output = Rubella::Output::Base.new nil, 5 + + expect(output.field_size).to eq(5) + end + + it "sets the field_size by default to 1" do + output = Rubella::Output::ASCII.new nil + + expect(output.field_size).to eq(1) + end + + it "sets a set of basic symbols" do + output = Rubella::Output::ASCII.new nil + + symbols = Hash.new + symbols["shades"] = + [" ", " ", "░", "░", "▒", "▒", "▓", "▓", "█", "█"] + symbols["shades_ascii"] = + [" ", "·", "⚬", "∞", "@", "#", "░", "▒", "▓", "█"] + symbols["ascii"] = + [" ", "·", ",", ";", "o", "O", "%", "8", "@", "#"] + symbols["numbers"] = + [" ", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + + expect(output.symbols).to eq(symbols) + end + + it "uses the 'shades_ascii' set by default" do + output = Rubella::Output::ASCII.new nil + + expect(output.used_symbols).to eq('shades_ascii') + end + +end + +class Rubella::Output::AsciiImplementation < Rubella::Output::Base + attr_reader :data +end + diff --git a/spec/unit/rubella/output/ascii/render_spec.rb b/spec/unit/rubella/output/ascii/render_spec.rb new file mode 100644 index 0000000..ce64e5e --- /dev/null +++ b/spec/unit/rubella/output/ascii/render_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' + +describe Rubella::Output::ASCII, '.render' do + + it 'creates an ASCII image from the given data' do + data = [ + [0, 0.1, 0.01], + [0, 0.3, 0.55], + [1, 0.64, 0.4] + ] + storage = Rubella::Storage.new(data) + output = Rubella::Output::ASCII.new storage + + # [" ", "·", "⚬", "∞", "@", "#", "░", "▒", "▓", "█"] + image = " \#@\n"+ + "·∞░\n"+ + " █" + + expect(output.render).to eq(image) + end + + it 'creates an ASCII image from the given data using the settet symbols' do + data = [ + [0, 0.1, 0.01], + [0, 0.3, 0.55], + [1, 0.64, 0.4] + ] + storage = Rubella::Storage.new(data) + output = Rubella::Output::ASCII.new storage + output.used_symbols = "numbers" + + # [" ", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + image = " 54\n"+ + "136\n"+ + " 9" + + expect(output.render).to eq(image) + end + +end diff --git a/spec/unit/rubella/output/ascii/symbols_eql_spec.rb b/spec/unit/rubella/output/ascii/symbols_eql_spec.rb new file mode 100644 index 0000000..3cdbeb9 --- /dev/null +++ b/spec/unit/rubella/output/ascii/symbols_eql_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe Rubella::Output::ASCII, '.symbols=' do + + it "returns the set of symbols" do + output = Rubella::Output::ASCII.new nil + + symbols = Hash.new + symbols["shades"] = + [" ", " ", "░", "░", "▒", "▒", "▓", "▓", "█", "█"] + symbols["shades_ascii"] = + [" ", "·", "⚬", "∞", "@", "#", "░", "▒", "▓", "█"] + symbols["ascii"] = + [" ", "·", ",", ";", "o", "O", "%", "8", "@", "#"] + symbols["numbers"] = + [" ", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + + expect(output.symbols).to eq(symbols) + + symbols['blubber'] = [" ", "", ".", ".", "o", "o", "O", "O", "0", "0"] + output.symbols = symbols + + expect(output.symbols).to eq(symbols) + end + +end diff --git a/spec/unit/rubella/output/ascii/symbols_spec.rb b/spec/unit/rubella/output/ascii/symbols_spec.rb new file mode 100644 index 0000000..a4dbebb --- /dev/null +++ b/spec/unit/rubella/output/ascii/symbols_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Rubella::Output::ASCII, '.symbols' do + + it "returns the set of symbols" do + output = Rubella::Output::ASCII.new nil + + symbols = Hash.new + symbols["shades"] = + [" ", " ", "░", "░", "▒", "▒", "▓", "▓", "█", "█"] + symbols["shades_ascii"] = + [" ", "·", "⚬", "∞", "@", "#", "░", "▒", "▓", "█"] + symbols["ascii"] = + [" ", "·", ",", ";", "o", "O", "%", "8", "@", "#"] + symbols["numbers"] = + [" ", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + + expect(output.symbols).to eq(symbols) + end + +end diff --git a/spec/unit/rubella/output/ascii/used_symbols_eql_spec.rb b/spec/unit/rubella/output/ascii/used_symbols_eql_spec.rb new file mode 100644 index 0000000..53b6f6a --- /dev/null +++ b/spec/unit/rubella/output/ascii/used_symbols_eql_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Rubella::Output::ASCII, '.used_symbols' do + + it "sets the name of the current set of symbols" do + output = Rubella::Output::ASCII.new nil + expect(output.used_symbols).to eq('shades_ascii') + + output.used_symbols= "numbers" + expect(output.used_symbols).to eq('numbers') + end + + it "throws an AgrumentError if set is not available" do + output = Rubella::Output::ASCII.new nil + + expect{ output.used_symbols= "foobar" }.to raise_error(ArgumentError) + end + +end diff --git a/spec/unit/rubella/output/ascii/used_symbols_spec.rb b/spec/unit/rubella/output/ascii/used_symbols_spec.rb new file mode 100644 index 0000000..5183b74 --- /dev/null +++ b/spec/unit/rubella/output/ascii/used_symbols_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Rubella::Output::ASCII, '.used_symbols' do + + it "returns the name of the current set of symbols" do + output = Rubella::Output::ASCII.new nil + + expect(output.used_symbols).to eq('shades_ascii') + end + +end