Created
October 16, 2012 17:55
-
-
Save cromwellryan/3900886 to your computer and use it in GitHub Desktop.
DCC 12-2012
This file contains 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('panda',function(){ | |
it('scalene',function(){ | |
expect(classify(1,2,3)).toBe('scalene'); | |
}); | |
it('isosceles', function() { | |
expect(classify(2,2,3)).toBe('isosceles'); | |
expect(classify(1,2,2)).toBe('isosceles'); | |
expect(classify(2,1,2)).toBe('isosceles'); | |
}); | |
it('equilateral', function() { | |
expect(classify(2,2,2)).toBe('equilateral'); | |
}); | |
}); |
This file contains 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
var classifiers = { | |
triangle: function(triangle) { /* I'm scalene... err isoceles */ }, | |
square: function(square) { /* I'm a square... err rombus */ } | |
}; | |
function triangle(s1,s2,s3) { | |
return { | |
s1: s1, | |
s2: s2, | |
s3: s3, | |
type: 'triangle' | |
} | |
} | |
function classify(shape) { | |
var classifiesthisshape = classifiers[shape.type]; | |
return classifiesthisshape(shape); | |
} |
This file contains 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
function classifytriangle(s1, s2, s3) { | |
if( s1 == s2 && s2 == s3 ) | |
return 'equilateral'; | |
if( s1 == s2 || s2 == s3 || s1 == s3) | |
return 'isosceles'; | |
return 'scalene'; | |
} |
This file contains 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
function quadrilateral(s1,s2,s3,s4) { | |
return { | |
s1: s1, | |
s2: s2, | |
s3: s3, | |
s4: s4, | |
classify: function() { /* I'm a square... err rombus */ } | |
}; | |
} | |
function triangle(s1,s2,s3) { | |
return { | |
s1: s1, | |
s2: s2, | |
s3: s3, | |
classify: function() { /* I'm scalene... err isoceles */ } | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment