Help with Scala case class Lab

Hi All,

I am new to Scala and currently doing hands on as part of learning Scala.

I need assistance with below hands on, which I believe is matching the requirement but HackerRank test case is failing. Not sure what exactly the issue.

Question :


Program I did for the same :
object Result {
// Create a case class book with name(string) and author(string)
case class book(name:String,author:String)
def describe() {
//Create the two case class objects as described in the statement
val book1 = Result.book(“Scala for the impatient”,“Cay S. Horstmann”)
val book2 = Result.book(“Scala Cookbook”,“Alvin Alexander”)
//Print the details here
println (s"Author of this ${book1.name} is ${book1.author}")
println (s"Author of this ${book2.name} is ${book2.author}")
}

}

object Solution {
def main(args: Array[String]) {
Result.describe()
}
}

Output received after running the HackerRank test case :
No test case passed. Use print or log statements to debug why your hidden test cases are failing. Hidden test cases are used to evaluate if your code can handle different scenarios, including corner cases.

Test case 0

Your Output (stdout)

  • Author of this Scala for the impatient is Cay S. Horstmann

  • Author of this Scala Cookbook is Alvin Alexander

(Meta-request: when you post code here, please surround it with triple-backticks – ``` – on lines by themselves, before and after the code. That will display the code in monospace, and keep the indentation, making it more readable.)

Looking at it, I have to assume this is a problem at the HackerRank level – some assumption they are making that isn’t entirely obvious. Your Scala code looks entirely reasonable to me as it is.

I know very little about HackerRank or how it works, but I wonder if the instructions have a capitalization typo, given that the name of the book should be Scala for the Impatient. I could imagine that the test case is actually looking for that, and the person writing the instructions got it wrong.

4 Likes

Thank you, that was the issue and once updated as Scala for the Impatient, it passed the test case :slight_smile: Thanks once again.

1 Like

I am using the same using case class question from hankerrank it is getting failed now. Not sure what is wrong

You’re missing a space in the first author’s name.

1 Like

Thank you so much @adamdabrowski .
Correct space was the issue Test case is passed now.

1 Like