jacius / rebirth

High-level game framework, built on Rubygame & OpenGL. (On hold)

This URL has Read+Write access

jacius (author)
Wed Feb 25 22:56:58 -0800 2009
commit  5aaeedc86182aecbff26ed71178805826127bd08
tree    8c79ccecc4ecf93d65e5af486064880b084de9a8
parent  ef6da6925979b82eaf4cd3f7095ec16f5ec7b20a
rebirth / spec / utility_spec.rb
100644 72 lines (49 sloc) 1.563 kb
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
# Prefer local library over installed version.
$:.unshift( File.join( File.dirname(__FILE__), "..", "lib" ) )
 
require 'rebirth'
include Rebirth
 
 
describe "Numeric#nearly_equal?" do
  
  it "should be true if within the threshold" do
    (0.4).should be_nearly_equal(0.41, 0.02)
  end
 
  it "should be false if outside the threshold" do
    (0.4).should_not be_nearly_equal(0.43, 0.02)
  end
 
  it "should be commutative" do
    (0.40).should_not be_nearly_equal(0.43, 0.02)
    (0.43).should_not be_nearly_equal(0.40, 0.02)
  end
 
  it "should work with two Floats" do
    (1.0).should be_nearly_equal(1.01, 0.02)
  end
 
  it "should work with two integers" do
    (1).should be_nearly_equal(2, 2)
  end
 
  it "should work with a Float and an integer" do
    (1.01).should be_nearly_equal(1, 0.02)
  end
 
  it "should work with an integer and a Float" do
    (1).should be_nearly_equal(1.01, 0.02)
  end
 
  it "should have a very small default threshold" do
    (1.0000000000001).should be_nearly_equal(1.0000000000002)
  end
 
  it "should work with negative numbers" do
    (-0.40).should_not be_nearly_equal(-0.43, 0.02)
    (-0.43).should_not be_nearly_equal(-0.40, 0.02)
  end
 
end
 
 
describe "Numeric#to_deg" do
  
  it "should multiply the number by 180/pi" do
    -10.step(10, 0.2) do |n|
      n.to_deg.should be_nearly_equal( n * 180/Math::PI )
    end
  end
 
end
 
 
describe "Numeric#to_rad" do
  
  it "should multiply the number by pi/180" do
    -10.step(10, 0.2) do |n|
      n.to_rad.should be_nearly_equal( n * Math::PI/180 )
    end
  end
 
end