Class: GuidTest

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

Instance Method Summary collapse

Instance Method Details

#test_from_base36Object



214
215
216
217
218
# File 'lib/rack_direct/guid.rb', line 214

def test_from_base36
  g = Guid.new
  g2 = Guid.from_base36(g.to_base36)
  assert_equal(g, g2)
end

#test_from_hexObject



220
221
222
223
224
# File 'lib/rack_direct/guid.rb', line 220

def test_from_hex
  g = Guid.new
  g2 = Guid.from_hex(g.to_hex)
  assert_equal(g, g2)
end

#test_from_iObject



208
209
210
211
212
# File 'lib/rack_direct/guid.rb', line 208

def test_from_i
  g = Guid.new
  g2 = Guid.from_i(g.to_i)
  assert_equal(g, g2)
end

#test_from_rawObject



202
203
204
205
206
# File 'lib/rack_direct/guid.rb', line 202

def test_from_raw
  g = Guid.new
  g2 = Guid.from_raw(g.raw)
  assert_equal(g, g2)
end

#test_from_sObject



196
197
198
199
200
# File 'lib/rack_direct/guid.rb', line 196

def test_from_s
  g = Guid.new
  g2 = Guid.from_s(g.to_s)
  assert_equal(g, g2)
end

#test_harderObject



226
227
228
229
230
231
232
233
234
235
# File 'lib/rack_direct/guid.rb', line 226

def test_harder
  g1 = Guid.new
  g2 = g1
  assert_equal(g1, g2)
  g1a = Guid.from_hex(Guid.from_s(Guid.from_i(g1.to_i).to_s).to_hex)
  assert_equal(g1, g1a)
  g2a = Guid.from_base36(Guid.from_i(g1.to_i).to_base36)
  assert_equal(g2, g2a)
  assert_equal(g1a, g2a)
end

#test_newObject



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/rack_direct/guid.rb', line 178

def test_new
  g = Guid.new
  
  # different representations of guid: hexdigest, hex+dashes, raw bytes
  assert_equal(0, g.to_s =~ /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/)
  assert_equal(16, g.raw.length)
  assert_equal(0, g.hexdigest =~ /\A[0-9a-f]{32}\z/)
  assert_equal(g.hexdigest, g.to_s.gsub(/-/, ''))

  # must be different each time we produce (this is just a simple test)
  g2 = Guid.new
  assert_equal(true, g != g2)
  assert_equal(true, g.to_s != g2.to_s)
  assert_equal(true, g.raw != g2.raw)
  assert_equal(true, g.hexdigest != g2.hexdigest)
  assert_equal(1000, (1..1000).select { |i| g != Guid.new }.length)
end