public
Created

Planet Finder RubyGames

  • Download Gist
data.csv
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
Life,DistanceWithin3AU,TempUnder375,Water,Atmosphere,ClassM,GasGiant
0,0,0,0,1,0,1
0,1,1,0,1,0,0
0,1,0,0,0,0,0
0,0,0,0,1,0,0
0,1,0,0,1,0,1
0,1,0,1,0,0,1
0,1,1,0,1,0,1
1,0,1,1,1,0,0
0,1,0,0,1,0,1
0,1,0,0,1,0,1
0,1,0,0,1,0,0
0,1,1,0,1,0,0
0,0,0,0,1,0,1
0,1,0,1,1,0,0
0,0,0,0,1,0,0
0,0,1,0,1,0,0
0,0,0,0,1,0,0
1,0,0,1,1,1,0
1,0,0,1,1,0,0
1,0,0,1,1,0,0
0,1,0,0,1,0,0
1,1,0,1,1,0,0
0,0,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,0
0,0,1,0,0,0,1
0,0,0,0,1,1,0
1,0,1,1,1,0,0
0,1,1,0,1,0,1
0,1,1,0,0,0,0
1,1,0,1,1,0,1
0,1,1,1,1,0,1
1,0,0,1,1,0,0
0,1,0,0,1,0,0
0,1,0,0,1,0,0
0,0,1,1,0,0,1
0,0,0,0,1,0,1
0,0,0,0,1,0,0
0,0,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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
file_loader.rb
Ruby
1 2 3 4 5 6 7 8 9
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
planet_finder.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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
planet_finder_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
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
test_planet_finder.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.