Seite 1 von 1

Possible bug in the Ex3 tests

Verfasst: 20. Mai 2015 10:12
von DanielAW
Hi,

I'm not sure if I misunderstood something or if this is a bug:

The following test should check if "tuple0" has an index, if I use apply anyway, it should throw an Exception.

Code: Alles auswählen

"tuple0" should "not have an index" in {
  var res = false
  try {
    tuple0(1)
  } catch {
    case _: Exception => res = true
  }
  res should equal(true)
}
So far so good.

The text in this test says: singleton should have an index. But when the apply method does not throw an Exeption, the test fails.

Code: Alles auswählen

 "singleton" should "have an index" in {
    var res = false
    try {
      single(1)
    } catch {
      case _: Exception => res = true
    }
    res should equal(true)
 }
Is there something wrong here?

Regards Daniel

Re: Possible bug in the Ex3 tests

Verfasst: 20. Mai 2015 10:22
von leonidglanz
Hello,

In the introduction there is this description: A get method, returning the element at a given index (starting at 0). It throws an exception if the index is < 0 or >= n

So a singleton has only one element, so it should have an index, but if the index is smaller or equal n then we should throw an exception.

Regards,
Leonid Glanz

Re: Possible bug in the Ex3 tests

Verfasst: 20. Mai 2015 10:45
von DanielAW
Ahhh, this makes sense!

Thanks :-)