Skip to content

Instantly share code, notes, and snippets.

@richardvenneman
Created August 15, 2011 22:59
Show Gist options
  • Save richardvenneman/1148099 to your computer and use it in GitHub Desktop.
Save richardvenneman/1148099 to your computer and use it in GitHub Desktop.
Basic Jasmine CoffeeScript test
window.Password = class Password
constructor: (passphrase) ->
@strength = @calcStrength passphrase.length
calcStrength: (len) ->
len--
if len / 3 > 10 # everything with a length-1 > 30 gets a strength of 10
10
else
Math.floor len / 3 # everything else gets a strength of its length-1 divided by 3
describe "Password", ->
it "should report bad passwords", ->
password = new Password 'bad'
(expect password.strength).toEqual 0
it "should report average passwords", ->
password = new Password 'thisisaverage'
(expect password.strength).toEqual 4
it "should report good passwords", ->
password = new Password 'thisisagoodpasswordassaidbyxkcd'
(expect password.strength).toEqual 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment