During this lab session:
This activity helps students develop the following skills, values and attitudes: ability to analyze and synthesize, capacity for identifying and solving problems, and efficient use of computer systems.
IMPORTANT NOTE: The lab activities can be developed individually or in pairs. The lab report must be developed individually.
Create a folder called refactoring
. Inside this folder, create two files called student.rb
and tc_student.rb
.
Both Ruby source files must start with a comment containing the lab's title, date, and the authors' personal information. For example:
# Lab 4: Refactoring # Date: 18-Sep-2013 # Authors: # 456654 Thursday Rubinstein # 1160611 Anthony Stark
Place the following code in the file called student.rb
:
# File: student.rb class Student attr_reader :name, :id def initialize(name, id, anual_income) @name = name @id = id @anual_income = anual_income @grades = [] end def reset_anual_income(anual_income) previous_anual_income = @anual_income @anual_income = anual_income previous_anual_income end def add_grade(grade) @grades << grade self end def meh # Display Personal Information puts "Name: #{ @name } ID: #{ @id }" puts "Anual income: #{ @anual_income }" value = 0 @grades.each do |grade| value += grade end value = value / @grades.size.to_f puts "Grade average: #{ value }" # Display Disclaimer puts 'The contents of this class must not be considered an offer,' puts 'proposal, understanding or agreement unless it is confirmed' puts 'in a document signed by at least five blood-sucking lawyers.' end def scholarship_worthy? # Nothing reasonable to do if this student has currently no grades. return -1 if @grades.empty? # A student is worthy of a scholarship if he/she has good grades and # is poor. value = 0 @grades.each do |grade| value += grade end value = value / @grades.size.to_f (value >= 85) and (@anual_income < 15_000) end end
In the tc_student.rb
file write a complete unit test class in order to thoroughly verify the current behavior of Student
instances. Make sure to individually test the meh
and scholarship_worthy?
methods.
Modify the Student
class so that you carry out the following refactorings as many times as you consider necessary:
In the resulting source code include a comment for each modification you carried out. Clearly state what refactoring was applied.
Rerun (and adjust if necessary) your unit tests to make sure that the refactorings didn't modify the class' external behavior.
To hand in your individual lab work, follow these instructions.
lab4_report_A0MMMMMMM.txt
, where A0MMMMMMM
is your student ID. From your AsciiDoc source, generate the corresponding HTML file. That file should be called lab4_report_A0MMMMMMM.html
. Place these two files in the refactoring
directory.
refactoring
directory. Call this file refactoring.tgz
. From a terminal, you can use the following command to create this file (make sure to run it at the same level where the refactoring
folder resides):
tar czf refactoring.tgz refactoring
Due date is Tuesday, September 24.
This activity will be evaluated using the following criteria:
50% | Implementation of functional requirements. |
---|---|
50% | Lab report. |
DA | The program and/or report was plagiarized. |