Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
DCC 12-2012
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');
});
});
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);
}
function classifytriangle(s1, s2, s3) {
if( s1 == s2 && s2 == s3 )
return 'equilateral';
if( s1 == s2 || s2 == s3 || s1 == s3)
return 'isosceles';
return 'scalene';
}
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