Skip to content
ewernli edited this page Sep 21, 2012 · 26 revisions

Deadline: Wednesday, 26. September 2012, 12:00

1. Registration (1 point)

To register for the exercises, you must

  • Create a github account (if you already have one, you can reuse it) ;
  • Create a repository ese2012_warmup;
  • Follow ese_unibe_ch on twitter ;

Then

  • Send a mail to [email protected] with the title "registration ESE 2012", containing your github and twitter accounts. Send the mail from your @students.unibe.ch email address, otherwise it will be queued in the mailing list.

We will confirm your registration, and send you the license key for RubyMine.

Recommended readings for github are:

This part of the exercise is solved if you successfully obtained a reply to your registration email.

2. Short Bio (1 point)

We request that you write a short bio about yourself using the github wiki:

  1. Add a wiki page "bio" to the wiki of ese2012_warmup.
  2. Introduce yourself by writing a few short paragraphs about yourself and your knowledge and experience in Software Engineering. If you like you can also write down your contact information, this will likely be useful during the project later on in this course.

Answer the following questions with a few keywords or a short sentence:

  • What programming languages do you know and use?
  • Have you been involved in any software projects?
  • Do you have experience working in teams?

3. Programming (4 points)

The goal of this task is to implement a simple application to trade items. Users have an amount of credits. Users in the system can propose items to a fixed price, which other users can buy using their credits.

The requirements you are asked to implement are:

  • Users have a name.
  • Users have an amount of credits.
  • A new user has originally 100 credit.
  • Items have a name.
  • Items have a price.
  • An item can be active or inactive.
  • An item has an owner.
  • A user can add a new item to the system with a name and a price; the item is originally inactive.
  • A user provides a method that lists his/her active items to sell.
  • A user can buy active items of another user (inactive items can't be bought). When a user buys an item, it becomes the owner; credit are transferred accordingly; immediately after the trade, the item is inactive. The transaction fails if the buyer has not enough credits.

Note that this task only involves to model the requested features of the entities User and Item. We do not ask you to provide a user-interface. The code has to be accompanied with unit-tests though. For each of the above requirements, it is required to have at least one test method containing at least one assertion. For the last requirement, you must have at least 3 test methods that cover different cases (enough/not enough credit, active/inactive, etc.)

The code must be provided according to the guidelines:

Ruby version and IDE

  • The code must adhere to Ruby 1.8 syntax. (Ruby 1.8 is still the default version for Mac OS X and Linux despite availability of 1.9 since several years)
  • You are free to use whatever IDE you want, but we suggest RubyMine for which we have a classroom license.

Structure

The code must be structured as follows:

/app
     appname.rb
     /module_name
           class_name.rb
/test
     test_name.rb

Coding Style

For this exercise, only the following bare minimal rules are mandatory:

  • One file per class
  • Class names are upper CamelCase but file name is lower snake case, e.g.MyClass in my_class.rb
  • Method names are lower snake case, e.g. my_method
  • Generate attributes with attr_accessor and access them with self, e.g. self.attribute = 42.

Ruby 101

Here are two sample classes to show idiomatic ruby code. The code can be found under the ese2012-idiomatic-ruby repository.

The class Student in student.rb shows the main language constructs needed for this exercise. For quick reference to the language, you can have a look at one of the many ruby cheat sheets:

  # a module is a namespace to avoid name collisions
  module University
  
    class Student
  
      # generate getter and setter for name and grades
      attr_accessor :name, :grades
  
      # factory method (constructor) on the class
      def self.named( name )
          student = self.new
          student.name = name
          student
      end
  
      # initialize is called automatically
      # when an instance is created
      def initialize
        self.grades = Array.new
      end
  
      def to_s
        # string interpolation
        "#{name} (average=#{self.average})"
      end
  
      def add( grade )
        grades.push( grade )
      end
  
      def average
        # list comprehension with closures
        total = grades.inject(0){ |sum, grade| sum + grade }
        total / grades.length
      end
  
      # ? is a coding convention for method returning boolean
      def award?
        # another list comprehension with closures
        grades.all? { |grade| grade == 6 }
      end
  
    end
  
  end

The class StudentTest in student_test.rb shows how to write a unit test with Ruby:

  require 'test/unit'
  require 'student'
  
  # syntax for inheritance
  class StudentTest < Test::Unit::TestCase
  
    def test_award
      student = University::Student.named( 'John')
      student.add(6)
      assert( student.award?, 'Student deserves an award')
    end

  end

IDE warnings

RubyMine will give a false warning Cannot find variable with given name for 'attr_accessor' for the code above. This is a known issue that will be fixed later. You can ommit it.

Notice

You can solve the third part of the exericse in team of two. You are asked to deliver the code in the ese2011-warmup repository of one of the author. You need to send a mail to [email protected] with the following subject line: "Exercise 1: Warming Up", give the names of the authors, and the git repository to pull the code from. We must be able to create a ruby project out of your code and run the tests with no pain. Exerices must be delivered by Wednesday, 26. September 2012, 12:00.

Clone this wiki locally