Skip to content

Commit

Permalink
added #letter
Browse files Browse the repository at this point in the history
  • Loading branch information
abarnhard committed Aug 6, 2014
1 parent 0f165f9 commit 07a72f4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/models/student.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ Student.prototype.avg = function(){

};

Student.prototype.letter = function(){
if(!this.tests.length){return 'N/A';}

var avg = this.avg();
if(avg < 60){
return 'F';
}else if(avg < 70){
return 'D';
}else if(avg < 80){
return 'C';
}else if(avg < 90){
return 'B';
}else{
return 'A';
}
};

module.exports = Student;

// Helper Functions
Expand Down
27 changes: 27 additions & 0 deletions test/unit/student.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,32 @@ describe('Student', function(){
expect(s1.avg()).to.be.closeTo(75, 0.1);
});
});
describe('#letter', function(){
it('should return A', function(){
s1 = new Student({name:'Jim Jones', color:'blue'});
s1.tests = [95];
expect(s1.letter()).to.equal('A');
});
it('should return B', function(){
s1 = new Student({name:'Jim Jones', color:'blue'});
s1.tests = [85];
expect(s1.letter()).to.equal('B');
});
it('should return C', function(){
s1 = new Student({name:'Jim Jones', color:'blue'});
s1.tests = [75];
expect(s1.letter()).to.equal('C');
});
it('should return D', function(){
s1 = new Student({name:'Jim Jones', color:'blue'});
s1.tests = [65];
expect(s1.letter()).to.equal('D');
});
it('should return F', function(){
s1 = new Student({name:'Jim Jones', color:'blue'});
s1.tests = [55];
expect(s1.letter()).to.equal('F');
});
});

});

0 comments on commit 07a72f4

Please sign in to comment.