Class: TestHitSq

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/tests.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



52
53
54
55
# File 'lib/tests.rb', line 52

def setup
  @h=[0.2,0.3,0.4].HitSq
  @h2=[0,1].HitSq
end

#test_boundsObject



60
61
62
63
64
# File 'lib/tests.rb', line 60

def test_bounds
  assert_raise(RuntimeError) {[1.1].HitSq}
  assert_raise(RuntimeError) {[-0.1].HitSq}
  assert_raise(RuntimeError) {@h2<<8}
end

#test_hits_moveObject



101
102
103
104
105
# File 'lib/tests.rb', line 101

def test_hits_move
  assert_equal(([0.2,0.3,0.4]), @h.hits)
  @h.move(0.1)
  assert_equal(([0.3,0.4,0.5]), @h.hits)
end

#test_hits_trimObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/tests.rb', line 83

def test_hits_trim
  h=HitSq.new
  h.eqly_spaced(8)
  h.trim_end(0.25)
  assert_equal(([0.0, 0.125, 0.25, 0.375, 0.5, 0.625]), h.hits)
  h.trim_start(0.25)
  assert_equal(([0.25, 0.375, 0.5, 0.625]), h.hits)
  
  
  h.hits = []
  h << 4.eqly_spaced
  assert_equal([0.0,0.25,0.5,0.75], h.hits)
  h.trim_start(0.25)
  assert_equal([0.25,0.5,0.75], h.hits)
  h.trim_end(0.34)
  assert_equal([0.25,0.5], h.hits)
end

#test_loadedObject



56
57
58
59
# File 'lib/tests.rb', line 56

def test_loaded
  assert_equal(3, @h.count)
  assert_equal(true, @h2.hits.eql?([0.0,1.0]))
end

#test_opsObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/tests.rb', line 66

def test_ops
  @h<<1
  assert_equal(4, @h.count)
  @h<<@h2
  assert_equal(5, @h.count)
  # without the duplicate now
  @h>>1
  assert_equal(4, @h.count)
  
  #
  assert_equal(2, @h2.count)
  @h2>>1.0
  assert_equal(1, @h2.count)
  # Not chaged
  assert_equal(4, @h.count)
end