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.');
    return;
  }
 
  // 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.');
    return;
  }
 
  // debit the user's account
  debitAccount(username, songPrice);
 
  // start downloading the song to the client machine
  downloadSong(songId);
}

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.

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.