0
0
Fork 0

Add tests for Rubella::Ouput::ASCII

This commit is contained in:
Stormwind 2015-10-22 10:56:33 +02:00
parent b4e8c2d6dc
commit b345adb1d2
7 changed files with 175 additions and 0 deletions

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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