To Home Page

IT 231 -- Project 3

Testing Class Methods

 

Create a folder named Proj3Smith (replace Smith by your last name) that contains the files time-test.rb from Question 1, vm-test.rb from Question 2, and vm-url.rb from Question 3. Also include the Rails project TestStudent from Question 4, which includes test-students.rb.

In what follows, to test the methods of a class means call each of the methods in ways that will produce all of the expected outputs or return values of these methods.

  1. Test seven of the methods of the Time class shown in the UML Diagram. Put your ruby test statements in the file test-time.rb.
     
  2. Test the methods of the VendingMachine class. Here is the source code. Put the code for the VendingMachine class and the ruby statements that test it in the file test-vm.rb. Look at the Dice class with test code as an example.
     
    To buy a candy bar, you must deposit three quarters (call the deposit_quarters method three times), and then select the candy (call the select_candy method). To fully test the vending machine, you should attempt to buy six candy bars. On the first five tries, you should be successful, but on the sixth try, the vending machind will be out of candy so your attempt should fail.
     
  3. Draw the UML diagram of the VendingMachine class. See the UML Diagram of the Dice class as an example.
     
    You can use Visio or other drawing package to draw the UML diagram. You can also use "typewriter graphics" like this:
    See the String and Dice Examples (Examples 13 and 14). Put your UML diagram for the vending maching class in a file named vm-url.txt, vm-url.docx, vm-url.vsd, vm-url.vsd.gif, etc.
     
  4. Create a Rails project named TestStudent with a model named Student having these fields: first_name, major, year, gpa. Write a file named test-students.rb that does the following:
     
    1. Creates a new Student object.
    2. Sets the first_name instance variable of the object.
    3. Sets the major instance variable of the object.
    4. Sets the year instance variable of the object.
    5. Sets the gpa instance variable of the object.
    6. Saves the object in the database.
    7. Checks the count of rows in the students table.
    8. Repeats steps a through g to create three more objects and add them to the database as well.
    9. Deletes one of the objects from the database.
    10. Checks the count of rows in the database.

Move all files inside your Rails project file (which you named Proj3Smith), then zip and submit the project file (which should be named Proj3Smith.zip).

Grading Criteria: Functionality: 60%; Test is Complete: 30%; Zipped and Submitted Correctly: 10%.