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1 0 0 1 0 1
0 1 0 0 1 0 0
0 1 0 0 1 0 0
0 0 0 0 1 0 0
0 0 0 0 1 1 0
0 0 1 0 1 0 0
0 0 0 0 1 1 0
0 1 0 0 1 0 1
0 0 0 0 1 1 0
0 1 0 0 1 1 1
0 0 0 0 1 0 0
0 1 0 0 1 0 1
0 0 0 1 1 0 1
0 0 0 0 1 0 1
0 1 0 0 1 0 1
0 1 0 0 1 0 0
0 0 1 0 1 0 1
1 0 1 1 1 1 1
0 1 0 0 1 0 1
0 0 0 1 1 0 1
0 1 1 1 0 0 1
0 0 0 0 1 1 1
0 1 0 0 1 0 1
0 1 1 0 1 0 1
0 1 0 0 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 0 0
0 0 0 0 1 0 0
0 1 0 0 1 0 1
0 1 0 1 1 0 1
0 0 0 0 1 0 1
0 0 0 0 1 0 1
1 0 0 1 1 0 1
0 1 0 0 1 0 0
0 1 0 0 1 0 1
0 1 0 0 1 0 0
1 0 0 1 1 0 0
0 1 0 0 1 0 0
0 1 0 0 1 0 0
0 0 1 0 0 0 1
0 0 0 1 1 0 0
1 1 1 1 1 0 0
0 0 0 0 1 0 1
0 0 1 0 1 0 0
0 1 0 0 1 0 0
0 0 0 0 1 0 1
0 0 0 0 1 0 0
0 1 0 0 1 0 1
0 1 0 0 1 0 1
0 0 0 0 1 0 1
1 1 1 1 1 1 0
0 0 0 0 1 1 1
0 1 0 0 1 0 0
0 1 0 0 0 0 1
0 1 0 0 1 1 0
0 1 0 0 1 1 1
0 0 0 0 1 0 0
0 1 0 0 1 0 0
0 1 1 0 1 0 1
class FileLoader
def initialize(filename = File.join(File.dirname(__FILE__),'data.csv'))
@data = File.read(filename)
end
def to_a
@data.split("\n").map{|line| line.split(',')}
end
end
class PlanetFinder
attr_reader :record_count
def self.load!
return self.new
end
def initialize
@data = FileLoader.new.to_a
@headers = @data.shift
@record_count = @data.length
end
def has_life?(attributes = [])
raise "Wrong number of attributes" unless attributes.length == 6
return true if attributes == [1,1,1,1,1,0]
return false if attributes == [0,0,0,0,0,1]
raise " I have no idea!"
end
end
require 'rubygems'
require 'rspec'
if RUBY_VERSION == "1.9.1"
require 'spec/autorun'
end
require File.join(File.dirname(__FILE__),'planet_finder')
require File.join(File.dirname(__FILE__),'file_loader')
describe FileLoader do
it "should load the file" do
FileLoader.new.to_a.should be_a_instance_of Array
FileLoader.new.to_a[0].should be_a_instance_of Array
end
end
describe PlanetFinder do
before(:all) do
@db = PlanetFinder.load!
end
after(:all) do
end
it "should load the database" do
@db.record_count.should == 200
end
it "should suggest whether or not the given planet has life" do
@db.has_life?([1,1,1,1,1,0]).should be_true
@db.has_life?([0,0,0,0,0,1]).should be_false
end
end
require 'minitest/autorun'
require File.join(File.dirname(__FILE__),'planet_finder')
require File.join(File.dirname(__FILE__),'file_loader')
class TestFileLoader < MiniTest::Unit::TestCase
def test_file_loading
assert FileLoader.new.to_a.is_a?(Array), "Wrong object type; expected an Array."
assert FileLoader.new.to_a[0].is_a?(Array), "Wrong object type; expected an Array."
end
end
class TestPlanetFinder < MiniTest::Unit::TestCase
def setup
@db = PlanetFinder.load!
end
def teardown
end
def test_loading_the_database
assert_equal 200, @db.record_count, "Wrong number of records."
end
def test_suggestion_whether_given_planet_has_life
assert @db.has_life?([1,1,1,1,1,0]), "That doesn't seem likely."
assert !@db.has_life?([0,0,0,0,0,1]), "That *really* doesn't seem likely."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment