Design an oracle for the following JavaScript function.
2. Generate a test case set for this function and provide a coverage analysis report for your test case set.

The JavaScript function:

function purchaseSong(username, password, songId) {
  // first authenticate the user
  if (checkCredentials(username, password) == false) {
    alert('The username or password is incorrect.');
  // get the price of the song
  var songPrice = getSongPrice(songId);
  // make sure the user has enough money in his account
  if (getAccountBalance(username) < songPrice) {
    alert('You do not have enough money in your account.');
  // debit the user's account
  debitAccount(username, songPrice);
  // start downloading the song to the client machine

Notice: You may note that the user could be malicious and try to modify the JavaScript. Your oracle and test case should reflect this fact.

Edited by Nick Evan: Add code-tags

8 Years
Discussion Span
Last Post by Gatayo

Ok congratulations, you've demonstrated that you can paste your homework. Do you have any specific questions? Anything at all to show that you have given this the least bit of thought?


I have already solved the problem, I just wanted to compare my solution to others and see if there would some similarities in the way of approaching the problem

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.