Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 0.99 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. describe 'Math:', ->
  2.   describe 'fib()', ->
  3.     it 'should calculate the numbers correctly up to fib(16)', ->
  4.       fib = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
  5.       expect(Math.fib(i)).toEqual fib[i] for i in [0..16]
  6.  
  7.   describe 'uuid()', ->
  8.     it 'should have the proper UUID format', ->
  9.       expect(Math.uuid()).toMatch /[A-Z0-9]{8}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{13}/
  10.  
  11.     it 'should have always the numer 4 at position 14', ->
  12.       expect(Math.uuid()).toMatch /[A-Z0-9]{8}-[A-Z0-9]{4}-4[A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{13}/
  13.       expect(Math.uuid()).toMatch /[A-Z0-9]{8}-[A-Z0-9]{4}-4[A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{13}/
  14.       expect(Math.uuid()).toMatch /[A-Z0-9]{8}-[A-Z0-9]{4}-4[A-Z0-9]{3}-[A-Z0-9]{4}-[A-Z0-9]{13}/
  15.  
  16.     it 'should generate a unique uuid for 1000 generated uuids at least', ->
  17.       uuids = []
  18.       counter = 0
  19.  
  20.       while counter < 1000
  21.         uuids.push Math.uuid()
  22.         counter++
  23.  
  24.       expect(uuids.length).toEqual _.uniq(uuids).length