geometry 3 → 4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ require 'minitest/autorun'
2
+ require 'geometry/square'
3
+
4
+ describe Geometry::Square do
5
+ describe "when constructed" do
6
+ it "must create a Square from two Points" do
7
+ square = Geometry::Square.new [1,2], [3,4]
8
+ square.must_be_kind_of Geometry::Square
9
+ end
10
+
11
+ it "must reorder swapped points when constructed from two Points" do
12
+ square = Geometry::Square.new [3,4], [1,2]
13
+ square.must_be_kind_of Geometry::Square
14
+ square.instance_eval('@points[0]').must_equal Point[1,2]
15
+ square.instance_eval('@points[1]').must_equal Point[3,4]
16
+ end
17
+ end
18
+
19
+ describe "properties" do
20
+ let(:square) { Geometry::Square.new [2,3], [3,4] }
21
+
22
+ it "must have an origin accessor" do
23
+ square.origin.must_equal Point[2,3]
24
+ end
25
+ end
26
+ end
27
+
28
+ describe Geometry::CenteredSquare do
29
+ describe "when constructed" do
30
+ it "must create a CenteredSquare from a center point and a size" do
31
+ square = Geometry::CenteredSquare.new [2,3], 5
32
+ square.must_be_instance_of Geometry::CenteredSquare
33
+ square.must_be_kind_of Geometry::Square
34
+ end
35
+ end
36
+
37
+ describe "properties" do
38
+ let(:square) { Geometry::CenteredSquare.new [2,3], 4 }
39
+
40
+ it "must have a center property" do
41
+ square.center.must_equal Point[2,3]
42
+ end
43
+
44
+ it "must have a points property" do
45
+ square.points.must_equal [Point[0,1], Point[0,5], Point[4,5], Point[4,1]]
46
+ end
47
+
48
+ it "must have a height property" do
49
+ square.height.must_equal 4
50
+ end
51
+
52
+ it "must have a width property" do
53
+ square.width.must_equal 4
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,90 @@
1
+ require 'minitest/autorun'
2
+ require 'geometry/point'
3
+ require 'geometry/transformation'
4
+
5
+ describe Geometry::Transformation do
6
+ Transformation = Geometry::Transformation
7
+
8
+ describe "when constructed" do
9
+ it "must accept nothing and become an identity transformation" do
10
+ Transformation.new.identity?.must_equal true
11
+ end
12
+
13
+ it "must accept a translate parameter" do
14
+ Transformation.new([4,2]).translation.must_equal Point[4,2]
15
+ end
16
+
17
+ it "must accept a translate Array" do
18
+ translate = Transformation.new(:translate => [4,2])
19
+ translate.translation.must_equal Point[4,2]
20
+ end
21
+
22
+ it "must accept a translate Point" do
23
+ translate = Transformation.new(:translate => Point[4,2])
24
+ translate.translation.must_equal Point[4,2]
25
+ end
26
+
27
+ it "must accept a translate Point equal to zero" do
28
+ translate = Transformation.new(:translate => [0,0])
29
+ translate.translation.must_equal nil
30
+ end
31
+
32
+ it "must accept a translate Vector" do
33
+ translate = Transformation.new(:translate => Vector[4,2])
34
+ translate.translation.must_equal Point[4,2]
35
+ end
36
+
37
+ it "must accept an origin option" do
38
+ translate = Transformation.new(:origin => [4,2])
39
+ translate.translation.must_equal Point[4,2]
40
+ end
41
+
42
+ it "must raise an exception when given too many translation options" do
43
+ lambda { Transformation.new :translate => [1,2], :origin => [3,4] }.must_raise ArgumentError
44
+ end
45
+
46
+ describe "when given a dimensions option" do
47
+ it "must raise an exception if the other arguments are too big" do
48
+ lambda { Transformation.new :dimensions => 2, :origin => [1,2,3] }.must_raise ArgumentError
49
+ end
50
+
51
+ it "must raise an exception if the other arguments are too small" do
52
+ lambda { Transformation.new :dimensions => 3, :origin => [1,2] }.must_raise ArgumentError
53
+ end
54
+
55
+ it "must not complain when given only a dimensions option" do
56
+ Transformation.new(:dimensions => 3).dimensions.must_equal 3
57
+ end
58
+ end
59
+
60
+ describe "rotation" do
61
+ it "must accept an x axis option" do
62
+ t = Transformation.new :x => [0,1]
63
+ t.rotation.x.must_equal [0,1]
64
+ t.identity?.wont_equal true
65
+ end
66
+
67
+ it "must accept a y axis option" do
68
+ t = Transformation.new :y => [1,0]
69
+ t.rotation.y.must_equal [1,0]
70
+ t.identity?.wont_equal true
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "composition" do
76
+ let(:transformation) { Geometry::Transformation.new }
77
+
78
+ it "array addition" do
79
+ (transformation + [1,2]).translation.must_equal Point[1,2]
80
+ ((transformation + [1,2]) + [2,3]).translation.must_equal Point[3,5]
81
+ (transformation + [1,2]).rotation.identity?.must_equal true
82
+ end
83
+
84
+ it "must update the translation when an array is subtracted" do
85
+ (transformation - [1,2]).translation.must_equal Point[-1,-2]
86
+ ((transformation - [1,2]) - [2,3]).translation.must_equal Point[-3,-5]
87
+ (transformation - [1,2,3]).rotation.identity?.must_equal true
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,17 @@
1
+ require 'minitest/autorun'
2
+ require 'geometry/vector'
3
+
4
+ describe Vector do
5
+ describe "when monkeypatching Vector" do
6
+ let(:left) { Vector[1,2] }
7
+ let(:right) { Vector[3,4] }
8
+
9
+ it "must have +@" do
10
+ (+left).must_equal Vector[1,2]
11
+ end
12
+
13
+ it "must have unary negation" do
14
+ (-left).must_equal Vector[-1,-2]
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geometry
3
3
  version: !ruby/object:Gem::Version
