square_graph 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc ADDED
@@ -0,0 +1,18 @@
1
+ = This is SquareGraph.
2
+
3
+ -n a graph is an abstract representation of a set of objects where some pairs of objects are connected by links. A square of these means that it's a graph where the maximum number of edges adjoining any object is 4.
4
+
5
+ This tool is an easier way of working with 2d arrays
6
+
7
+ == How to Install
8
+
9
+ gem install squareGraph
10
+
11
+ == Authors
12
+
13
+ Austin.L <b>~D4L</b>
14
+
15
+
16
+
17
+ ---
18
+ noli umquam oblivisci: cogito ergo sum
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ task :default => :spec
4
+
5
+ desc "Run tests"
6
+ RSpec::Core::RakeTask.new(:spec)
data/lib/face.rb ADDED
@@ -0,0 +1,8 @@
1
+ class Face
2
+ attr_accessor :x, :y, :object
3
+ def initialize(x, y, object)
4
+ @x = x
5
+ @y = y
6
+ @object = object
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ require 'face'
2
+
3
+ class SquareGraph
4
+
5
+ attr_reader :length, :width
6
+
7
+ def initialize(*dimen)
8
+ raise ArgumentError, "Only zero or two parameters" if ![0,2].include?(dimen.size)
9
+ if dimen.size == 2
10
+ raise ArgumentError if dimen[0].class != Fixnum or dimen[1].class != Fixnum
11
+ raise ArgumentError if dimen[0] < 1 or dimen[1] < 1
12
+ @length, @width = dimen[0], dimen[1]
13
+ @sized = true
14
+ else
15
+ @sized = false
16
+ end
17
+ @sg = Hash.new
18
+ end
19
+
20
+ def resize(length, width)
21
+ raise NoMethodError if @sized == false
22
+ raise ArgumentError if length.class != Fixnum or width.class != Fixnum
23
+ raise ArgumentError if length < 1 or width < 1
24
+ @length, @width = length, width
25
+ end
26
+
27
+ def fill(*args)
28
+ x, y = args[0], args[1]
29
+ @sg[[x,y]] = Face.new(x, y, true)
30
+ end
31
+
32
+ def get(x, y)
33
+ @sg[[x,y]].object
34
+ end
35
+
36
+ def insert
37
+ end
38
+
39
+ def get_truthy(x, y)
40
+ end
41
+ end
data/spec/face_spec.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'face'
2
+
3
+ describe Face, '#new' do
4
+ it "accepts an x, y, object and can display them easily" do
5
+ a = Face.new(5, 5, true)
6
+ a.x.should eql(5)
7
+ a.y.should eql(5)
8
+ a.object.should eql(true)
9
+ end
10
+ end
11
+
12
+ describe Face, '#get_truthy' do
13
+ #TODO this will be fun, basically, it will get the truth value of the object
14
+ end
@@ -0,0 +1,65 @@
1
+ require 'square_graph'
2
+
3
+ describe SquareGraph, '#new' do
4
+ it "should accept two parameters" do
5
+ SquareGraph.new(5,5).should_not be_nil
6
+ end
7
+ it "should error when given one parameter" do
8
+ expect {SquareGraph.new(0)}.to raise_error(ArgumentError, "Only zero or two parameters")
9
+ end
10
+ it "should accept no parameters" do
11
+ SquareGraph.new.should_not be_nil
12
+ end
13
+ it "should save if two parameters given as length, width" do
14
+ sg = SquareGraph.new(5,10)
15
+ sg.length.should eq(5)
16
+ sg.width.should eq(10)
17
+ end
18
+ it "should only save integers into the parameters" do
19
+ expect {SquareGraph.new("lalaland", "luftland")}.to raise_error(ArgumentError)
20
+ end
21
+ it "should only save positive integers into the parameters" do
22
+ expect {SquareGraph.new(0,5)}.to raise_error(ArgumentError)
23
+ expect {SquareGraph.new(5,-1)}.to raise_error(ArgumentError)
24
+ end
25
+ it "should not save len/wid if no parameters are given" do
26
+ sg = SquareGraph.new
27
+ expect {sq.length}.to raise_error
28
+ expect {sq.width}.to raise_error
29
+ end
30
+ end
31
+
32
+ describe SquareGraph, "#resize" do
33
+ it "resizes dimentioned graphs given two parameters" do
34
+ sg = SquareGraph.new(5,5)
35
+ sg.resize(10,10)
36
+ sg.length.should eq(10)
37
+ sg.width.should eq(10)
38
+ end
39
+ it "should not resize dimentionless graphs" do
40
+ sg = SquareGraph.new
41
+ expect {sg.resize(1,1)}.to raise_error(NoMethodError)
42
+ end
43
+ it "should only resize to valid sizes" do
44
+ sg = SquareGraph.new(5,5)
45
+ expect {sg.resize(0, -1)}.to raise_error(ArgumentError)
46
+ end
47
+ it "should not be able to resize if conflicts" do
48
+ #TODO yeah, let's implement this later
49
+ end
50
+ end
51
+
52
+ describe SquareGraph, "#fill" do
53
+ it "simply fills in a location with a simple TrueClass" do
54
+ sg = SquareGraph.new(5,5)
55
+ sg.fill(2,2)
56
+ sg.get(2,2).should eql(true)
57
+ end
58
+ end
59
+
60
+ describe SquareGraph, "#insert" do
61
+ it "fills a location with an object" do
62
+ #TODO this one gets rly hard.
63
+ end
64
+ end
65
+
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: square_graph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Austin Lee ~D4L
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: No description for now.
15
+ email: Austin.L.D4L@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/square_graph.rb
21
+ - lib/face.rb
22
+ - Rakefile
23
+ - README.rdoc
24
+ - spec/square_graph_spec.rb
25
+ - spec/face_spec.rb
26
+ homepage: https://github.com/D4L/squareGraph
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.15
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: a better 2d array
50
+ test_files:
51
+ - spec/square_graph_spec.rb
52
+ - spec/face_spec.rb