Created
August 15, 2011 22:59
-
-
Save richardvenneman/1148099 to your computer and use it in GitHub Desktop.
Basic Jasmine CoffeeScript test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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