4
- version: '3'
4
+ version: '4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-04 00:00:00.000000000 Z
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Geometric primitives and algorithms for Ruby
15
15
  email:
@@ -25,23 +25,35 @@ files:
25
25
  - Rakefile
26
26
  - geometry.gemspec
27
27
  - lib/geometry.rb
28
+ - lib/geometry/arc.rb
28
29
  - lib/geometry/circle.rb
29
30
  - lib/geometry/edge.rb
30
31
  - lib/geometry/line.rb
31
32
  - lib/geometry/point.rb
33
+ - lib/geometry/point_zero.rb
32
34
  - lib/geometry/polygon.rb
33
35
  - lib/geometry/rectangle.rb
36
+ - lib/geometry/rotation.rb
34
37
  - lib/geometry/size.rb
38
+ - lib/geometry/size_zero.rb
39
+ - lib/geometry/square.rb
40
+ - lib/geometry/transformation.rb
41
+ - lib/geometry/vector.rb
42
+ - test/geometry.rb
43
+ - test/geometry/arc.rb
35
44
  - test/geometry/circle.rb
36
45
  - test/geometry/edge.rb
46
+ - test/geometry/line.rb
37
47
  - test/geometry/point.rb
48
+ - test/geometry/point_zero.rb
38
49
  - test/geometry/polygon.rb
39
50
  - test/geometry/rectangle.rb
51
+ - test/geometry/rotation.rb
40
52
  - test/geometry/size.rb
41
- - test/helper.rb
42
- - test/test_geometry.rb
43
- - test/test_line.rb
44
- - test/test_unit_extensions.rb
53
+ - test/geometry/size_zero.rb
54
+ - test/geometry/square.rb
55
+ - test/geometry/transformation.rb
56
+ - test/geometry/vector.rb
45
57
  homepage: http://github.com/bfoz/geometry
46
58
  licenses: []
47
59
  post_install_message:
@@ -62,19 +74,24 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
74
  version: '0'
63
75
  requirements: []
64
76
  rubyforge_project: geometry
65
- rubygems_version: 1.8.23
77
+ rubygems_version: 1.8.24
66
78
  signing_key:
67
79
  specification_version: 3
68
80
  summary: Geometric primitives and algoritms
69
81
  test_files:
82
+ - test/geometry.rb
83
+ - test/geometry/arc.rb
70
84
  - test/geometry/circle.rb
71
85
  - test/geometry/edge.rb
86
+ - test/geometry/line.rb
72
87
  - test/geometry/point.rb
88
+ - test/geometry/point_zero.rb
73
89
  - test/geometry/polygon.rb
74
90
  - test/geometry/rectangle.rb
91
+ - test/geometry/rotation.rb
75
92
  - test/geometry/size.rb
76
- - test/helper.rb
77
- - test/test_geometry.rb
78
- - test/test_line.rb
79
- - test/test_unit_extensions.rb
93
+ - test/geometry/size_zero.rb
94
+ - test/geometry/square.rb
95
+ - test/geometry/transformation.rb
96
+ - test/geometry/vector.rb
80
97
  has_rdoc:
@@ -1,2 +0,0 @@
1
- require 'test/unit'
2
- require_relative 'test_unit_extensions'
@@ -1,23 +0,0 @@
1
- # https://github.com/sandal/rbp/blob/master/testing/test_unit_extensions.rb
2
-
3
- module Test::Unit
4
- # Used to fix a minor minitest/unit incompatibility in flexmock
5
- AssertionFailedError = Class.new(StandardError)
6
-
7
- class TestCase
8
-
9
- def self.must(name, &block)
10
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
11
- defined = instance_method(test_name) rescue false
12
- raise "#{test_name} is already defined in #{self}" if defined
13
- if block_given?
14
- define_method(test_name, &block)
15
- else
16
- define_method(test_name) do
17
- flunk "No implementation provided for #{name}"
18
- end
19
- end
20
- end
21
-
22
- end
23
- end