Mathematics
Algorithms
Logic
Numbers
Data Types
def average(grades) grades.sum.to_f / grades.size unless grades.empty? end
- def average(grades)
grades.sum.fdiv(grades.length)- grades.sum.to_f / grades.size unless grades.empty?
- end
Test.assert_equals(average([1, 2, 3]), 2) Test.assert_equals(average([2, 3]), 2.5) Test.assert_not_equals(average([2, 3]), 2) Test.assert_equals(average([0,0,0]), 0) Test.assert_equals(average([0]), 0) Test.assert_equals(average([]), nil)
# TODO: Replace examples and use TDD development by writing your own tests# These are some of the methods available:# Test.expect(boolean, [optional] message)# Test.assert_equals(actual, expected, [optional] message)# Test.assert_not_equals(actual, expected, [optional] message)- Test.assert_equals(average([1, 2, 3]), 2)
- Test.assert_equals(average([2, 3]), 2.5)
- Test.assert_not_equals(average([2, 3]), 2)
- Test.assert_equals(average([0,0,0]), 0)
- Test.assert_equals(average([0]), 0)
- Test.assert_equals(average([]), nil)