Skip to content

Instantly share code, notes, and snippets.

@xtbl
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtbl/77859caf7f5e0a6b529e to your computer and use it in GitHub Desktop.
Save xtbl/77859caf7f5e0a6b529e to your computer and use it in GitHub Desktop.
example_testing_jasmine
var JasmineTester = function() {};
JasmineTester.prototype = {
constructor: JasmineTester,
// Returns true if the given string has more vowel characters (a,e,i,o,u) than consonants, ignoring whitespace
isVowely: function(str){
},
// Returns the largest numerical value of an array, or null if argument is not an array or if there are no valid numbers in array
max: function(arr){
// Write code here
var currentMax = 0;
if(arr.length > 0) {
for(var i = 0; i< arr.length; i++) {
if(arr[i] > currentMax) {
currentMax = arr[i];
}
}
return currentMax;
} else {
return null;
}
},
// Creates a duplicate-value-free version of an array using strict equality for comparisons, or null if argument is not a valid array
unique: function(arr) {
}
};
//Spec Code
describe('JS Test:', function() {
var testObject = new JasmineTester();
describe('isVowely', function(){
it('should return true if there are more vowels', function() {
expect(testObject.isVowely('Aaron')).toBe(true);
});
it('should return false if there are fewer vowels', function() {
expect(testObject.isVowely('Brad')).toBe(false);
});
it('should return false if there are equal vowels', function() {
expect(testObject.isVowely('Elle')).toBe(false);
});
it('should return false if input is not a valid string', function() {
expect(testObject.isVowely(123)).toBe(false);
});
it('should disregard whitespace', function() {
expect(testObject.isVowely('A a r o n')).toBe(true);
});
});
describe('max', function(){
it('should return the largest number', function() {
expect(testObject.max([3,1,3,0,5,-3])).toBe(5);
expect(testObject.max([5,4.5])).toBe(5);
});
it('should disregard non-numeric values', function() {
expect(testObject.max(['10',undefined,'Joe',NaN,5,-3])).toBe(5);
});
it('should return null if argument does not contain valid input', function() {
expect(testObject.max()).toBe(null);
expect(testObject.max(5)).toBe(null);
expect(testObject.max([])).toBe(null);
expect(testObject.max([NaN])).toBe(null);
expect(testObject.max(['test','with','strings','only'])).toBe(null);
});
});
describe('unique', function(){
it('should return only unique values', function() {
expect(testObject.unique([3,1,3,0,5,-3,5,1])).toBe([3,1,0,5,-3]);
expect(testObject.unique([5,5,5])).toBe([5]);
expect(testObject.unique(['1',1,true,true])).toBe(['1',1,true]);
});
it('should return null if argument does not contain valid input', function() {
expect(testObject.unique()).toBe(null);
expect(testObject.unique(5)).toBe(null);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment